Fork me on GitHub
#lsp
<
2022-01-01
>
pinkfrog13:01:42

Using lsp with calva

pinkfrog13:01:25

How to let lsp understand the babashaka related files, for example, as in this project: https://github.com/juxt/site/blob/master/bin/site/#L1. This file does not support functionalties such as jump to definition.

ericdallo14:01:18

@UGC0NEP4Y it's required to have a bb.edn at project root pointing to the project paths so LSP can run bb print-deps

ericdallo14:01:05

Just create a bb.edn file at project root with something like:

{:paths ["bin"]}

pinkfrog14:01:04

Didn’t make it.

pinkfrog14:01:34

What debug information should I look at?

pinkfrog14:01:39

I am using lsp together with calva

ericdallo14:01:35

You need to reload vscode window after creating the file

ericdallo14:01:44

Check clojjre-lsp log

ericdallo14:01:52

It should print the result of classpath scan

ericdallo14:01:45

Check last section

pinkfrog14:01:38

2022-01-01T14:17:09.941Z  INFO [clojure-lsp.server:450] - Starting server...
2022-01-01T14:17:10.036Z  DEBUG [clojure-lsp.nrepl:21] - nrepl not found, skipping nrepl server start...
2022-01-01T14:17:10.084Z  INFO [clojure-lsp.server:319] - Initializing...
2022-01-01T14:17:10.181Z  INFO [clojure-lsp.source-paths:190] - Using given source-paths: #{"src" "dev" "test"}
2022-01-01T14:17:10.224Z  INFO [clojure-lsp.source-paths:190] - Using given source-paths: #{"src" "dev" "test"}
2022-01-01T14:17:11.404Z  INFO [clojure-lsp.db:?] - Reading analysis cache from Datalevin db took 1.19 secs
2022-01-01T14:17:11.410Z  INFO [clojure-lsp.crawler:140] - Using cached classpath for project root /Users/matthew/Drive/dev/samples/site
2022-01-01T14:17:11.412Z  INFO [clojure-lsp.crawler:227] - Analyzing source paths for project root /Users/matthew/Drive/dev/samples/site
2022-01-01T14:17:11.414Z  INFO [clojure-lsp.source-paths:190] - Using given source-paths: #{"src" "dev" "test"}
2022-01-01T14:17:11.416Z  INFO [clojure-lsp.feature.clojuredocs:40] - Refreshing clojuredocs cache...
2022-01-01T14:17:12.350Z  INFO [clojure-lsp.crawler:?] - Project only paths analyzed, took 0.94 secs
2022-01-01T14:17:12.369Z  DEBUG [clojure-lsp.server:?] - :initialize 2285ms
2022-01-01T14:17:12.381Z  INFO [clojure-lsp.server:371] - Initialized!
2022-01-01T14:17:12.383Z  DEBUG [clojure-lsp.server:?] - :initialized 1ms
2022-01-01T14:17:12.383Z  WARN [clojure-lsp.server:267] - {}
2022-01-01T14:17:12.416Z  INFO [clojure-lsp.source-paths:190] - Using given source-paths: #{"src" "dev" "test"}
2022-01-01T14:17:12.419Z  DEBUG [clojure-lsp.server:?] - :didOpen 33ms
2022-01-01T14:17:12.422Z  INFO [clojure-lsp.producer:?] - :testTree 0.00 secs
2022-01-01T14:17:12.446Z  DEBUG [clojure-lsp.server:?] - :documentSymbol 10ms
2022-01-01T14:17:12.492Z  DEBUG [clojure-lsp.server:?] - :semanticTokensRange 3ms
2022-01-01T14:17:12.689Z  DEBUG [clojure-lsp.server:?] - :semanticTokensFull 1ms
2022-01-01T14:17:12.822Z  INFO [clojure-lsp.kondo:?] - Linting whole project files took 0.48 secs
2022-01-01T14:17:21.844Z  INFO [clojure-lsp.source-paths:190] - Using given source-paths: #{"src" "dev" "test"}
2022-01-01T14:17:21.849Z  DEBUG [clojure-lsp.server:?] - :didOpen 5ms
2022-01-01T14:17:21.849Z  INFO [clojure-lsp.producer:?] - :testTree 0.00 secs
2022-01-01T14:17:21.852Z  DEBUG [clojure-lsp.server:?] - :semanticTokensFull 0ms
2022-01-01T14:17:21.852Z  DEBUG [clojure-lsp.server:?] - :documentSymbol 0ms
2022-01-01T14:17:21.904Z  DEBUG [clojure-lsp.server:?] - :codeAction 52ms
2022-01-01T14:17:21.948Z  DEBUG [clojure-lsp.server:?] - :documentSymbol 0ms
2022-01-01T14:18:46.403Z  INFO [clojure-lsp.source-paths:190] - Using given source-paths: #{"src" "dev" "test"}

