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

Update support for rust-analyzer's inlay hints #3404

Merged
merged 6 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Add [[https://github.com/idris-community/idris2-lsp][idris2-lsp]]
* Add [[https://github.com/aca/emmet-ls][emmet-ls]]
* Support all ~initializationOptions~ in ~typescript-language-server~
* Update rust-analyzer's inlay hint protocol support.
** Release 8.0.0
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.
* Set ~lsp-clients-angular-language-server-command~ after the first connection to speed up subsequent connections.
Expand Down
16 changes: 8 additions & 8 deletions clients/lsp-rust.el
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ https://rust-analyzer.github.io/manual.html#auto-import.
:group 'lsp-rust-analyzer
:package-version '(lsp-mode . "8.0.0"))

(defcustom lsp-rust-analyzer-inlay-type-format ": %s"
(defcustom lsp-rust-analyzer-inlay-type-format "%s"
"Format string for variable inlays (part of the inlay face)."
:type '(string :tag "String")
:group 'lsp-rust-analyzer
Expand All @@ -869,7 +869,7 @@ https://rust-analyzer.github.io/manual.html#auto-import.
:group 'lsp-rust-analyzer
:package-version '(lsp-mode . "8.0.0"))

(defcustom lsp-rust-analyzer-inlay-param-format "%s:"
(defcustom lsp-rust-analyzer-inlay-param-format "%s"
"Format string for parameter inlays (part of the inlay face)."
:type '(string :tag "String")
:group 'lsp-rust-analyzer
Expand Down Expand Up @@ -910,20 +910,20 @@ meaning."
(if (and (lsp-rust-analyzer-initialized?)
(eq buffer (current-buffer)))
(lsp-request-async
"rust-analyzer/inlayHints"
"experimental/inlayHints"
(lsp-make-rust-analyzer-inlay-hints-params
:text-document (lsp--text-document-identifier))
(lambda (res)
(remove-overlays (point-min) (point-max) 'lsp-rust-analyzer-inlay-hint t)
(dolist (hint res)
(-let* (((&rust-analyzer:InlayHint :range :label :kind) hint)
((&RangeToPoint :start :end) range)
(overlay (make-overlay start end nil 'front-advance 'end-advance)))
(-let* (((&rust-analyzer:InlayHint :position :label :kind) hint)
(pos (lsp--position-to-point position))
(overlay (make-overlay pos (+ pos 1) nil 'front-advance 'end-advance)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure what that second parameter should be; pos doesn't work, but the position we get doesn't really have an end per se.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess would be that pos doesn't work because we set evaporate, which makes Emacs remove the hints when they have length 0. I don't know if that's necessary, since we also remove the overlays manually when we update them. Maybe @yyoncho knows more here

(overlay-put overlay 'lsp-rust-analyzer-inlay-hint t)
(overlay-put overlay 'evaporate t)
(cond
((equal kind lsp/rust-analyzer-inlay-hint-kind-type-hint)
(overlay-put overlay 'after-string
(overlay-put overlay 'before-string
(format lsp-rust-analyzer-inlay-type-space-format
(propertize (format lsp-rust-analyzer-inlay-type-format label)
'font-lock-face 'lsp-rust-analyzer-inlay-type-face))))
Expand All @@ -935,7 +935,7 @@ meaning."
'font-lock-face 'lsp-rust-analyzer-inlay-param-face))))

((equal kind lsp/rust-analyzer-inlay-hint-kind-chaining-hint)
(overlay-put overlay 'after-string
(overlay-put overlay 'before-string
(format lsp-rust-analyzer-inlay-chain-space-format
(propertize (format lsp-rust-analyzer-inlay-chain-format label)
'font-lock-face 'lsp-rust-analyzer-inlay-chain-face))))))))
Expand Down
8 changes: 4 additions & 4 deletions lsp-protocol.el
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ See `-let' for a description of the destructuring mechanism."

(lsp-interface (rls:Cmd (:args :binary :env :cwd) nil))

(defconst lsp/rust-analyzer-inlay-hint-kind-type-hint "TypeHint")
(defconst lsp/rust-analyzer-inlay-hint-kind-param-hint "ParameterHint")
(defconst lsp/rust-analyzer-inlay-hint-kind-chaining-hint "ChainingHint")
(defconst lsp/rust-analyzer-inlay-hint-kind-type-hint 1)
(defconst lsp/rust-analyzer-inlay-hint-kind-param-hint 2)
(defconst lsp/rust-analyzer-inlay-hint-kind-chaining-hint nil)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nil seems like it's a bug in rust-analyzer? It feels like it should be 3 but it definitely isn't on my machine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so not a bug but an extension to the draft spec.

Copy link

@lnicola lnicola Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lsp-interface (rust-analyzer:AnalyzerStatusParams (:textDocument))
(rust-analyzer:SyntaxTreeParams (:textDocument) (:range))
(rust-analyzer:ExpandMacroParams (:textDocument :position) nil)
Expand All @@ -415,7 +415,7 @@ See `-let' for a description of the destructuring mechanism."
(rust-analyzer:RunnableArgs (:cargoArgs :executableArgs) (:workspaceRoot))
(rust-analyzer:RelatedTestsParams (:textDocument :position) nil)
(rust-analyzer:RelatedTests (:runnable) nil)
(rust-analyzer:InlayHint (:range :label :kind) nil)
(rust-analyzer:InlayHint (:position :label :kind) nil)
(rust-analyzer:InlayHintsParams (:textDocument) nil)
(rust-analyzer:SsrParams (:query :parseOnly) nil)
(rust-analyzer:CommandLink (:title :command) (:arguments :tooltip))
Expand Down