Lsp langserver config question – doesn't work on single machine!

I don’t think this is an issue with LSP necessarily as I have the same init.lua working on two other machines. But I would love to get this one working too!

I have two lang servers installed: CSS and TypeScript. TypeScript works fine. CSS reports, cmd ["vscode-css-language-server"] is not executable.

When I search for the executable (fd vscode-css-language-server) I see it here:

System/Volumes/Data/usr/local/lib/node_modules/vscode-langservers-extracted/bin/vscode-css-language-server
usr/local/lib/node_modules/vscode-langservers-extracted/bin/vscode-css-language-server

My etc/paths/ looks like this:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/lib

By comparison when I fd typescript-language-server – which is working fine,

I get:

System/Volumes/Data/usr/local/lib/node_modules/typescript-language-server
System/Volumes/Data/usr/local/bin/typescript-language-server
usr/local/lib/node_modules/typescript-language-server
usr/local/bin/typescript-language-server

I’m a beginner with CLI stuff so possible I’m missing something obvious? Or is it possible the executable itself is borked? This machine uses a version of the langserver from a private repo (behind corporate firewall).

Any things to try appreciated!

Maybe css-laguage servers installation wasn’t done properly . You can try reinstalling it . Or try putting a symlink to the binnary on your path with (Assuming ln is available :P)

ln -s usr/local/lib/node_modules/vscode-langservers-extracted/bin/vscode-css-language-server usr/local/bin

Thanks, tried re-installing approx 873 times to no avail :wink:

Tried that cmd too but does not seem to make any difference. Assuming at this point the code package itself must be the problem.

Is there a way of testing the lang server itself outside of Vim to be certain it’s the install that’s borked?

Yes, you should be able to execute it on the command line by entering the joined string of the “cmd” table

1 Like

Thanks, I run vscode-css-language-server --stdio and get:

zsh: command not found: vscode-css-language-server

So something defo off with that package by the looks of things?

 ~/test  master ?1
❯ npm i -g vscode-langservers-extracted

 ~/test  master ?4
❯ which vscode-css-language-server
/usr/local/bin/vscode-css-language-server

 ~/test  master ?4
❯ vscode-css-language-server --stdio

This is where it is on macos, not sure on linux.

1 Like

Thanks, defo not being found on mine so I’ll get our IT dept to try and re-add to our local feed. Thanks for the help

You have the server binary in

/System/Volumes/Data/usr/local/lib/node_modules/vscode-langservers-extracted/bin/vscode-css-language-server

Right ? I’m assuming you ran fd from root of filesystem .

Check if you can run the binary with full path. You either have to put the binary in your $PATH or specify full path to the binary in your config.

You should be able to specify full path to executable in you config with cmd key.

Probably something like this

require'lspconfig'.cssls.setup {
  cmd = {'/System/Volumes/Data/usr/local/lib/node_modules/vscode-langservers-extracted/bin/vscode-css-language-server
', '--stdio'}
}

Yes! That works! Thanks @shadman

Now I just need to add some sort of environment variable in my init.lua so I can have a different cmd for this one machine!

Just to close the loop here…

Thankfully, a little control flow into the init.lua can deal with with this, providing one path when in one environment and another when it another.

I’m using zsh as my shell, so set an environment variable there. In the .zshrc I added this line:

export MACHINE=work

Then in my init.lua I added this:

-- different path for CSS lang server on office machine
local envMachine = os.getenv("MACHINE")
if envMachine == "work" then
    machineCmd = 'SPECIAL PATH HERE'
else
    machineCmd = 'vscode-css-language-server'
end

And then in the init.lua, used that machineCmd as the cmd: cmd = {machineCmd, '--stdio'},