Fork me on GitHub
#lsp
<
2023-11-06
>
magnars07:11:43

This might be off topic here, but I'll give it a shot. I'm using lsp-mode in emacs along with the built-in vscode-langservers-extracted to get CSS lsp features. Any way to make this aware of multiple .css files at once? Right now I can navigate to vars defined in the same css file, but not other files.

ericdallo13:11:18

never did that, but I feel like it's missing the concept of project to know other css files

magnars13:11:21

Sounds likely!

pez11:11:36

Can I configure clojure-lsp so that it serves .cljs files as well as it serves .clj files? It’s my #joyride scripts, which are .cljs. Details in 🧵 ->

pez11:11:59

If e.g. hover a symbol reset! in the script. I get a very bare bones and boring hover. The lsp message log looks like so:

[Trace - 12 :02:43 PM] Sending request 'textDocument/hover - (32)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/pez/.config/joyride/scripts/js_repl.cljs"
    },
    "position": {
        "line": 54,
        "character": 13
    }
}


[Trace - 12:02:43 PM] Received response 'textDocument/hover - (32)' in 12ms.
Result: {
    "range": {
        "start": {
            "line": 54,
            "character": 12
        },
        "end": {
            "line": 54,
            "character": 18
        }
    },
    "contents": {
        "kind": "markdown",
        "value": "
clojure\nreset!\n
\n\n----\n\n*[/Users/pez/.config/joyride/scripts/js_repl.cljs](file:///Users/pez/.config/joyride/scripts/js_repl.cljs)*"
    }
}
Renaming the file to foo.clj, the exchange looks like so:
[Trace - 12:03:15 PM] Sending request 'textDocument/hover - (36)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/pez/.config/joyride/scripts/js_repl.clj"
    },
    "position": {
        "line": 54,
        "character": 12
    }
}


[Trace - 12:03:15 PM] Received response 'textDocument/hover - (36)' in 13ms.
Result: {
    "range": {
        "start": {
            "line": 54,
            "character": 12
        },
        "end": {
            "line": 54,
            "character": 18
        }
    },
    "contents": {
        "kind": "markdown",
        "value": "
clojure\nclojure.core/reset!\n[atom newval]\n
\n\nSets the value of atom to newval without regard for the\ncurrent value. Returns newval.\n\n__Examples:__\n\n
clojure\nuser=> (def x (atom 10))\n#'user/x\n\nuser=> @x\n10\n\nuser=> (reset! x 20)\n20\n\nuser=> @x\n20\n
\n\n__See also:__\n\n[clojure.core/swap!]()\n\n[clojure.core/compare-and-set!]()\n\n[clojure.core/atom]()\n\n[clojure.core/swap-vals!]()\n\n[clojure.core/reset-vals!]()\n\n----\n\n*[/Users/pez/.m2/repository/org/clojure/clojure/1.11.1/<clojure-1.11.1.jar:clojure/core.clj](jar:file:///Users/pez/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar!/clojure/core.clj)*>"
    }
}

ericdallo11:11:16

If kondo provides that analysis it should work, otherwise it's a bug in clojure-lsp or kondo, but before I'd check if the classpath is correct as most of the time issues like that are related to classpath

ericdallo11:11:46

Even if this comes from clojure.core or cljs.core

pez11:11:50

Server info says:

"classpath": [
    "/Users/pez/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar",
    "src",
    "/Users/pez/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar",
    "test",
    "/Users/pez/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar",
    "scripts"
  ],

pez11:11:15

I have placed a deps.edn file there to help clojure-lsp:

{:paths ["src" "scripts"]}

pez11:11:46

Ideally I’d wish for a joyride.edn. But that’s a separate story. 😃

ericdallo12:11:42

so there is no clojurescript deps on the classpath right?

ericdallo12:11:31

that's the problem I guess, a empty deps.edn includes only clojure.core stuff, for cljs you would need to explicit declare that dep

pez12:11:17

Thanks! That worked. Even if it doesn’t really make sense to add clojurescript deps, since we’re not using ClojureScript. @U04V15CAJ, what’s the recommended config for nbb?

borkdude12:11:01

there is none

✔️ 1
pez13:11:19

Is there a way I can use nbb to calculate the classpath?

pez13:11:09

Thinking I could do something like so.

{:project-specs [{:project-path "joyride.edn"
                  :classpath-cmd ["npx" "nbb" "-e" ",,,"]}]}

borkdude13:11:17

@U0ETXRFEW yes, there is nbb.classpath/get-classpath

pez13:11:45

Thanks! I’ll have a look!

ericdallo13:11:20

@U0ETXRFEW if you find some sane default for joyride.edn , we can open a PR on clojure-lsp to consider that project spec as default if that makes sense

pez13:11:29

Awesome. I’ll try to figure this out.

pez13:11:44

@U04V15CAJ, it’s a bit unclear to me how to populate the classpath from a map like this

{:paths ["src" "scripts"]
 :deps {org.clojure/clojurescript {:mvn/version "1.11.54"}}}

borkdude13:11:45

do you have this in nbb.edn?

pez13:11:54

No. I could, I guess, but it gets to be a similar problem as having it in deps.edn. Can I tell nbb to look elsewhere for the config?

borkdude13:11:12

I guess you could make a deps.edn with a joyride alias and configure lsp to include the joyride alias

pez13:11:57

Ah, yes. Creates a dependency on clojure though. Can I have aliases in nbb.edn?

borkdude13:11:19

what do you mean a dependency on clojure

borkdude13:11:25

no you can't

ericdallo13:11:42

I think a good idea would be to have a joyride.edn which would add the clojurescript deps via CLI args in the classpath-cmd of the project spec?

pez13:11:47

I don’t want a Joyrider to depend on clojure.

borkdude13:11:22

nbb.edn depends on bb FWIW, how else did you think it deals with all the maven stuff, magically re-implement everything in Node.js? ;)

