Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generation for types after cursor #53

Closed
ouuan opened this issue Jan 30, 2022 · 5 comments
Closed

Allow generation for types after cursor #53

ouuan opened this issue Jan 30, 2022 · 5 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@ouuan
Copy link

ouuan commented Jan 30, 2022

For example, if the cursor is at the beginning of a line starts with some whitespace:

    int foo();

I'll need to move the cursor to int or further to call Neogen.

An inline forward search may solve this problem.

@danymat danymat changed the title Neogen when cursor is in the line but not in the characters of the function Allow generation for types after cursor Jan 30, 2022
@danymat
Copy link
Owner

danymat commented Jan 30, 2022

Hello ! This is tricky, because Neogen currently generates when you are "inside" (that means, inside any subnode of desired content.)
If we allow this behavior, what happens if this int foo(); is already inside something else (for example a function) ? Will we call the annotations for the function or the type ?

Maybe Neogen could process itself 2 times:

  • First time: locate next upper node that matches Neogen requested "type".
  • Second time (like a fallback): if nothing found, locate the first node in the same line that matches the requested type.

@danymat danymat added the enhancement New feature or request label Jan 30, 2022
@danymat
Copy link
Owner

danymat commented Jan 30, 2022

This is a good idea, but could be a "breaking" change, because it can modify some process in someone's workflow.
It's a very good idea, after consideration.

@ouuan
Copy link
Author

ouuan commented Jan 30, 2022

I just realized that mapping to $<cmd>Neogen<cr> works for me. It may not work in some other use cases, though.

@danymat
Copy link
Owner

danymat commented Jan 30, 2022

I will put this idea on hold, asking for more feedback on users. I feel like this is a too much important change to do, without asking for more input

@danymat danymat added help wanted Extra attention is needed question Further information is requested and removed help wanted Extra attention is needed labels Jan 30, 2022
@danymat
Copy link
Owner

danymat commented Feb 24, 2022

Hello, after giving more though on this, I find that this is not optimal, and thus for multiple reasons:

  • The user should have a predictable guess of what annotation will be generated. As mentioned here: Allow generation for types after cursor #53 (comment), this will be very unpredictable, even if I want to come up with the solution I proposed.
  • This feature will add a complexity to the code where it is not required: going with my solution, that would required fetching the nodes and doing multiple times the same loop, in order to find the best node
  • Lastly, finding a node in the same line in Treesitter is currently a pain to do so, because that will require to filter every nodes and only keep ones that start at the current line. The other way around is not possible, aka: fetching nodes for a specific line

I'm sorry if this answer does not satisfy you, feel free to reopen this issue if you find some counterarguments on what my takes, or if you want to contribute to the issue. Nevertheless, thanks for the suggestion !
Cheers 🙂 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants