LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.24k stars 304 forks source link

Inject library paths at runtime #2330

Open musjj opened 11 months ago

musjj commented 11 months ago

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?

necauqua commented 4 months ago

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