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

Diagnostic warn about duplicates from symlinked workspace

Open strash opened this issue 2 years ago • 5 comments

How are you using the lua-language-server?

NeoVim

Which OS are you using?

MacOS

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

I expected ignoring symlinks.

Actual Behaviour

I have a plugin I'm developing on my machine and I'm using Packer (plugin manager) to install the plugin in a plugins directory. Local plugins are just symlinked. This causes the diagnostics to warn about duplicates in every single annotation.

If I remove the symlink diagnostic stop spamming warnings.

Screenshot 2023-03-12 at 14 55 48 Screenshot 2023-03-12 at 14 57 27

Reproduction steps

  1. Install latest stable neovim
  2. Install Packer or, I think, any other plugin manager
  3. Install local plugin via plugin manager use("~/path_to_plugin")
  4. Open any file which contains annotations
  5. See warnings

Additional Notes

No response

Log File

No response

strash avatar Mar 12 '23 12:03 strash

This is my settings for the server.

local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")

nvim_lsp.lua_ls.setup({
	on_attach = map.set_lsp_map,
	capabilities = capabilities,
	flags = flags,
	settings = {
		Lua = {
			completion = {
				callSnippet = "Both",
			},
			diagnostics = {
				globals = { "vim" },
			},
			runtime = {
				version = "LuaJIT",
				path = runtime_path,
			},
			telemetry = {
				enable = false,
			},
			window = {
				progressBar = false,
				statusBar = false,
			},
			workspace = {
				-- if I remove this line, then the problem is solved
				-- but then I can't get neovim api to work
				library = vim.api.nvim_get_runtime_file("", true),
				checkThirdParty = false,
			},
		},
	},
})

strash avatar Mar 12 '23 12:03 strash

I did some hacking and removed the symlink from the runtime path. It works but it is still a hack.

local runtime_path = vim.split(package.path, ";")
local runtime_file = vim.api.nvim_get_runtime_file("", true)
-- HACK start
local idxs = {}
for i, v in ipairs(runtime_file) do
	if v:find("everybody-wants-that-line.nvim", 0, true) or v:match(".local/share/nvim/site$") then
		table.insert(idxs, i)
	end
end
for i = #idxs, 1, -1 do
	table.remove(runtime_file, idxs[i])
end
-- HACK end
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")

nvim_lsp.lua_ls.setup({
	on_attach = map.set_lsp_map,
	capabilities = capabilities,
	flags = flags,
	settings = {
		Lua = {
			...
			workspace = {
				library = runtime_file,
				checkThirdParty = false,
			},
		},
	},
})

strash avatar Mar 12 '23 13:03 strash

I think this is the function of the symbol link

sumneko avatar Mar 13 '23 06:03 sumneko

Simple case: I want to distribute a directory vector with a file vector.lua inside of it in order to follow the convention (look at middleclass.lua, fun.lua, argparse.lua and other popular Lua libraries).

However I also want to allow for people with the default package.path of ?.lua;?/init.lua to import the entire vector directory, without having to extract the vector.lua itself. To do this, I simply made a relative symlink init.lua pointing to vector.lua.
This is why the duplicate annotations problem is annoying.

It would be nice if the annotations automatically ignored a file that has already been read.

adamnejm avatar May 31 '23 11:05 adamnejm

I have encountered this same issue in my library lua-stream. My file structure looks like this:

> tree
.
├── doc
│   └── examples.lua
├── LICENSE
├── lua
│   └── stream
│       └── init.lua
├── README.md
├── stream -> lua/stream/
├── stylua.toml
└── test
    └── init.lua

having /stream be a symlink to /lua/stream/ allows the default package.path to import it as require "stream", while also /lua/stream/ allows NeoVim plugins to import it as well.

aarondill avatar Feb 23 '24 13:02 aarondill