BetterThanTomorrow / calva

Clojure & ClojureScript Interactive Programming for VS Code
https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva
Other
1.69k stars 217 forks source link

Untitled Clojure files get no clojure-lsp support #1668

Open PEZ opened 2 years ago

PEZ commented 2 years ago

When using the VS Code command New file (cmd/ctrl+n) and set the language of it to Clojure, you have an Untitled file.

This file gets no clojure-lsp support.

There is some discussion in #1666 around this.

ericdallo commented 2 years ago

The LSP spec is clear about server should handle a URI even if it's not saved on filesystem, that is required for LSPs work on remote filesystems etc. For this case, it seems to me there is not even a URI, so not sure would be possible to handle that, we need to check what vscode-language-client is sending on didOpen or if it's not sending this at all

PEZ commented 2 years ago

In VS Code the ”file” actually has a URI. Don't recall exactly, but something with untitled:// I think. It has a languageId of clojure too, maybe that is something sent with the request?

Maybe we can override it somehow and provide some phony Uri... I'll experiment a bit with it during the weekend.

ericdallo commented 2 years ago

yeah, the languageId is something only on client side I think, server doesn't use/check it, IIRC is not part of the spec. But yeah, a URI is all we (should) need, probably a untitled:// would cause other issues tho

Cyrik commented 2 years ago

I was just reading the docs and this is probably what we need to add to createClient: { scheme: 'untitled', language: 'clojure' }. The file scheme apparently ignores untitled.

PEZ commented 2 years ago

Sounds odd on the create client level. Can you link to the docs, @Cyrik ?

Cyrik commented 2 years ago

It's a bit vague, but that was my interpretation of this part: scheme

bpringe commented 2 years ago

I was just reading the docs and this is probably what we need to add to createClient: { scheme: 'untitled', language: 'clojure' }. The file scheme apparently ignores untitled.

After reading the part of the docs linked, that does seem likely to work.

PEZ commented 2 years ago

The part I don't understand here is why this would go in createClient?

Cyrik commented 2 years ago

The "client" is just the basic vscode implementation that we add our stuff on top of. The documentSelector we provide to the client determines which files are seen as relevant. If a file is seen as irrelevant its contents/changes won't get sent to the LSP server, unless we interfere with the default behavior. Currently, we are saying:

documentSelector: [
        { scheme: 'file', language: 'clojure' },
        { scheme: 'jar', language: 'clojure' },
      ]

So any file or jar that is in the clojure language is relevant and sent to the lsp-server. untitled does not fall into that definition, since it's not a file. So hopefully adding untitled will just fix this problem 😄

PEZ commented 2 years ago

Thanks! That was the context I was lacking. Makes total sense.