-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Add support for Resolve Macro As of clojure-lsp #1077
Comments
I was made aware by Eric that the "resolve macro" code action is showing up even though we don't support it yet. We need to soon either implement this or make that code action not show in the UI. |
That code action need 2 additional parameters to work that Calva could ask for user to input:
More info here: https://clojure-lsp.github.io/clojure-lsp/features/#resolve-macro-as |
@ericdallo https://github.com/emacs-lsp/lsp-mode/blob/73b127f4cf09a443e1353aa6c40b2379b59c1bd6/clients/lsp-clojure.el#L206 In the above line, if the workspace root is nil, then the literal |
yeah, that was a just a test that won't work 😅 we should probably check if the
|
Oh I see... so Calva should get that from the server-info command? |
Calva already send the |
Actually we don't send that in the initialize request... should we be? I do see that clojure-lsp sets the root path itself anyway, it seems. I see it with the server-info command. |
I think calva send the project root, otherwise, clojure-lsp wouldn't scan the project: https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/handlers.clj#L40-L41 |
You can confirm that checking the log between client<->server |
I can see it's sent, but we don't set it ourselves. I think the client library we use is sending it. I can probably just use Edit: |
exactly! |
@ericdallo I'm not sure if this is an issue but I noticed when I only have a single file open (not a project), the resolve-macro-as code action doesn't get returned by the server when the cursor is on a Request and response when a project is open and cursor is on
Request and response when only one file is open (same file as above) and cursor is on
|
@bpringe, yes, it seems this is an issue with the analysis as when you open a single file, clojure-lsp just call clj-kondo for the current file and not a classpath, so it doesn't have the analysis of |
Thanks for explaining. I agree that it's a corner case. 👍 |
@ericdallo Sorry for yet another question on this 😄. I've implemented the code action part of this, and also started implementing a Calva command. The command gets the doc uri, line, and character and calls the command that handles the code action, where the rest of the args are retrieved. However, if no macro actually exists at the cursor position, clojure-lsp adds Should clojure-lsp handle this nil case and not edit the config file if the macro-at-cursor is nil? ;; Cursor here |
(deftest hello .. ;; Config result
{:lint-as {nil clojure.core/def}} |
This is the parsing error, if you're interested. 🤷♂️ {
"resource": "/home/brandon/development/clojure-test/test/core_test.clj",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "syntax",
"severity": 8,
"message": "Can't parse /home/brandon/development/clojure-test/test/core_test.clj, java.lang.NullPointerException",
"source": "clj-kondo",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 1
} |
Np, I like to help :) yes, we can fix it on clojure-lsp, this doesn't happen ATM with emacs since we return the code action only when it works, but anyway we should avoid those things when user calls manually the resolve-macro.
Just to make it clear, It should call the command with 5 args: uri, line, character, macro-to-resolve, config-location |
Thanks. Yeah, the code action is only returned when it works in VS Code as well, but I added a global (enabled in Clojure files) command for Calva. It looked as though lsp-mode did this, but maybe I was mistaken.
I do call the clojure-lsp command like that in the |
Wondering if I should just leave it as a code action and remove the command... simpler that way. 🤔 |
I'm don't know how lsp-mode behaves but I noticed in Calva if just a single file is open, the command results in Note that this is not the code action, as I know that does not show up for single files, as we discussed above. Does clojure-lsp not find the macro at cursor correctly if just a single file is open? If it can't easily be done, maybe I could disable the command if no project is open. |
Never mind, I'm guessing the issue for code actions is the same in this situation too. I just disabled the command if no folder is open. |
I confirmed the resolve macro works on lsp-mode for a simple file |
Hmm... I made a file - (ns core-test
(:require [clojure.test :refer [is deftest testing]]))
(deftest| one-equals-one
(is (= 1 1))) Request + response:
I don't see any errors in the clojure-lsp log file. I see Is that log statement supposed to say the name of the macro it's resolving as? Like Edit: Looks like it does not log which macro it's resolving as the new macro. |
@ericdallo It looks like clojure-lsp's db is used for getting the function name at the cursor. That's supposed to work when only a single file is open?" If that fails, then this |
That function should always return even for single files, It'll only return nil if it doesn't know the document uri, which is if client send it incorrectly
Yep, I'll check it and try to fix it |
@ericdallo Thanks! So, did resolving this same macro work in your single file test with lsp-mode? If so, why did it work there and not for me? Another question - are there cases where resolving a macro with a single file would work? I'm confused as to when this would work with a single file given what you said above (unless the macro definition was in the current namespace). If it wouldn't work in most cases, I wonder if I should disable it unless a folder is open... but I guess even a "folder" being open doesn't mean a "project" is open, so the issue could still exist if a "folder" is open. |
Not, it will not work for deftest or any macro that belongs to another namespace not in the single file, as clojure-lsp don't scan the classpath for single file tests, what I did was just to avoid changing the config to nil and printing a error log to user for those cases.
yes, IMO we should allow resolve the macro only when the |
@ericdallo mentioned we'll need to write something for this to work. I'm just adding this issue to track it for later.
The text was updated successfully, but these errors were encountered: