summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2021-01-03 18:58:44 +0000
committerbrian m. carlson <sandals@crustytoothpaste.net>2021-01-03 18:58:44 +0000
commite7d5d6c7fab6b8f62e9c63d21d11193f9fc294bd (patch)
treede84ec0bb9f0dfdf0167fe9c99935e04a7717e1e
parentd9ecc0fcd56b45af92cfc647eb2255a2c8353a0a (diff)
vimrc: add a check for lsproot
Normally we set the project root for LSPs to the top of the Git repository. However, sometimes there are multiple projects in a repository and we need some way to indicate that the LSP should use a subdirectory as the directory. Let's look for a file that's called ".lsproot" that indicates this. This file can be ignored in .git/info/exclude. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
-rw-r--r--vim/vimrc18
1 files changed, 11 insertions, 7 deletions
diff --git a/vim/vimrc b/vim/vimrc
index 3e36918..2b6643b 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -531,21 +531,25 @@ function! s:ToggleScreenSize()
endif
endfunction
+function! s:SortLSPRoots(a, b)
+ " Sort the longest items first, since these will be more specific.
+ let x = len(a:b) - len(a:a)
+ return x / abs(x)
+endfunction
+
function! s:FindLSPRoot()
let buffer = bufnr("%")
" If we're in a submodule, .git will often, but not always, be a file, not a
" directory. Check both and pick the more deeply nested one.
+ let lsp_root_file = fnamemodify(ale#path#FindNearestFile(buffer, '.lsproot'), ':h')
let git_file = fnamemodify(ale#path#FindNearestFile(buffer, '.git'), ':h')
let git_dir = fnamemodify(ale#path#FindNearestDirectory(buffer, '.git'), ':h:h')
- if empty(git_file)
- return git_dir
- elseif empty(git_dir)
- return git_file
- endif
-
- return len(git_file) > len(git_dir) ? git_file : git_dir
+ let items = [lsp_root_file, git_file, git_dir]
+ let items = filter(items, 'len(v:val) > 0')
+ let items = sort(items, "s:SortLSPRoots")
+ return items[0]
endfunction
function! s:SetLSPRoot()