pez13:11:44

Lately I have been considering to bundle bb with Calva. This could push me over to the yes side of that…

borkdude13:11:21

you already include deps.clj which is the ingredient used by bb to do all of this maven stuff

pez13:11:41

Indeed… :thinking_face:

pez13:11:47

So deps.clj supports custom config files? (Not just deps.edn)

borkdude13:11:12

It does, with -Sdeps-file

pez13:11:53

Great. I don’t want to depend on Java either, but bundling bb or a binary deps.clj might be the way.

borkdude13:11:11

deps.clj always depends on java

pez13:11:30

There’s a binary dist, right?

borkdude13:11:00

there is a deps.clj binary but deps.clj is just the clj bash script ported to clojure unless you're going to use tools-deps-native https://github.com/babashka/tools-deps-native

pez13:11:19

I actually do not care so much what is used. I just want as few dependencies as possible. Joyride is fully usable without any other dependency. I’d like to keep it like that. Here it is OK with a Calva dependency, since it is Calva that wants clojure-lsp to have the classpath.

pez13:11:22

@UKFSJSM38, does clojure-lsp have a way to resolve classpaths from a deps map?

pez13:11:03

tools-deps-native looks interesting

pez14:11:36

Hmmm, this was surprisingly tricky!

pez14:11:13

Maybe the solution is to make Calva check if bb is installed on the classpath. If it isn’t, install it and help the user get it on the PATH. And then the classpath-cmd in clojure-lsp will use bb if it is installed, otherwise just return whatever is in paths of joyride.edn. WDYT?

borkdude14:11:22

That's fine but users will still require java, since bb calls deps.clj I think 99% of joyride users will already have it installed though

pez14:11:13

Hmm, still java… Then I don’t want to go that way. 😃 I’ll think some more here…

borkdude14:11:38

You won't avoid using java no matter what way of entry into deps.clj you will use

pez14:11:02

Yeah, tools-deps-native may be my only option.

pez14:11:35

But that creates other problems that I have not yet solved…

borkdude14:11:58

I'd say just go with deps.clj since you already have it in Calva - this is just for clojure-lsp right?

pez14:11:27

Yeah, it’s for creating as nice a dev ux as I can for Joyriders.

borkdude14:11:38

Calva could expose a command for calculating a classpath given a .edn file and then call deps.clj

pez14:11:33

Calva can’t expose anything to command line tools.

borkdude14:11:42

deps.clj could also have an option to use tools-deps-native so you can avoid java, but the only thing is, that tools-deps-native I consider an experimental project

pez14:11:14

I saw the experimental tag. I think that’s fine.

borkdude14:11:24

Perhaps you can experiment with this, I'd be open to an option + PR ;)

🙏 1
pez14:11:36

From a Joyride perspective. I get if you don’t think that way about deps.clj.

borkdude14:11:45

what deps.clj could do, given an environment variable DEPS_CLJ_TOOLS_DEPS_NATIVE=true , it could download (instead of the tools jar) the binary

pez14:11:32

It’s actually not that easy to call deps.clj from the command line either. First I need to know where it is, and VS Code won’t tell me. 😃

borkdude14:11:57

maybe try with tools-deps-native only then

borkdude14:11:43

$ tools-deps-native

tools.deps.edn ...

          help  show this help message
          deps  output a claspath map from a deps map
  create-basis  output a basis from a set of deps sources and a set of aliases
     root-deps  output the root deps.edn
    slurp-deps  read, canonicalize and output a deps.edn file
user-deps-path  output the path to the users deps.edn file

pez14:11:50

It’s a bit the same there. But I guess Calva can place it in a known place. Same with deps.clj.

pez14:11:10

That’s a sweet cli!

borkdude14:11:11

"But I guess Calva.." I guess you mean joyride?

pez14:11:49

Calva or Joyride. I’m undecided. It is Calva that is bringing in clojure-lsp.

borkdude14:11:51

$ tools-deps-native deps '{:deps {medley/medley {:mvn/version "1.0.0"}}}'
{:classpath-roots ["/Users/borkdude/.m2/repository/medley/medley/1.0.0/medley-1.0.0.jar" "/Users/borkdude/.m2/repository/org/clojure/clojure/1.7.0/clojure-1.7.0.jar"], :classpath {"/Users/borkdude/.m2/repository/medley/medley/1.0.0/medley-1.0.0.jar" {:lib-name medley/medley}, "/Users/borkdude/.m2/repository/org/clojure/clojure/1.7.0/clojure-1.7.0.jar" {:lib-name org.clojure/clojure}}}

pez14:11:58

I guess Joyride makes most sense. We are to support a joyride.edn project spec after all.

pez14:11:18

No Windows binary, right?

borkdude14:11:18

ok, would be a nice way to mature tools-deps-native I guess

pez14:11:53

Ah, I think I read somewhere that there were only binaries for Mac and Linux.

borkdude14:11:00

README is stale

pez14:11:19

Great that reality wins over the map!

borkdude14:11:34

tools-deps-native is also designed to be used in conjunction with tools.bbuild: https://github.com/babashka/tools.bbuild tools.build for bb without java :)

pez14:11:37

OMG. You are crazy in the most wonderful way.

pez14:11:46

It would be nice if I could call tools-deps-native like so:

$ tools-deps-native --deps-file joyride.edn --print-path
And it would print the path how clojure -Spath prints it.

borkdude15:11:13

dude, you can script right?

pez15:11:04

I like to think so. 😃 But it’s a bit awkward to script in a vector of command line args. And to make it compatible across platforms.

borkdude15:11:58

first make it work, then improve, it seems like you're asking for premature features

borkdude15:11:42

you can do this from JS/node.js

👍 1
borkdude15:11:56

which should be relatively OS-friendly

pez15:11:02

I created an issue for it.

pez15:11:53

I’ll try with scripting it. maybe "npx" "nbb" … is the way to go.

borkdude15:11:39

that doesn't make sense to me, I thought you said you wanted to not use bb / java you didn't have to. nbb uses both for resolving deps from nbb.edn

pez15:11:15

I mean to pipe tools-deps-native’s output to nbb.

borkdude15:11:25

why nbb though?

borkdude15:11:30

you're already in joyride?

pez15:11:41

I’m on the command line. No Joyride.

borkdude15:11:27

how are you on the command line? I don't get it. Btw, you could write a small JS file as part of joyride's package that you can call from the command line.

borkdude15:11:44

e.g. a "bin" entry in the package.json

pez15:11:59

clojure-lsp asks for a classpath-cmd. That’s what I need to construct.

pez15:11:50

Still the problem with how the command line should find the Joyride bin directory. There doesn’t seem to be a clean way to do that.

borkdude15:11:06

doesn't npx joyride_deps work?

borkdude15:11:19

or node_modules/.bin/joyride_deps?

borkdude15:11:42

or node_modules/joyride/scripts/deps

pez15:11:45

what’s joyride_deps?

borkdude15:11:00

an imaginary script that you package in joyride's npm package

pez15:11:20

Ah, so now there’s a joyride npm package? 😃

borkdude15:11:42

vscode doesn't have an node_modules dir?

pez15:11:17

Well, I guess it has, but it won’t tell us where it is.

borkdude15:11:25

perhaps joyride can spit the JS script on startup to some known location

pez15:11:47

Yes. That should work.

borkdude15:11:59

