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

Hover broken when repl is connected but cider-nrelp is not present #1432

Closed
simonacca opened this issue Dec 12, 2021 · 6 comments
Closed

Hover broken when repl is connected but cider-nrelp is not present #1432

simonacca opened this issue Dec 12, 2021 · 6 comments
Labels
bug Something isn't working ux User experience related

Comments

@simonacca
Copy link
Contributor

simonacca commented Dec 12, 2021

Hi,

It appears that the hover functionality (formally "Show Hover" and "Show Definition Preview Hover" actions in vscode) is broken in some circumstances (for me at least).

I have made a repo where I can reproduce the issue.

My vscode version: 1.62.3 ccbaa2d27e38e5afa3e5c21c1c7bef4657064247 x64

How to reproduce

  1. clone the repo
  2. open the repo with vscode
  3. open with devcontainers (for example using command "remote-containers: Rebuild and reopen in container")
    aside: I am not sure if devcontainers are necessary to trigger the issue, but this is the only way that I'm able to test as I use
    nix in this setup and am not yet able to get calva to recognize the appropriate clojure-lsp.
  4. wait for clojure-lsp to download and initialize
  5. open the file src/main/core.cljs
  6. verify that hover functionality works correctly at this point (i.e. triggering the "Show Hover" action when the cursor is on defn shows the docs for defn)
  7. start the build with npx shadow-cljs watch app
  8. connect to the build with calva via "Calva: Connect to a running REPL" > shadow-cljs > suggested port > :app
  9. verify that hover functionality doesn't work anymore (i.e. no docs dialog appears at all when triggering the "Show Hover" action)
  10. (not essential) execute the "Calva: disconnect from REPL server" action and observe that Hover works again

Thanks for looking into this! I hope to have not overlooked any of the docs or already open issues.

Addendum: "Clojure language client" output pane transcript

These have been obtained by triggering the Hover action over the defn symbol

Transcript when working
[Trace - 12:14:00 AM] Sending request 'textDocument/hover - (35)'.
Params: {
    "textDocument": {
        "uri": "file:///workspaces/acme-app/src/main/core.cljs"
    },
    "position": {
        "line": 2,
        "character": 2
    }
}


[Trace - 12:14:00 AM] Received response 'textDocument/hover - (35)' in 36ms.
Result: {
    "contents": {
        "kind": "markdown",
        "value": "```clojure\ncljs.core/defn\n```\n\nSame as (def name (core/fn [params* ] exprs*)) or (def\nname (core/fn ([params* ] exprs*)+)) with any doc-string or attrs added\nto the var metadata. prepost-map defines a map with optional keys\n:pre and :post that contain collections of pre or post conditions.\n\n----\n\n*[/home/builder/.m2/repository/org/clojure/clojurescript/1.10.891/clojurescript-1.10.891.jar:cljs/core.cljc](jar:file:///home/builder/.m2/repository/org/clojure/clojurescript/1.10.891/clojurescript-1.10.891.jar!/cljs/core.cljc)*"
    },
    "range": {
        "start": {
            "line": 2,
            "character": 0
        },
        "end": {
            "line": 2,
            "character": 17
        }
    }
}
Transcript when broken
[Trace - 12:12:34 AM] Sending request 'textDocument/documentHighlight - (31)'.
Params: {
    "textDocument": {
        "uri": "file:///workspaces/acme-app/src/main/core.cljs"
    },
    "position": {
        "line": 2,
        "character": 2
    }
}


[Trace - 12:12:34 AM] Received response 'textDocument/documentHighlight - (31)' in 3ms.
Result: [
    {
        "range": {
            "start": {
                "line": 2,
                "character": 1
            },
            "end": {
                "line": 2,
                "character": 5
            }
        }
    }
]


[Trace - 12:12:34 AM] Sending request 'textDocument/codeAction - (32)'.
Params: {
    "textDocument": {
        "uri": "file:///workspaces/acme-app/src/main/core.cljs"
    },
    "range": {
        "start": {
            "line": 2,
            "character": 2
        },
        "end": {
            "line": 2,
            "character": 2
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 12:12:34 AM] Received response 'textDocument/codeAction - (32)' in 24ms.
Result: [
    {
        "title": "Resolve macro 'cljs.core/defn' as...",
        "kind": "quickfix",
        "data": {
            "id": "resolve-macro-as",
            "uri": "file:///workspaces/acme-app/src/main/core.cljs",
            "line": 3,
            "character": 3
        }
    },
    {
        "title": "Cycle privacy",
        "kind": "refactor.rewrite",
        "data": {
            "id": "refactor-cycle-privacy",
            "uri": "file:///workspaces/acme-app/src/main/core.cljs",
            "line": 2,
            "character": 2
        }
    },
    {
        "title": "Extract function",
        "kind": "refactor.extract",
        "data": {
            "id": "refactor-extract-function",
            "uri": "file:///workspaces/acme-app/src/main/core.cljs",
            "line": 2,
            "character": 2
        }
    },
    {
        "title": "Create test for 'init'",
        "kind": "refactor.rewrite",
        "data": {
            "id": "refactor-create-test",
            "uri": "file:///workspaces/acme-app/src/main/core.cljs",
            "line": 2,
            "character": 2
        }
    },
    {
        "title": "Clean namespace",
        "kind": "source.organizeImports",
        "data": {
            "id": "clean-ns",
            "uri": "file:///workspaces/acme-app/src/main/core.cljs",
            "line": 2,
            "character": 2
        }
    }
]
@bpringe bpringe added the ux User experience related label Dec 12, 2021
@bpringe
Copy link
Member

bpringe commented Dec 12, 2021

Thanks for the report! In the case you describe above (although without using a container, and I don't think that's relevant now), provideHover is throwing an exception here, and that exception isn't being handled, so no hover is provided.

I think the exception is happening because while there may be a connection to a cljs repl, there's no connected runtime (no browser running the app - evaluating code in the repl doesn't work).

We should catch the exception there and return null, probably, then clojure-lsp will provide the hover.

@bpringe bpringe added the bug Something isn't working label Dec 12, 2021
@bpringe bpringe added this to To do in Brandon's Board via automation Dec 12, 2021
@bpringe
Copy link
Member

bpringe commented Dec 12, 2021

Ah, actually it seems the exception occurs because your repl doesn't include cider-nrepl. If you start it using Calva's jack-in, or with the following command manually, the hovers will work after the repl is connected.

npx shadow-cljs -d cider/cider-nrepl:0.26.0 watch :app

We still need to handle the exception though for the case when cider-nrepl isn't used.

@bpringe
Copy link
Member

bpringe commented Dec 12, 2021

This is the error that occurs when cider-nrepl is not present: 'The server does not recognize or cannot perform the 'ns-list' operation'. A PR is incoming.

@bpringe bpringe changed the title "Show Hover" functionality broken when calva is connected Hover broken when repl is connected but cider-nrelp is not present Dec 12, 2021
@bpringe
Copy link
Member

bpringe commented Dec 12, 2021

A fix for the case of not using cider-nrepl will be in the next release. For now, you can use the command mentioned above to keep hovers working after connecting to the repl (and you may want to use that command anyway).

@simonacca
Copy link
Contributor Author

Duh, I should have thought of trying the standard jack-in to arrive at a diagnosis... :)

Thank you for the prompt response and for the PR, amazing!
I can cofirm that using calva from the dev branch and no cider-nrepl, I now get the hover content from LSP 👌

For anyone reading this issue in the future that like me needs to start the repl manually, I just discovered that there is a "Calva: Copy Jack-In Command to Clipboard" command to generate the line above from @bpringe (useful in case more dependencies are added, or if you use a different "project type").

Brandon's Board automation moved this from To do to Done Dec 12, 2021
@bpringe
Copy link
Member

bpringe commented Dec 14, 2021

You're welcome! The change is out now as of 2.0.230.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ux User experience related
Projects
Development

No branches or pull requests

2 participants