From: Andreas Louv Date: Fri, 7 Apr 2023 22:11:29 +0000 (+0200) Subject: Use the parent directory for files not a descendent of the CWD X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ac531c87bb2a39f7b797a1872efa744cfd59abd5;p=vim-lsp.git Use the parent directory for files not a descendent of the CWD --- diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 2d71cd9..e652d01 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -155,12 +155,22 @@ def InitServer(lspserver: dict, 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] diff --git a/doc/lsp.txt b/doc/lsp.txt index 6ea8a03..56e5802 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -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: