codegrip icon indicating copy to clipboard operation
codegrip copied to clipboard

Return new cursor position from `reshape_info()`

Open dgkf opened this issue 1 year ago • 2 comments

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 avatar Aug 25 '24 04:08 dgkf

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.

dgkf avatar Aug 26 '24 03:08 dgkf

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.

lionel- avatar Aug 29 '24 07:08 lionel-