BetterThanTomorrow / calva

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

Clojure-lsp caching in multi-project workspace #934

Closed kstehn closed 1 year ago

kstehn commented 3 years ago

When you have a workspace with multiple projects the lsp only creates one cache folder which is in the first folder.

This causes problems when you have two projects and they have the exact same namespace but diffrent content. For example:

So depending on the order of creating the files you get diffrent result in auto-completion. When i created foo.core in Project-b last and then require in Project-a foo.core somewhere and type foo.core/test i will get test-b suggested and not test-a.

Also another problem which will be unlikely but can happen is on windows when you have many diffrent projects and a lot of namespaces cached. At somepoint the filesystem of windows gets pretty slow for one folder when you have a lot of small files in it.

Another thing, but i am not sure about this, is that not all of the classpath of the other projects will be cached because there might not be scanned.

ericdallo commented 3 years ago

Thanks for the report @kstehn, this probably is related to https://github.com/clojure-lsp/clojure-lsp/issues/191 I'm not sure this is an issue on the server @PEZ since is the responsibility of the client to tell what is the project root, I think in this case would need to start the server in each subproject.

kstehn commented 3 years ago

So i was looking around to find a possible solution. Because it gets a bit annoying to rember That some error/Infos need to be ignored and other Features not really working or only sometimes.

So i found a sample to start multiple lsp based on need. https://github.com/microsoft/vscode-extension-samples/blob/main/lsp-multi-server-sample/client/src/extension.ts#L55

Basicaly when a new file is opened, we just need to check if a ls was already launched for this Project. If not launch it and remember it so we can Later clean it up.

bpringe commented 3 years ago

@kstehn So, in essence Calva would be starting and maintaining a client for each project within a given vscode workspace (starting them as files within the project are opened)?

It seems like this would be resource-intensive versus having a single language server handling all projects, but I'm not sure if there is a better way.

ericdallo commented 3 years ago

Yes, you are right, the correct approach would be clojure-lsp has support for multiple workspaces, I'm afraid is no easy task though.