Skip to content
New issue

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

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

Already on GitHub? # to your account

Texlab root_dir is prioritising $HOME if $HOME/.latexmkrc is present #2975

Closed
Eryx5502 opened this issue Jan 19, 2024 · 5 comments
Closed

Texlab root_dir is prioritising $HOME if $HOME/.latexmkrc is present #2975

Eryx5502 opened this issue Jan 19, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Eryx5502
Copy link

Description

As noted in PR #2831, $HOME/.latexmkrc is used for per-user config and should not be considered for fixing root_dir. However, even after #2831, I'm getting $HOME as root_dir with the following file structure:

/home/user/
├── .latexmkrc
└── work/
    └── project/
        ├── .git
        └── file.tex

As a workaround, it is possible set lua root_dir = require('lspconfig.util').root_pattern('.git') which will yield the correct root_dir inside git repos.

Neovim version

NVIM v0.10.0-dev Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Run "nvim -V1 -v" for more info

Nvim-lspconfig version

042aa6b

Operating system and version

Ubuntu 20.04 inside WSL2

Affected language servers

texlab

Steps to reproduce

  1. cd $HOME/work/project
  2. nvim -u minimal_init.lua file.tex
  3. :LspInfo will show root_dir = /home/user

Actual behavior

$HOME is chosen as the root_dir because of the existence of the .latexmkrc file.

Expected behavior

$HOME/work/project should be chosen as root_dir since it has a .git folder.

Minimal config

-- Used the minimal_init.lua, modified only at the end to add texlab LSP

local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
	local path_sep = on_windows and "\\" or "/"
	local result = table.concat({ ... }, path_sep)
	return result
end

vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local lspconfig_path = join_paths(package_root, "test", "start", "nvim-lspconfig")

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
	vim.fn.system({ "git", "clone", "https://github.com/neovim/nvim-lspconfig", lspconfig_path })
end

vim.lsp.set_log_level("trace")
require("vim.lsp.log").set_format_func(vim.inspect)
local nvim_lsp = require("lspconfig")
local on_attach = function(_, bufnr)
	local function buf_set_option(...)
		vim.api.nvim_buf_set_option(bufnr, ...)
	end

	buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")

	-- Mappings.
	local opts = { buffer = bufnr, noremap = true, silent = true }
	vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
	vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
	vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
	vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
	vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
	vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
	vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
	vim.keymap.set("n", "<space>wl", function()
		print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
	end, opts)
	vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
	vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
	vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
	vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
	vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
	vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
	vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = "texlab"
if not name then
	print("You have not defined a server name, please edit minimal_init.lua")
end
if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
	print([[You have not defined a server default cmd for a server
    that requires it please edit minimal_init.lua]])
end

nvim_lsp[name].setup({
	cmd = cmd,
	on_attach = on_attach,
})

print([[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]])

LSP log

Non appeared in $HOME/.cache/nvim/lsp.log

@Eryx5502 Eryx5502 added the bug Something isn't working label Jan 19, 2024
@Badhi
Copy link

Badhi commented Jan 19, 2024

This behavior of root_directory is causing a huge startup time in pyright when trying to find the root directory when file is in a deeper directory (even when the config related to that file is located in a closer ancenstor directory)

This is because the root_directory is giving priority to the file mentioned earliest in arglist in searching by going through all the ancestor directories before going to the next file in the arglist.

Instead, IMO doing a check on all the files given in the list for each directory before going to the ancestor is logical

@justinmk
Copy link
Member

@tomtomjhj thoughts?

@tomtomjhj
Copy link
Contributor

#2885 seems to have changed the behavior of root_pattern.

@justinmk
Copy link
Member

justinmk commented Jan 29, 2024

IMO doing a check on all the files given in the list for each directory before going to the ancestor is logical

Why? It sounds like the issue can be fixed by swapping the order.

The benefit of #2885 is that it at least makes the precedence rules very clear.

@tomtomjhj
Copy link
Contributor

The current solution will make root overly big in cases like this (project instead of docs):

project/
    .git
    src/
    docs/
        .latexmkrc
        *.tex

Personally, I prefer the older version of root_pattern because it is stronger in the sense that it can be used for implementing the new version of root_pattern with a chain of ors (like the "special-cased" solution from #2885)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants