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

Return new cursor position from reshape_info() #22

Open
dgkf opened this issue Aug 25, 2024 · 2 comments
Open

Return new cursor position from reshape_info() #22

dgkf opened this issue Aug 25, 2024 · 2 comments

Comments

@dgkf
Copy link
Contributor

dgkf commented Aug 25, 2024

Currently, after issue only a "change" action from the LSP, the entire region of replaced text is selected after the code action. Instead, it would be more intuitive if the same cursor remained selected through the transformation, mapping its original position to its final position.

To support this, it would be helpful if reshape_info also returned the new cursor position. The rest can be handled on the languageserver side.

@dgkf
Copy link
Contributor Author

dgkf commented Aug 26, 2024

After implementing this, I learned that LSP doesn't actually support this yet. It won't be rolling out until the next release.

With the new LSP capability, a replacement can be provided as a snippet, using $0 to indicate the final cursor location after inserting the snippet.

Although codegrip could return this snippet text to simplify things, I think it would be better that it return the cursor position (perhaps as number of characters into the replacement?), and then let the LSP escape other $'s and insert this special $0 string.

One potential downside of this for editors like helix or vim, is that you probably don't want cursor positioning handled exactly like a snippet if you're in normal mode. I'm assuming most modal editors would drop you into edit mode for stepping through snippet tabstops, but in this case you probably want to be left in whatever mode you issued the code-action in. Will probably wait to see what it looks like after 3.18 rolls out before speculating further.

@lionel-
Copy link
Owner

lionel- commented Aug 29, 2024

That makes sense, happy to return more info such as cursor position.

Regarding editor modality, I guess the LSP clients in these editors should decide what to do in that case? In my experience (vscodevim, emacs evil) it's fine to do snippet transforms in normal state without dropping in insert state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants