-
-
Notifications
You must be signed in to change notification settings - Fork 927
lsp-rust: support rust-analyzer.showReference lens #2299
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
Changes from all commits
53c7a2b
dd4d5b7
1767902
00a1a58
4e766bc
dddb162
84fadc5
d9a17fa
1c0c2b8
19bdc11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,7 +295,7 @@ PARAMS progress report notification data." | |
(lsp-workspace-status nil workspace) | ||
(lsp-workspace-status (format "%s - %s" title (or message? "")) workspace)))) | ||
|
||
(cl-defmethod lsp-execute-command (_server (_command (eql rls.run)) params) | ||
(lsp-defun lsp-rust--rls-run ((&Command :arguments? params)) | ||
(-let* (((&rls:Cmd :env :binary :args :cwd) (lsp-seq-first params)) | ||
(default-directory (or cwd (lsp-workspace-root) default-directory) )) | ||
(compile | ||
|
@@ -635,6 +635,11 @@ them with `crate` or the crate name they refer to." | |
(lsp-defun lsp-rust--analyzer-run-single ((&Command :arguments?)) | ||
(lsp-rust-analyzer-run (lsp-seq-first arguments?))) | ||
|
||
(lsp-defun lsp-rust--analyzer-show-references | ||
((&Command :title :arguments? [_uri _filepos references])) | ||
(lsp-show-xrefs (lsp--locations-to-xref-items references) nil | ||
(s-contains-p "reference" title))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity what are the expected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reference(s) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a side note, do we prefer scheme-style There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Most of the code is written using scheme-style although this is not enforced 100% during reviews. |
||
|
||
(lsp-register-client | ||
(make-lsp-client | ||
:new-connection (lsp-stdio-connection | ||
|
@@ -648,7 +653,8 @@ them with `crate` or the crate name they refer to." | |
:priority (if (eq lsp-rust-server 'rust-analyzer) 1 -1) | ||
:initialization-options 'lsp-rust-analyzer--make-init-options | ||
:notification-handlers (ht<-alist lsp-rust-notification-handlers) | ||
:action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single)) | ||
:action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single) | ||
("rust-analyzer.showReferences" #'lsp-rust--analyzer-show-references)) | ||
:library-folders-fn (lambda (_workspace) lsp-rust-library-directories) | ||
:after-open-fn (lambda () | ||
(when lsp-rust-analyzer-server-display-inlay-hints | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,19 +144,14 @@ See `lsp-lens--schedule-refresh' for details." | |
(define-key [mouse-1] (lsp-lens--create-interactive-command command)))) | ||
|
||
(defun lsp-lens--create-interactive-command (command?) | ||
"Create an interactive COMMAND? for the lens." | ||
(let ((server-id (->> (lsp-workspaces) | ||
(cl-first) | ||
(or lsp--cur-workspace) | ||
(lsp--workspace-client) | ||
(lsp--client-server-id)))) | ||
(if (functionp (lsp:command-command command?)) | ||
(lsp:command-command command?) | ||
(lambda () | ||
(interactive) | ||
(lsp-execute-command server-id | ||
(intern (lsp:command-command command?)) | ||
(lsp:command-arguments? command?)))))) | ||
"Create an interactive COMMAND? for the lens. | ||
COMMAND? shall be an `&Command' (e.g. `&CodeLens' :command?) and | ||
mustn't be nil." | ||
(if (functionp (lsp:command-command command?)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd guess no, because it wasn't possible previously (this wouldn't be a regression caused by this PR): (if (functionp (lsp:command-command command?))
(lsp:command-command command?)
(lambda ()
(interactive)
(lsp-execute-command server-id
(intern (lsp:command-command command?))
(lsp:command-arguments? command?))))
; (if (functionp (lsp:command-command nil)) ...) -> (functionp nil) -> nil This means that the control flow passed to the other branch, creating a lambda that would try to (lsp:command-command nil) ; => nil
(intern nil) ; => error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is called on line 190 in master (without this PR), and only lenses that have a command are passed to it ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I'm asking is because of parameter name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't do that, since it is an Elisp-level change, meaning that this entire thing has to be manually tested again, for something this trivial. See this comment by @yyoncho. Noting that in the docstring is good enough, IMHO. Also, the name isn't that bad: |
||
(lsp:command-command command?) | ||
(lambda () | ||
(interactive) | ||
(lsp--execute-command command?)))) | ||
|
||
(defun lsp-lens--display (lenses) | ||
"Show LENSES." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have different indent or should be on the same line with the function name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the line would be > 80 columns. Is that preferred?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can put multi-line for the parameters right?
That would make it easier to distinguished between params and body of a function
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options are:
or
, both of which require one more line. What do you think? Do you prefer either of them over the current solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for late reply, both look fine to me.
The current solution has same indent between args and body and that make it quite hard to distinguish them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyoncho which do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me all three options are acceptable... Just want to mention that we do not enforce 80 symbols or at least there is no agreement on that ATM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I'll keep your latter point in mind. Not changing the call here is the best option then, because it means no new changes have to made and reviewed.