unless clojure-lsp kicks in before joyride ever started ;)

pez15:11:02

I’ll add this idea to the issue.

pez15:11:29

We can rely on that Calva is pretty slow to start. And Joyride is very fast. 😃

borkdude15:11:36

perhaps we can make an npm package (in squint of course :P) that downloads/caches tools-deps-native and offers a neat JS interface for downloading clojure deps :P

pez15:11:52

squint can read edn structures, I am guessing?

borkdude15:11:21

It doesn't have EDN on board currently, but you can do it via https://github.com/jorinvo/edn-data Someone has used this from squint quite recently

pez15:11:03

I wonder if this creates a node dependency that we could avoid.

pez15:11:48

Something needs to run the JS code?

borkdude15:11:28

you want to do the downloading/caching/etc of tools-deps-native rather using bash and powershell?

borkdude15:11:18

you were the one who suggested npx nbb

pez15:11:30

Yeah, that also has that problem.

pez15:11:45

We handle the download for deps.clj and clojure-lsp in Calva, so we could do this in Joyride for tools-deps-native too.

borkdude15:11:22

then "stub" the scripting part for now with bb or nbb and we can optimize that part later in tools-deps-native perhaps

borkdude15:11:54

this is the "pre-mature" part that's probably too early to decide on now unless you're 100% certain you're going the tools-deps-native route

pez15:11:12

Makes sense to me.

borkdude16:11:35

Piping to jet also works ;)

$ tools-deps-native deps '{:paths ["src"] :deps {medley/medley {:mvn/version "1.3.0"}}}' | jet -t ':classpath-roots (str/join ":")'
"src:/Users/borkdude/.m2/repository/medley/medley/1.3.0/medley-1.3.0.jar:/Users/borkdude/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/Users/borkdude/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar:/Users/borkdude/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar"

borkdude16:11:55

But bb is more flexible since it supports fs/path-separator

pez19:11:01

The classpath is always separated with :, no?

borkdude19:11:31

not on Windows

pez19:11:39

Haha, wtf.

borkdude19:11:47

on Windows it's ;

borkdude19:11:08

this is because on Windows you can have colons in paths: c:\Users\...

👍 1
pez19:11:36

I’m contacting the developer for more information.

😂 1
borkdude19:11:29

Don't download it through http://Finder.app, but just using curl

borkdude19:11:43

or use sudo xattr -c ./tools-deps-native

ericdallo19:11:31

or use linux 😛

borkdude19:11:40

This is with all unsigned binaries, just don't use a GUI to download and unzip them on macOS

borkdude19:11:09

or use linux

borkdude19:11:18

or Windows ;)

🤯 2
borkdude19:11:09

but why even use a GUI if you can use the Terminal ;)

pez19:11:42

Yeah, Joyride is going to download it without clicking so then this is not a problem. 😃

borkdude19:11:53

btw how many deps do you expect joyride users to have in joyride.edn?

pez19:11:08

The way to solve the GUI problem using the GUI is to right-click the binary and select Open from the context menu. Then click Open in the warning dialog. I think that does something similar to sudo xattr.

pez19:11:03

I think only the for the ones that are built-in joyride. ClojureScript, rewrite-clj, promesa, and such.

borkdude19:11:58

right and some :paths ?

pez19:11:43

Four paths to begin with, I think. src, script, ~/.config/joyride/src, and ~/.config/joyride/scripts.

pez19:11:14

Though I am thinking joyride.edn could also be used to configure more paths for Joyride, WDYT?

borkdude19:11:16

that's what I wondered about

pez20:11:39

This almost works (if I forget about windows for a moment)

{:project-specs [{:project-path "joyride.edn"
                  :classpath-cmd ["bash" "-c" "$HOME/binaries/tools-deps-native deps \"`< joyride.edn`\" | jet -t ':classpath-roots (str/join \":\")'"]}]}
What trips things up now is the quotes around the string that jet outputs.

borkdude20:11:41

add println

pez20:11:23

println doesn’t do it

pez20:11:35

oh, yes, Last in the thread… now it works.

🎉 1
pez20:11:16

Well, this command line works:

$HOME/binaries/tools-deps-native deps "`< joyride.edn`" | jet -t ':classpath-roots (str/join ":") println'
But I don’t get it to work when configuring is as the :classpath-cmd

pez20:11:04

I can’t shake the feeling that the interface of tools-deps-native could be a bit less demanding.

borkdude20:11:30

