Closed axdank closed 4 months ago
I have the same issue but mine happens when giving @class
annotation.
Same for me for ---@class
and types in many cases. Maybe it's due to the files being required
from multiple places in the code?
I just changed it so that the workspace folder itself is not added as a library. The issue you're seeing should not be possible with default lsp-config and lazydev.
Your project root should be the LSP root, and it's lua
folder should be added to the workspace libraries.
The top-level root folder won't be included because of the path
and pathStrict
settings.
What does :LspInfo
say is your lsp root?
And what do you see when you enable lazydev opts.debug = true
?
Client: lua_ls (id: 1, bufnr: [7, 86])
filetypes: lua
autostart: true
root directory: /Users/alex/.dotfiles/.config/nvim
cmd: /Users/alex/.local/share/nvim/mason/bin/lua-language-server
My luals
is configured as follows:
lua_ls = {
settings = {
Lua = {
workspace = {
checkThirdParty = false,
},
codeLens = {
enable = true,
},
completion = {
callSnippet = 'Replace',
},
doc = {
privateName = { '^_' },
},
hint = {
enable = true,
setType = false,
paramType = true,
paramName = 'Disable',
semicolon = 'Disable',
arrayIndex = 'Disable',
},
},
},
},
That's all fine. What does lazydev debug show?
## ~/.dotfiles/.config/nvim
- **runtime** `/opt/homebrew/Cellar/neovim/0.10.0/share/nvim/runtime/lua`
- `~/.local/share/nvim/lazy/luvit-meta/library`
- **nvim** `~/.config/nvim/lua`
- **conform.nvim** `~/.local/share/nvim/lazy/conform.nvim/lu
## [single]
- **runtime** `/opt/homebrew/Cellar/neovim/0.10.0/share/nvim/runtime/lua`
- `~/.local/share/nvim/lazy/luvit-meta/library`
That's all correct. Do you still see the dups?
yeah, changing the dir to lua
did not do anything (not that I was expecting it to)
Yeah and I still having this issue too (updated lazydev):
Client: lua_ls (id: 4, bufnr: [2, 3, 4])
filetypes: lua
autostart: true
root directory: /home/raydev/git/dotfiles/nvim
cmd: /home/raydev/.local/share/nvim/mason/bin/lua-language-server
lua_ls = {
settings = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
window = {
progressBar = false,
},
hint = { enable = true },
},
},
},
Just checked that I have the latest version: "lazydev.nvim": { "branch": "main", "commit": "ae12a6224c466315f6ecbe6ed1ee7c5641f21d40" },
and LuaLS also up to date?
I can't reproduce this. Can you create an example file that should trigger this?
debug:
:lua = require("lazydev.workspace").global()
<1>{
client_id = -1,
library = { "/home/axdank/.local/share/bob/v0.10.0/nvim-linux64/share/nvim/runtime/lua" },
root = "global",
settings = {},
<metatable> = <2>{
GLOBAL = "global",
SINGLE = "single",
__index = <table 2>,
add = <function 1>,
client = <function 2>,
debug = <function 3>,
enabled = <function 4>,
find = <function 5>,
get = <function 6>,
get_root = <function 7>,
global = <function 8>,
is_special = <function 9>,
new = <function 10>,
single = <function 11>,
update = <function 12>,
workspaces = {
["-1global"] = <table 1>,
["1/mnt/hdd/axdank/dotfiles/nvim"] = {
client_id = 1,
library = { "/home/axdank/.config/nvim/lua", "/home/axdank/.local/share/bob/v0.10.0/nvim-linux64/share/nvim/runtime/lua", "/home/axdank/.local/share/nvim/lazy/fzf-lua/lua", "/home/axdank/.local/share/nvim/lazy/mason.nvim/lua", "/home/axdank/.local/share/nvim/lazy/lazydev.nvim/lua" },
root = "/mnt/hdd/axdank/dotfiles/nvim",
settings = {
Lua = {
diagnostics = {
globals = { "vim", "axcore" }
},
runtime = {
path = { "?.lua", "?/init.lua" },
pathStrict = true,
version = "LuaJIT"
},
workspace = {
checkThirdParty = false,
library = { "/home/axdank/.local/share/bob/v0.10.0/nvim-linux64/share/nvim/runtime/lua", "/home/axdank/.config/nvim/lua", "/home/axdank/.local/share/nvim/lazy/fzf-lua/lua", "/home/axdank/.local/share/nvim/lazy/mason.nvim/lua", "/home/axdank/.local/share/nvim/lazy/lazydev.nvim/lua" }
}
}
},
<metatable> = <table 2>
},
["1single"] = {
client_id = 1,
library = {},
root = "single",
settings = {
Lua = {
diagnostics = {
globals = { "vim", "axcore" }
},
runtime = {
path = { "?.lua", "?/init.lua" },
pathStrict = true,
version = "LuaJIT"
},
workspace = {
checkThirdParty = false,
library = { "/home/axdank/.local/share/bob/v0.10.0/nvim-linux64/share/nvim/runtime/lua" }
}
}
},
<metatable> = <table 2>
}
}
}
}
Actually I did clone LazyVim/LazyVim
to try but surprisingly it works fine without any issue...
I think I fixed it. Problem is symlinks vs real paths. Can you verify it works?
works for me! thanks my hero!
Great :)
I also use symlinks, but it worked for me because I typically edit in my ~/dot
folder which is a real folder
now it works perfect, just my problem is that I use symlinks, thx @folke
Thanks @folke, how do you have the stamina I will never understand :)
@folke I find another problem. I use nix home-manager. I edit file in ~/.config/home-manager
, and nix will produce these files to /nix/store/xxxxxx.lua
, and link files to ~/.config/nvim
. When I edit files in ~/.config/home-manager
, I also get the duplication definitaion warning.
@nanozuki that's not possible to fix I think, since I would have to check all the lua files and dereference them to their real path. Not something that I'd do.
I'd also argue that duplicates like these are a LuaLS bug, since it should know it's the same file and hence not a dup.
Either way, can you paste the contents of :LazyDev
? Just to make sure it's not something else
I understand this is a tricky situation. I accept any result and appreciate your work.
:LazyDev
print this:
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
},
format = {
enable = false
},
hint = {
enable = true
},
runtime = {
path = { "?.lua", "?/init.lua" },
pathStrict = true,
version = "LuaJIT"
},
telemetry = {
enable = false
},
workspace = {
checkThirdParty = false,
library = { "/nix/store/hhmcp0p0y2kjgjgpxs4ygna3d04cadsh-neovim-unwrapped-0.10.0/share/nvim/runtime/lua", "/Users/crows/.local/share/nvim/lazy/luvit-meta/library", "/Users/crows/.config/home-manager/configs/nvim/lua", "/Users/crows/.config/nvim/lua" }
}
}
}
And { debug = ture }
print this:
Info 16:37:24 notify.info lazydev.nvim ## ~/.config/home-manager/configs/nvim
- **runtime** `/nix/store/hhmcp0p0y2kjgjgpxs4ygna3d04cadsh-neovim-unwrapped-0.10.0/share/nvim/runtime/lua`
- `~/.local/share/nvim/lazy/luvit-meta/library`
- **nvim** `~/.config/home-manager/configs/nvim/lua`
- **nvim** `~/.config/nvim/lua`
Info 16:37:24 notify.info lazydev.nvim ## [single]
- **runtime** `/nix/store/hhmcp0p0y2kjgjgpxs4ygna3d04cadsh-neovim-unwrapped-0.10.0/share/nvim/runtime/lua`
- `~/.local/share/nvim/lazy/luvit-meta/library`
What's the output of
:=vim.tbl_map(vim.uv.fs_realpath, {"/Users/crows/.config/home-manager/configs/nvim/lua", "/Users/crows/.config/nvim/lua"})
{ "/Users/crows/.config/home-manager/configs/nvim/lua", "/Users/crows/.config/nvim/lua" }
These files are not linked.
And my neodev.conf's opt works fine. Just in case these will help.
{
override = function(root_dir, options)
if root_dir:find('config.*nvim') then
-- enable plugins in config managers
options.plugins = true
end
end,
}
In that case there's little I can do (not linked).
Fine, thanks for your time.
I wonder why the path .config/nvim
was added to "workspace.library". I didn't open any files in it.
Because you require a file from your neovim config in the files you have open.
lazydev then resolves that module with vim.loader
to the path in your ~/.config/nvim
folder
Is it possible to resolve the module in the current workspace first? The file I required exists in the current workspace.
In the screenshot, is .config/home-manager/configs/nvim/lua/config/configs.lua
requries .config/home-manager/configs/nvim/lua/config/globals.lua
. (root dir for LuaLS is .config/home-manager/configs/nvim
)
After the manager produce the files, it's .config/nvim/lua/config/configs.lua
requires .config/nvim/lua/config/globals.lua
.
@folke I read the code of "lazydev," and I think we can add workspace modules when the lua ls attach to the buffer ("M.on_attach"). Do you have interested or suggestion in this? I can make a PR for this.
@nanozuki can you check the new version?
@folke Awesome! All "duplicated" warnings are gone. Thank you, it helps a lot.
This version also fixed the #17, btw.
great!
I also just pushed a bunch of new changes, including a lspconfig integration to fix its workspace management. There's also an API call for people that don't use lspconfig to properly deal with existing workspaces.
Did you check docs and existing issues?
Neovim version (nvim -v)
v0.10.0
Operating system/version
Linux EndeavourOS rolling x86_64
Describe the bug
There is a duplication of definitions, and seeing require(“lazydev.workspace”).global(), it is inserted inside Lua.workspace.library, the same path as the root of the lsp. One of the cases could be because I manage some folders inside my neovim configuration as a separate plugin with lazy.nvim, and that makes it take its own path again.
For the moment I solved it by patching the add function inside lazydev.workspace, so that it checks if the path does not start with the same path as the lsp client root.
Steps To Reproduce
--
Expected Behavior
Add within library only paths not contained within the lsp client's root_path