nvim-lspconfig
                                
                                 nvim-lspconfig copied to clipboard
                                
                                    nvim-lspconfig copied to clipboard
                            
                            
                            
                        possibly unintuitive lua_ls root_dir detection logic
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.
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.
Indeed, that sounds like a very reasonable solution.
In this case it makes sense to take longest value of
util.root_pattern 'lua/'andutil.find_git_ancestorresults.
PR welcome!
In this case it makes sense to take longest value of
util.root_pattern 'lua/'andutil.find_git_ancestorresults.PR welcome!
@justinmk, in case you wanna take a look: I made a corresponding PR based on @powerman's suggestion, see #3322.