lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Inject library paths at runtime

Open musjj opened this issue 2 years ago • 1 comments

Is there any way to pass library paths dynamically at runtime e.g. via environment variables like LUA_PATH?

My use-case is that I want to create an isolated development environment with Nix. Nix paths are hashed (/nix/store/rhb22df25vwdq5fr5dba8w873qciqgmg...) so they can change at any time, making static configs like .luarc.json ineffective.

Ideally, the server can pick up the current lua executable in the PATH and automatically detect all the libraries (this is how it works with pyright). Is this currently possible?

musjj avatar Sep 15 '23 17:09 musjj

A standard solution/workaround for issues like those in NixOS is add static etc paths to packages with etc.<name>.source = package

For example:

etc.lua-lsp.source = pkgs.lua-language-server

Which links the lua-language-server of the nixpkgs your system uses to the /etc/static/lua-lsp

And now you can set

  "Lua.misc.executablePath": "/etc/static/lua-lsp/bin/lua-language-server",

in VSCode settings, for example, and it will live through upgrades forever

Same way for your specific issue, the above is an easy example.

Funnily you don't have to have it otherwise installed too, technically every single package is "lazily installed", meaning it only gets actually downloaded to your local store when needed anywhere, in this case to be linked in this stable location lol

necauqua avatar May 08 '24 14:05 necauqua