Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(lua_ls) Fix broken example setup when workspace_folders are not used #3133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikehaertl
Copy link
Contributor

Without this fix I get errors on startup and the config is not applied properly.

LSP[lua_ls]: Error ON_INIT_CALLBACK_ERROR: "[string ":lua"]:79: attempt to index field 'workspace_folders' (a nil value)"

@mikehaertl mikehaertl requested a review from glepnir as a code owner May 2, 2024 17:17
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then
return
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glepnir Actually I wonder if the current example configuration makes much sense anymore. From https://luals.github.io/wiki/configuration/:

The language server loads its settings from one of the following sources, in order of priority:

So the if at the beginning should not be required at all anymore.

And even on_init is probably not necessary: The whole config can just be passed in settings as shown here: https://luals.github.io/wiki/configuration/#neovim

What do you think?

Copy link
Member

@lewis6991 lewis6991 May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I'm using: https://github.com/lewis6991/dotfiles/blob/main/config%2Fnvim%2Flua%2Flewis6991%2Flsp.lua#L137-L146

Basically if there's no .luarc.json which configures the - workspace then apply some default settings which include $VIMRUNTIME. You shouldn't include this unconditionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't include this unconditionally.

But according to the lua_ls documentation that shouldn't be the case: If the server finds a .luarc.json it will not use the config sent from the LSP client (neovim).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that?

@glepnir glepnir requested a review from lewis6991 May 3, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants