nvim-lspconfig icon indicating copy to clipboard operation
nvim-lspconfig copied to clipboard

possibly unintuitive lua_ls root_dir detection logic

Open pitkling opened this issue 1 year ago • 2 comments

Description

I had some problems with the root dir detection of the lua_ls language server. I took a look at the corresponding code and was surprised that finding the git ancestor has lower priority than the lua/ subdirectories (which, btw, is not mentioned in the documentation).

My specific problem with this: Consider the following directory structure:

HOME/
├─ workspaces/
│  ├─ lua/
│  ├─ python/
│  ├─ work/
│  │  ├─ SomeProjectWithLuaFiles/
│  │  │  ├─ .git/

The lua/ and python/ directories contain some miscellaneous language-specific projects I sometimes work on. The project directory under Work also contains some lua files. I expected the .git directory in the project to ensure that the project root dir is correctly detected to be …/SomeProjectWithLuaFiles. But since the search for the lua/ subdirectory is done first, my LSP detects HOME/workspaces/ as the root directory.

I know I can easily change this, I was just wondering if this is intended? While I know that many lua projects have a lua/ subdirectory, I feel that such language-specific workspace directories are not that uncommon, and that the search for the git ancestor should be done before looking for the lua/ subdirectory.

Even if it is intended, I think this should be at least mentioned in the documentation for the default lua_ls configuration.

pitkling avatar May 20 '24 19:05 pitkling

If I get right the point is to limit lua workspace by lua/ subdir of a large repo. In this case it makes sense to take longest value of util.root_pattern 'lua/' and util.find_git_ancestor results.

powerman avatar Jul 03 '24 18:07 powerman

Indeed, that sounds like a very reasonable solution.

pitkling avatar Jul 04 '24 07:07 pitkling

In this case it makes sense to take longest value of util.root_pattern 'lua/' and util.find_git_ancestor results.

PR welcome!

justinmk avatar Sep 18 '24 21:09 justinmk

In this case it makes sense to take longest value of util.root_pattern 'lua/' and util.find_git_ancestor results.

PR welcome!

@justinmk, in case you wanna take a look: I made a corresponding PR based on @powerman's suggestion, see #3322.

pitkling avatar Sep 30 '24 12:09 pitkling