From ac531c87bb2a39f7b797a1872efa744cfd59abd5 Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Sat, 8 Apr 2023 00:11:29 +0200 Subject: [PATCH] Use the parent directory for files not a descendent of the CWD --- autoload/lsp/lspserver.vim | 14 ++++++++++++-- doc/lsp.txt | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) 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: -- 2.48.1