From 9c9e1d32f7dde654c87e2c4b291ca274597b99a5 Mon Sep 17 00:00:00 2001
From: Andreas Louv <andreas@louv.dk>
Date: Sat, 8 Apr 2023 00:11:29 +0200
Subject: [PATCH] Use the CWD as the "rootUri" and initial "workspaceFolder"

---
 autoload/lsp/lspserver.vim | 4 ++--
 doc/lsp.txt                | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim
index 89822e4..2d71cd9 100644
--- a/autoload/lsp/lspserver.vim
+++ b/autoload/lsp/lspserver.vim
@@ -153,14 +153,14 @@ def InitServer(lspserver: dict<any>, bnr: number)
       }
 
   # Compute the rootpath (based on the directory of the buffer)
-  var bufDir = bnr->bufname()->fnamemodify(':p:h')
   var rootPath = ''
   var rootSearchFiles = lspserver.rootSearchFiles
   if !rootSearchFiles->empty()
+    var bufDir = bnr->bufname()->fnamemodify(':p:h')
     rootPath = util.FindNearestRootDir(bufDir, rootSearchFiles)
   endif
   if rootPath == ''
-    rootPath = bufDir
+    rootPath = getcwd()
   endif
 
   lspserver.workspaceFolders = [rootPath]
diff --git a/doc/lsp.txt b/doc/lsp.txt
index 8f40636..6ea8a03 100644
--- a/doc/lsp.txt
+++ b/doc/lsp.txt
@@ -271,8 +271,7 @@ To add a language server, the following information is needed:
 			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
-			directory of the current buffer is used as the
-			workspace root.
+			current working directory is used as the workspace root.
 
 Aditionally the following configurations can be made:
 
-- 
2.51.0