danymat / neogen

A better annotation generator. Supports multiple languages and annotation conventions.
GNU General Public License v3.0
1.34k stars 56 forks source link

Check if generation possible for current cursor position #132

Open mlthlschr opened 1 year ago

mlthlschr commented 1 year ago

Hi,

I am thinking about combining neogen with the lsp code actions. For that, I would like to check if it is possible to generate a comment at the current cursor position. If there is, I would like to display an option like "Generate comment" in the code action window.

I checked the API and it looks like right now it is only possible to trigger the generation, even if it is not at the cursor position. Is that correct?

Would be great if there was a way to check that. In case thats not available and not planned I offer help with implementation, if needed.

gshpychka commented 1 year ago

You could use tree-sitter and simply detect all classes, functions, etc.

mlthlschr commented 10 months ago

If it is desired for the project or someone else is interested, I implemented a feature here triggering neogen for the node one line below. I am using it in combination with a keymap, so that a comment in the line above e.g. a function triggers neogen (comparable to the behavior in Jetbrains IDEs).

danymat commented 3 months ago

Seems a very cool feature. However, I fall short understand what it needs to trigger neogen for the node one line below. If you are still interested in sharing, would you mind sharing a bit more ? And why not re-work the feature a bit, and create a PR for it ?

ColinKennedy commented 2 months ago

I would like to check if it is possible to generate a comment at the current cursor position

Generating under the current cursor is possible. In fact it's needed for https://github.com/danymat/neogen/pull/201

I added integration with LuaSnip + Neogen in a separate example: https://github.com/danymat/neogen/pull/202

Being able to generate docstring code at any cursor position I think would be a welcome thing.