pinkfrog14:01:13

Deleting the lsp/.cache seems having some change. Testing it.

ericdallo14:01:39

Try this: • rm .lsp/.cache • make sure the bb.edn file exists with that :path and you have updated babashka version • Reload vscode window • Get the logs

ericdallo14:01:04

That's the issue, BTW next clojjre-lsp version will print the reason on this popup, meanwhile you can check logs like you were checking

ericdallo14:01:15

What happens if you run on project: bb print-deps --format classpath ?

pinkfrog14:01:56

But yet, I have no jump to definition functionalities.

ericdallo14:01:18

Where are you testing jump to definition?

pinkfrog14:01:57

Does Calva can either understand deps.edn or bb.end at a single time? So I somehow have to disable the deps.edn part and tell lsp to switch to the bb.edn part?

ericdallo14:01:35

no, it will merge deps from both

ericdallo14:01:56

Almost sure it's a calva issue now, of finding definition of a external deps, I'll try to repro on emacs here first, one sec

thanks3 1
ericdallo14:01:31

nvm, is just to run the script

ericdallo14:01:00

oh, found it

ericdallo14:01:34

the file needs to be a clojure one 😅 like bin/site.clj or bin/site.cljc or bin/site.cljs , in this case only bin/site.clj makes sense

ericdallo14:01:52

otherwise calva will not recognize this as a clojure file and not activate lsp on that one

ericdallo14:01:27

IMO always avoid files without extensions, they just make tool's life harder

ericdallo14:01:36

Tested and it works after renaming

pinkfrog14:01:59

That’s sad though.

pinkfrog14:01:17

It’s meant to be executed as an executable.

pinkfrog14:01:29

Maybe I can tell VSCode to treat it differently. It should be something related with Calva.

ericdallo14:01:34

but still it's possible to be excecuted with the .clj extension

ericdallo14:01:14

my suggestion is to rename it, clojure-lsp for some features check the file type as well alongside with other tools

ericdallo14:01:28

we would need to change on calva and clojure-lsp and emacs etc

ericdallo14:01:40

why not just rename the file to follow the standard?

pinkfrog14:01:06

./bin/site.clj. sounds weird though.

ericdallo14:01:37

that's babashka magic :)

ericdallo14:01:05

you can check how vscode/emacs basic funcionality doesn't work for non .clj files

ericdallo14:01:35

even fixing it on clojure-lsp/calva for example, the basic modes would't behave like it behaves for .clj files

ericdallo14:01:37

you can see how bb also use .clj files for script examples: https://book.babashka.org/#_explicit_requires

pinkfrog14:01:16

Yup. I understand the shebang line part. > you can check how vscode/emacs basic funcionality doesn’t work for non .clj files Thinking on this, for emacs, major-mode file local variable should be fine. Dunno VSC.

pinkfrog14:01:06

Sounds Calva is clever enough to detect the non-extension file as clj:

pinkfrog14:01:41

Yet, adding the file extension indeed makes it work though.

ericdallo14:01:32

yeah, the major-mode file local variable fix that indeed, but calva is probably not activating LSP on that file

ericdallo14:01:50

or lsp is ignoring that

pinkfrog14:01:56

Indeed the activation should depend on the interpreted file type instead of the extension extracted from the file name.

ericdallo14:01:37

yeah, makes sense I think from LSP spec point of view

ericdallo14:01:17

not sure all the places we would need to fix, for sure there is somethign on lsp side about guessing the file type from the extension which is not reliable for those cases