well sure, the interface is just a quick hack to see if stuff works

borkdude20:11:37

it's an experiment you know

pez20:11:30

I like it the experiment. 😃 Just that for my use case an interface where I could have it read a file and spit out the path would remove the need of binaries and the problem with windows compatibility.

borkdude20:11:03

the need of binaries?

pez20:11:17

more binaries than tools-deps-native.

borkdude20:11:17

feel free to submit a PR of whatever you need, as long as you also add tests

🙏 1
pez20:11:22

I probably will. Next week. I used up this week’s budget for this in trying and failing to get the command line to work. 😃

Drew Verlee21:11:30

Can someone help me get LSP within emacs to work with my emacs files, or understand why it doesn't (so i can blacklist those files)? Here is the message i get when emacs starts, annoyingly this happens on every start i presume because my setup tries to load a project/directory which has a yaml file.

Server yamlls:55671/starting exited (check corresponding stderr buffer for details). Do you want to restart it? (y or n) 
If i select Y, i get re-asked the same question until i choose n. If i check the messages buffer i see that in response to answering "y" i get:
LSP :: Restarting LSP in buffer pipeline.yml
LSP :: Connected to [yamlls:55871/starting /home/drewverlee/devops].
LSP :: yamlls has exited (exited abnormally with code 1)
error in process sentinel: Quit [2 times]
So it seems like a yaml file is trying to be read by LSP, then their is an error in the process. My guess is that lsp can't handle this file properly, maybe cause it's aws yaml or something? I'm not sure how to find out more, if i look at lsp logs i see this related to lsp.
The following clients were selected based on priority: (server-id yamlls, priority 0)
Command "/home/drewverlee/.emacs.d/.cache/lsp/npm/yaml-language-server/bin/yaml-language-server --stdio" is present on the path.
Com
though their is a lot more going on. If i got to the lsp yaml site i see instructions to install the yaml server
npm install -g yaml-language-server
I went ahead did that (i think i already had those packages), and restarted emacs but it had no effect. I assume emacs can find them correctly as i used -g. My next step is probably to blacklist those yaml files, under the assumption that lsp is just failing because their some special aws yaml. But it would be nice to know for sure. Any ideas?

ericdallo22:11:12

• Just to make sure, that's not related with clojure or clojure-lsp right? • I agree the yamlls is crashing when starting which is bad • emacs is probably not finding yaml-language-server in the PATH, one way to test that is start emacs from terminal which should inherit the PATH env, you can check that with (getenv "PATH") i think

Drew Verlee22:11:45

It's not related to clojure. Your right, I'm just so used to asking lsp questions here. -_-.

Ed11:11:29

what have you got lsp-yaml-server-command set to? From the error, it looks like it's trying to execute /home/drewverlee/.emacs.d/.cache/lsp/npm/yaml-language-server/bin/yaml-language-server (does that file exist?) How have you installed npm? Are you using nvm? That will change where npm install -g puts it's files. When I install the yaml server lsp-mode seems to run

/usr/bin/npm -g --prefix /var/home/ed/.emacs.d/.cache/lsp/npm/yaml-language-server install yaml-language-server
so maybe you should include the --prefix /home/drewverlee/.emacs.d/.cache/lsp/npm/yaml-language-server/ bit in your manual npm install??

👀 1
practicalli-johnny13:11:59

yamls server seems to be broken on my Linux system for Emacs 29. Running Emacs from a desktop launcher did not have npm on the path, so it was not picked up by Emacs. Adding npm to the path in the .profile configuration file allowed the server to be installed (manually, via lsp-server-install). Although yamls is installed it still seems to fail at startup or when opening a .yaml file

LSP :: yamlls has exited (exited abnormally with code 127)
So either an issue with the sever or lsp-mode (or a combination of the two). It seems I also had issues with yamls with neovim too (I disabled it and used prettierd instead)

aisamu13:11:21

> I went ahead did that (i think i already had those packages), and restarted emacs but it had no effect. I assume emacs can find them correctly as i used -g. You're right, the logs show you already had those packages. lsp-mode does that for you "automatically". To see the installation for yourself, uninstall the global, delete the .cache/npm/... binary and visit the yaml again. (calling lsp-install-server with the universal argument (C-u) also forces a reinstall).

Ed14:11:10

if yamls is broken maybe installing yamllint and enabling yaml-yamllint in flycheck would be good enough?

😞 1
Drew Verlee18:11:48

thanks for the suggestions everyone.