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

cursor issue about variable and rust inlay hints #3263

Open
3 tasks done
c02y opened this issue Dec 15, 2021 · 2 comments
Open
3 tasks done

cursor issue about variable and rust inlay hints #3263

c02y opened this issue Dec 15, 2021 · 2 comments
Labels

Comments

@c02y
Copy link

c02y commented Dec 15, 2021

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command
emacs -q -l lsp-start-plain.el

where lsp-start-plain.el can be downloaded here.

Bug description

When I enable inlay hints for rust code, the cursor of the last character of the variable is at the wrong place.

Steps to reproduce

  1. Use rust-analyzer
  2. use lsp-mode for rust code
  3. open a rust file
  4. enable inlat hints for rust file by enabling lsp-rust-analyzer-inlay-hints-mode and lsp-rust-analyzer-server-display-inlay-hints
  5. move cursor, check out the gif

Peek 2021-12-16 05-00

BTW: I'm using Spacemacs(Spacemacs, rust-analyzer, all packages are all update to date), I'm not sure whether other people can reproduce it or not.

Expected behavior

Moving the cursor to the last character of the variable should not move over to the inlay hints

Which Language Server did you use?

rust-analyzer db2a7087b 2021-12-13 stable

OS

Linux

Error callstack

No response

Anything else?

No response

@c02y c02y added the bug label Dec 15, 2021
@deifactor
Copy link

deifactor commented Apr 7, 2023

I'm not sure if this is possible to easily fix. For a given block of propertized text and overlays, I think emacs will always display the cursor at the same point. If so, then there's no way to make it so you can have the cursor both immediately before and immediately after the overlay and insert text at the location you're expecting without hooking into post-command-hook to

  • Check if the command moved point by exactly +1 and that moved it past an overlay
  • Adjust the overlay properties (I think propertizing the text with 'cursor t works)
  • reset point to what it was before so your cursor hasn't actually moved

as well as do the opposite for moving backwards. Basically, instead of moving the cursor around the overlay, you move the overlay around the cursor.

This would potentially be a good candidate for emacs to support at the C level by adding a new property to overlays.

@deifactor
Copy link

deifactor commented Apr 9, 2023

I just wrote this snippet to propertize the overlay based on whether it makes more sense for the cursor to be at the start or the end (type overlays come after the thing they describe, param overlays come before):

(defun lsp-rust-analyzer-properties-for-inlay (kind)
  "Returns the text properties to be used for the inlay's after-string."
  (cond
   ((eql kind lsp/rust-analyzer-inlay-hint-kind-type-hint)
    ; Setting the cursor to 1 lets us put the cursor at the start of the
    ; overlay; not setting it/setting it to nil means we can put it at the
    ; end. See https://github.com/emacs-lsp/lsp-mode/issues/3263
    '(font-lock-face lsp-rust-analyzer-inlay-type-face cursor 1))
   ((eql kind lsp/rust-analyzer-inlay-hint-kind-param-hint)
    '(font-lock-face lsp-rust-analyzer-inlay-param-face))
   (t
    '(font-lock-face lsp-rust-analyzer-inlay-face))))

and then replace the call to propertize in lsp-rust-analyzer-update-inlay-hints with

(apply 'propertize (lsp-rust-analyzer-format-inlay concat-label kind)
       (lsp-rust-analyzer-properties-for-inlay kind))

If this doesn't somehow blow up in my face, I'll send a PR.

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

No branches or pull requests

2 participants