Your workspace is set to 'x'. Lua language server refused to load this dir.
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Windows
What is the issue affecting?
Other
Expected Behaviour
For this error not to occur, everything else is working just fine.
Actual Behaviour
LSP[lua_ls] Your workspace is set to `C:\Users\waffle`. Lua language server refused to load this directory. Please check your configuration.[learn more here](https://github.com/LuaLS/lua-language-server/wiki/FAQ#why-is-the-server-scanning-the-wrong-folder)
error is occuring even though the LSP works just fine and has been working for years prior to this with the exact same setup with no problems. Not sure what happened here but this error comes up, I remove it and everything is back working like normal. Only happens in the home dir.
Reproduction steps
- Install neovim and luals, open neovim from home path and this error comes up.
Additional Notes
No response
Log File
No response
Add --force-accept-workspace
Add
--force-accept-workspace
This is the template for lua_ls in neovim, where exactly do I add it? Thanks!
require'lspconfig'.lua_ls.setup {
on_init = function(client)
if client.workspace_folders then
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
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower and will cause issues when working on your own configuration (see https://github.com/neovim/nvim-lspconfig/issues/3189)
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {}
}
}
--force-accept-workspace is a launch cmd argument: https://luals.github.io/wiki/usage/#--force-accept-workspace
I don't know much about neovim, but according to the nvim-lspconfig's doc: https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#lua_ls
The default
cmdassumes that thelua-language-serverbinary can be found in$PATH. Default config:
cmd:{ "lua-language-server" }
maybe you have to this flag to the cmd?
require'lspconfig'.lua_ls.setup {
cmd = { "lua-language-server", "--force-accept-workspace" },
on_init = function(client)
... -- your original code above
end,
settings = {
Lua = {}
}
}
--force-accept-workspaceis a launch cmd argument: https://luals.github.io/wiki/usage/#--force-accept-workspaceI don't know much about neovim, but according to the nvim-lspconfig's doc: https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#lua_ls
The default
cmdassumes that thelua-language-serverbinary can be found in$PATH. Default config:
cmd:{ "lua-language-server" }maybe you have to this flag to the
cmd?require'lspconfig'.lua_ls.setup { cmd = { "lua-language-server", "--force-accept-workspace" }, on_init = function(client) ... -- your original code above end, settings = { Lua = {} } }
Thanks for answering! I tried to add --force-accept-workspace but the message seems to persist. Not entirely sure what's going on as I don't see the message anywhere other than in ~ dir with lua files.
I don't see the message anywhere other than in ~ dir with lua files.
By looking into the source code of luals, this error msg is generated during the workspace init logic, when the workspace path is / or ~ without setting the force accept workspace flag: https://github.com/LuaLS/lua-language-server/blob/cdb1b094edf125dc537298cc408f8c751dcedf00/script/workspace/workspace.lua#L46-L54
I guess this logic is to prevent LuaLS preloading too much files, because by default LuaLS will load every files recursively under root workspace path.
I tried to add --force-accept-workspace but the message seems to persist.
Anyway I tried to add a log.info("FORCE_ACCEPT_WORKSPACE", FORCE_ACCEPT_WORKSPACE) there to see its value when I specify a --force-accept-workspace flag, and to my surprise a nil is logged... π
There is another bug π
By further debugging, seems that the arg parsing pattern in the main.lua logic has a bug: https://github.com/LuaLS/lua-language-server/blob/cdb1b094edf125dc537298cc408f8c751dcedf00/main.lua#L20-L28
- The
([%w_]+)pattern can only match flags with underscore_but not a dash- - i.e. it can match
--force_accept_workspaceand set the value into_G["FORCE_ACCEPT_WORKSPACE"] - but (currently) cannot match
--force-accept-workspace... π€¦ββοΈ
The workaround
Try to use --force_accept_workspace for now @leet0rz
I can log the value of FORCE_ACCEPT_WORKSPACE when I specify this flag
cc @sumneko
main.lua δΈθ§£ζ arg ζη¨η pattern δΌΌζ―ζ bug.
-
'^%-%-([%w_]+)(.*)$'εͺθ½ match ε°--force_accept_workspace(underscore η) θδΈθ½ match--force-accept-workspace - ε ηΊ pattern η¨δΊ
[%w_]+ - δΌΌζ―θ¦ζΉζ
[%w_-]+
--force_accept_workspace
It did not work initially but then I updated lua_ls and now that command you gave me the last time worked, thanks :)
@tomlau10
There seems to be a side-effect, now the server scans the home dir and apparently it's not suppose to do that and I am getting a different error message about scanning too many files and files being to big etc. Is there another or better solution here for me? I have default settings for neovim mostly so I would guess this would be the case for others too? As said before this never happened before and all of a sudden it started happening with no changes in my config. Maybe from a update of either neovim or lua_ls.
There seems to be a side-effect, now the server scans the home dir and apparently it's not suppose to do that
You're right, this warning exists because luals thinks that it will scan too much file, but adding --force_accept_workspace is just silencing this warning, as said in my previous comment.
As said before this never happened before and all of a sudden it started happening with no changes in my config.
I git blamed the relevant code: https://github.com/LuaLS/lua-language-server/blob/cdb1b094edf125dc537298cc408f8c751dcedf00/script/workspace/workspace.lua#L46-L56
- it's been there for 2 years π€
- without the
--force_accept_workspace, luals will reject if your open/or~/as the workspace - I have no idea why this never happened before and all of a sudden it started happening ππ
Install neovim and luals, open neovim from home path and this error comes up.
I am unfamiliar with neovim (I use vscode), but here are some questions/suggestions in my mind:
- May I ask why do you want to open home path as the root workspace at the first place?
Since the logic of luals is to recursively scan all files in every sub directories in the root workspace
if you open home path
- then you will either get a warning;
- or let it scan all files I guess?
- just say you have some reasons to open neovim from home path.
- do you really need luals to run in this case?
- maybe you can set some config to disable luals when you open home path? (but let it run in other cases)
- another idea is that maybe you can setup a
.luarc.jsonin your home path with following{ "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", "workspace.ignoreDir": [ "**/*" ] }- this let luals ignores everything such that it won't scan all your folders π€ (you may change the ignore list accordingly)
- and you keep the
--force_accept_workspaceoption to silence the warning as well
Hope this can provide some insight on how to solve your problems π @leet0rz
@tomlau10 I am simply just opening .wezterm.lua - the config file for wezterm, not a project or anything like that. I am getting the warning that it is refusing because it's the home dir and if I add the force workspace setting it will give warnings that there are too many files being scanned or files being too big etc. Do you know if I can set that up inside the lsp settings instead of having a file? I tried to put it under workspace in the lsp and adding ignoreDir there but did not seem to be working.
I am simply just opening
.wezterm.lua- the config file for wezterm, not a project or anything like that
I just find a relevant (?) FAQ: https://luals.github.io/wiki/faq/#why-is-the-server-scanning-the-wrong-folder
When a workspace is opened, the client will send the URI of the directory to be scanned. When you open a single file, the client is supposed to send
nullfor the URI as there is no workspace, just a single file. However, some clients will mistakenly send the URI of the extension, or worse, the home directory. The server will do as it is told and scan what is sent, which can obviously cause issues should the home directory be sent.
There seems to be a single file mode? π€
Then I went to test with vscode:
- create a
.wezterm.luain my home director:C:\Users\TomLau - use the open file to open the
.wezterm.lua- nothing will be scanned from my
C:\Users\TomLau(even though the file is in home directory) - the hover said only
12 filesare cached (probably those built in meta files) - => so this works as expected β
- nothing will be scanned from my
- if otherwise I use open folder to open
C:\Users\TomLau, then select.wezterm.luafrom there- luals now starts to scan my whole home folder... π (because this is workspace mode I guess)
I think it's certainly related to your lua_ls plugin settings and how your plugin send to initialize request to server.
Again I am unfamiliar with neovim, maybe you have to ask help in the neovim community π« .
From my side, I may try to setup a neovim editor with lua_ls to test this situation when I have time.
From my side, I may try to setup a neovim editor with lua_ls to test this situation when I have time.
I just setup neovim on my windows PC and configured luals with the template config provided here: https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/configs/lua_ls.lua
And I can reproduce your situation that, opening a file in home folder will trigger scan all folders π
testing env: luals-3.15.3, neovim-0.10.3, nvim-lspconfig-1.3.0
- open a
C:\Users\TomLau\test.luaβ soon will show warning "Preloaded files has reached the upper limit" and I notice the memory usage of luals exe is increasing continuously in task manager - open a
C:\Users\TomLau\test\test.lua(i.e. a file in an empty folder to test it) β normal, memory usage is stable and no rapid increasing π€ this is expected because the folder is empty - open a
D:\test.lua(I have many subfolders inD:\) β memory usage is increasing rapidly, this suggests that luals and scanning all folders π³
testing env: luals-3.9.3, neovim-0.10.3, nvim-lspconfig-1.3.0
I downgraded my luals to 3.9.3, which is a stable version that I used a while ago, then repeat all testing The result are the same π€ => so unrelated to luals I think
testing env: luals-3.15.3, neovim-0.10.3, nvim-lspconfig-1.0.0
Then I downgraded nvim-lspconfig to a version before you create this issue, which is 1.0.0
(I found it from release page: https://github.com/neovim/nvim-lspconfig/releases)
βΌοΈ no more memory increasing βΌοΈ So the culprit must lie within the nvim-lspconfig π³
git bisect result
I then do a git bisect on nvim-lspconfig (which is a git repo)
There are only 'skip'ped commits left to test.
The first bad commit could be any of:
8d9fd3581ac07a2e1940435e13bda31a0cdeb795
2eccb418f2f972ad1167f8491a8180acdeb02384
We cannot bisect more!
-
8d9fd3581ac07a2e1940435e13bda31a0cdeb795cannot be tested (error when launchingnvim.exe) - but clearly the https://github.com/neovim/nvim-lspconfig/pull/3450 is causing this unknown scan all behavior when opening file in single file mode π¦
- I tested with latest master (
339ccc81e08793c3af9b83882a6ebd90c9cc0d3b) as well and this issue persist
suggestions
- I suggest you to open issue in
nvim-lspconfigrepo: https://github.com/neovim/nvim-lspconfig (or search if there are already issues tracking this problem) - If you decide to open a new issue in that repo
you can also cross link to this issue here, to provide more context for
nvim-lspconfigmaintainer - meanwhile you may try to downgrade your
nvim-lspconfigtov1.0.0or any workable commit before that pr3450 (sayac936a66fba9a58613bed95d7615cff2c5bf0387, as shown in my image above)
@leet0rz
I have default settings for neovim mostly so I would guess this would be the case for others too?
After going through the debugging above, I believe so. A quick scan in nvim-lspconfig's issue page, seems nothing related to this issue. Don't know why no one report it, maybe they don't know where to report to. π
As said before this never happened before and all of a sudden it started happening with no changes in my config.
The culprit PR https://github.com/neovim/nvim-lspconfig/pull/3450 is merged on Nov 24, 2024, and you created this issue on Nov 30, 2024. The time matches. If you always pull the latest master of nvim-lspconfig, this explains that "all of a sudden it started happening with no changes in my (your) config π
update
π€ I believe this is a related issue: https://github.com/neovim/nvim-lspconfig/issues/3531
- seems that now neovim is migrating the
lspconfigsetup to usevim.lsp.config()instead - no more
nvim-lspconfigplugin is needed, but you need the neovim preview version0.11 - the example
init.luasetup for luals: https://neovim.io/doc/user/lsp.html#lsp-quickstart
vim.lsp.config['luals'] = {
-- Command and arguments to start the server.
cmd = { 'lua-language-server' },
-- Filetypes to automatically attach to.
filetypes = { 'lua' },
-- Sets the "root directory" to the parent directory of the file in the
-- current buffer that contains either a ".luarc.json" or a
-- ".luarc.jsonc" file. Files that share a root directory will reuse
-- the connection to the same LSP server.
root_markers = { '.luarc.json', '.luarc.jsonc' },
-- Specific settings to send to the server. The schema for this is
-- defined by the server. For example the schema for lua-language-server
-- can be found here https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
}
}
}
}
vim.lsp.enable('luals')
With this setup, I can now open C:\Users\TomLau\test.lua as well as D:\test.lua, without the strange scan all folders issue.
And no more rapid memory increasing of luals exe now.
@tomlau10 very cool, that seems to be working so far, none of the errors are showing up and I can just place it right into my settings no issues so far. I'll message back if I find anything, strange that I am the only one reporting this, I wonder if this is happening with linux too or if it's a windows related issue and I guess not everyone is on nightly either but it is strange that I am the only person to be reporting this if that is the case lol. Maybe I can set up other LSPs like that too and just get rid of lspconfig, that would be nice.
I also ran into this problem while setting up ~/.wezterm.lua in Neovim.
At that error time (over 10000 file reache~~), ~/.luarc.json is created.
~/.luarc.json exists, loading lua files in other folders will also be problematic.
~/.luarc.json exists, workspace folder is ~.
If you delete ~/.luarc.json, loading lua files in other folders will become normal.
I use vscode to edit ~/*.lua.
~/.luarc.jsonexists, loading lua files in other folders will also be problematic.
I am unfamiliar with neovim, but I believe this this due to the root_markers settings :https://github.com/LuaLS/lua-language-server/issues/2975#issuecomment-2593344275
- it will consider the current directory as a workspace folder if it contains file defined in the
root_markers - so if you set
.luarc.jsonas a root marker, and you have a~/.luarc.json=> thevim.lspwill treat~as a workspace folder and send it to the language server, whenever you edit a file under~home directory - by this concept, clearly we shouldn't create a
.luarc.jsonin the~π€ otherwise it will send the whole workspace files~/**/*to the language server
Having this same issue on Debian 12.10 with neovim v0.10.4
I have the recommended '--force-accept-workspace' set under the luals table cmd option.
luals along with other servers are configured through mason-lspconfig in my nvim-lspconfig.
The error message persists
The workspace is set to 'x' warning and '--force-accept-workspace' option is a red herring.
The root problem is there is a bug in nvim-lspconfig, but it won't be fixed due to the migration to using vim.lsp, as explained here: https://github.com/LuaLS/lua-language-server/issues/2975#issuecomment-2593344275 and here: https://github.com/LuaLS/lua-language-server/discussions/3103#discussioncomment-12359447.
@FugueSoft
Ah okay I see thank you (ToT) I just learned how to set up nvim-lspconfig and we're already migrating (Β΄-οΉ-`;)
wait, so I'm confused. 'neovim/nvim-lspconfig' is being deprecated? And we're migrating to a different thing called vim.lsp? Am I missing something?
I am not neovim user (I use vscode) but AFAIK, it's the manager part of nvim-lspconfig (which manages client-server connections) being deprecated. nvim-lspconfig will remain as a config data only repo π€
https://github.com/neovim/nvim-lspconfig/issues/3531#issuecomment-2565863378
vim.lsp.config is now the recommended way to setup language server, but you will need latest version of neovim (0.11+).
Here is the official quick start guide
https://neovim.io/doc/user/lsp.html#lsp-quickstart
Ah I see, that clarifies things a bit. Thank you!
Figured out what's causing this issue for me, my home directory is a git repo for my dot files. The default from nvim-lspconfig for lua_lsp includes .git as a root_markers.
Specifying the config for lua_lsp in nvim/after and omitting .git from root_markers fixed it.
My home directory is also a dotfiles repo. It's pretty crazy too me that luals is trying to block me from doing something I should be able to do.