]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Use the parent directory for files not a descendent of the CWD
authorAndreas Louv <andreas@louv.dk>
Fri, 7 Apr 2023 22:11:29 +0000 (00:11 +0200)
committerAndreas Louv <andreas@louv.dk>
Mon, 10 Apr 2023 12:23:19 +0000 (14:23 +0200)
autoload/lsp/lspserver.vim
doc/lsp.txt

index 2d71cd9a0479c7d04ce7141dedd776b499f85e40..e652d015fe53dd40fe3de92869e667109ea99818 100644 (file)
@@ -155,12 +155,22 @@ def InitServer(lspserver: dict<any>, bnr: number)
   # Compute the rootpath (based on the directory of the buffer)
   var rootPath = ''
   var rootSearchFiles = lspserver.rootSearchFiles
+  var bufDir = bnr->bufname()->fnamemodify(':p:h')
   if !rootSearchFiles->empty()
-    var bufDir = bnr->bufname()->fnamemodify(':p:h')
     rootPath = util.FindNearestRootDir(bufDir, rootSearchFiles)
   endif
   if rootPath == ''
-    rootPath = getcwd()
+    var cwd = getcwd()
+
+    # bufDir is within cwd
+    var bufDirPrefix = bufDir[0 : cwd->strcharlen() - 1]
+    if &fileignorecase
+        ? bufDirPrefix ==? cwd
+        : bufDirPrefix ==# cwd
+      rootPath = cwd
+    else
+      rootPath = bufDir
+    endif
   endif
 
   lspserver.workspaceFolders = [rootPath]
index 6ea8a030e78675cd64120a333672c528ab63eb06..56e58022a6d80ce627e20b83912b81664d09207a 100644 (file)
@@ -270,8 +270,10 @@ To add a language server, the following information is needed:
                        multiple directories are found, then the directory
                        closest to the directory of the current buffer is used
                        as the workspace root.  If this parameter is not
-                       specified or the files are not found, then the
-                       current working directory is used as the workspace root.
+                       specified or the files are not found, then the current
+                       working directory is used as the workspace root for
+                       decendent files, for any other files the parent
+                       directory of the file is used.
 
 Aditionally the following configurations can be made: