-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
lsp-rust: support rust-analyzer.showReference lens #2299
Conversation
Please revert the lsp-execute-command elimination because it is used multiple times in different projects (e. g. lsp-java, ccls, etc). |
;; `lsp-interface' is unsuitable for ShowReference destructuring, as that code | ||
;; action yields an array of three elements, not a map. | ||
(lsp-defun lsp-rust--analyzer-show-references | ||
((&Command :title :arguments? [_uri _filepos references])) |
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
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:
(lsp-defun lsp-rust--analyzer-show-references ((&Command
:title :arguments?
[_uri _filepos references]))
or
(lsp-defun lsp-rust--analyzer-show-references ((&Command :title :arguments?
[_uri _filepos
references]))
, 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.
@yyoncho can I perhaps instead refactor the other projects to not use it? That function needs to be at least be refactored, as it removes the :title field (without it, it is impossible to know whether to use |
I am fine with this approach. |
@yyoncho can you give me a list of projects that use it? |
lsp-java is done. |
ccls.el is done. |
IDK - you have to check all packages that depend on lsp-mode. |
Instead of just deleting code, I think we should probably make that function become obsoleted, and promote |
@kiennq actually, |
Also, from the packages I checked, there are no more uses of it. We'll need to wait for ccls and lsp-java, and then this can be merged. |
Lens resolution is not using The A quick search of |
We cannot use a new function for this. Also, my problem isn't only the :title field, even though it hints the problems that will follow; Regarding your github search, most of them are elpa directories containing |
Nevermind, it's still too many. I propose an alternative: |
I'll re-add it as a normal defun. It is not overriden using Note the exclusions: I have provided PRs for The following PRs need to be merged before this can be, though: Also, should we make |
2f4a74d
to
957a056
Compare
We may want to make a new release for this though, as it would break ccls.el and lsp-java-* for anyone who decides to update |
8c2e6a1
to
44e5986
Compare
I tested this with These seem unrelated to the changes though (I'll investigate with master). |
I tested with master, |
lsp-mode.el
Outdated
(lsp--client-server-id)))) | ||
(condition-case nil | ||
(prog1 (lsp-execute-command server-id (intern command) arguments?) | ||
(lsp--warn "`lsp-execute-command' is deprecated")) |
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.
Why don't you just make lsp-execute-command
obsolete instead? We will have compile warning about that, and that would be standard way to alert package maintainer about obsolete function.
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.
That somehow slipped my mind; concluded from testing, calling that function doesn't cause warnings, but overriding it using cl-defmethod
does. I couldn't find anything in the Emacs docs about the obsoletion of generics, though. Fixed.
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 code looks good to me. I will proceed with the merge after doing manual testing.
(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 comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity what are the expected title
values here?
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.
reference(s)
definition(s)
E.g. 2 references, 2 definitions. I'm unsure whether the singular forms can actually be encountered, though.
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.
As a side note, do we prefer scheme-style ?
or common-lisp-style p
predicate functions? I.e. s-contains-p
or s-contains?
.
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.
As a side note, do we prefer scheme-style
?
or common-lisp-stylep
predicate functions? I.e.s-contains-p
ors-contains?
.
Most of the code is written using scheme-style although this is not enforced 100% during reviews.
@yyoncho you may want to hold off merging until my ccls.el PR gets merged, as otherwise users will get inevitable byte-compiler warnings. |
Is the ccls pr mandatory? |
(lsp-execute-command server-id | ||
(intern (lsp:command-command command?)) | ||
(lsp:command-arguments? command?)))))) | ||
(if (functionp (lsp:command-command command?)) |
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.
Can command?
be nil
here?
If so, don't you need to check before passing it to lsp--execute-command
?
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.
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 intern
nil, which errors.
(lsp:command-command nil) ; => nil
(intern nil) ; => error
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 function is called on line 190 in master (without this PR), and only lenses that have a command are passed to it (-filter #'lsp:command-command
), so I guess command? cannot be nil. I'll note that in the docstring.
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.
Fixed.
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 reason I'm asking is because of parameter name command?
which indicates it can be nil
, we should change the parameter name too.
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.
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: command?
also corresponds to the naming of the CodeLens
and CodeAction
:command?
fields, indicating that this function expects them to be passed in.
@yyoncho I'd argue yes, because |
I would like to propose not deprecating |
Can you rebase? |
Add a rust-analyzer specific :action-handler for the showReference lens, which leverages `lsp-show-xrefs'. Refactor: eliminate `lsp-execute-command', because it caused the :title to be lost, which is needed to distinguish between the "references" or "implementations" variants of that lens. Defining a new `lsp-interface' to destructure "rust-analyzer.showReference" was impossible, as the former doesn't support destructuring lists (the :arguments? paramter is a special, 3-element list.).
Its original function, being a `cl-defgeneric' that can be overriden per language server is gone; however, PRs were provided to eliminate all uses of it in that context. To remain backwards-compatible, it will still remain as an obsolete `defun' that calls `lsp--execute-command' internally.
Since it wouldn't do what it did previously (being an extension point), restoring that function doesn't actually improve backwards compatibility. Reverts 957a056.
`lsp-execute-command' now works as an extension point again, but a deprecation warning is shown if it is used to handle a command. To implement this, leverage `cl-no-applicable-method': call `lsp-execute-command' first, and then, if there is no implementation, go trough the handler hash tables as usual.
The proper way to mark a function as deprecated is to use `make-obsolete'; use that instead of `lsp--warn'.
`lsp-interface' wasn't designed to destructure lists; stating that fact before `lsp-rust--analyzer-show-references' is as such redundant, since that is normal and not noteworthy.
The COMMAND? argument of that function mustn't be nil, which is unclear from its name (?). Note that fact in its docstring. The name of that argument is still good though, because it refers to a field name in `CodeAction' and `CodeLens'. Based on a discussion with @kiennq.
Unlike previously assumed, calling `lsp-execute-command' causes byte-compile warnings, not just using it in `cl-defmethod'. Wrap the call in `with-no-warnings', since that should be the only use of that function.
5ea5db1
to
19bdc11
Compare
Add a rust-analyzer specific :action-handler for the showReference lens,
which leverages
lsp-show-xrefs'. Refactor: eliminate
lsp-execute-command', because it caused the :title to be lost, which isneeded to distinguish between the "references" or "implementations"
variants of that lens.
Defining a new `lsp-interface' to destructure
"rust-analyzer.showReference" was impossible, as the former doesn't
support destructuring lists (the :arguments? paramter is a special,
3-element list.).