From aca77b317d3e65b3182fdc721f33767f3f8b0b66 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@bil.ke>
Date: Sat, 9 Mar 2024 04:17:43 +0100
Subject: [PATCH] fixes

---
 .config/nvim/lua/config/lsp.lua                  |  1 +
 .config/nvim/lua/funcs.lua                       | 12 +++++-------
 .config/nvim/lua/plugins/lsp/mason-lspconfig.lua |  2 ++
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/.config/nvim/lua/config/lsp.lua b/.config/nvim/lua/config/lsp.lua
index ae3fe776..c0b89e41 100644
--- a/.config/nvim/lua/config/lsp.lua
+++ b/.config/nvim/lua/config/lsp.lua
@@ -1,5 +1,6 @@
 local conf = { handlers = {} }
 
+-- https://github.com/bmewburn/intelephense-docs/blob/master/installation.md#configuration-options
 conf.handlers["intelephense"] = {
 	init_options = {
 		storagePath = os.getenv("XDG_CACHE_HOME") .. "/intelephense",
diff --git a/.config/nvim/lua/funcs.lua b/.config/nvim/lua/funcs.lua
index a0e62796..255c011c 100644
--- a/.config/nvim/lua/funcs.lua
+++ b/.config/nvim/lua/funcs.lua
@@ -565,16 +565,14 @@ function M.has_value(table, value)
 end
 
 function M.get_gwd(path)
-	local find = { ".git" }
-	local opts = { stop = os.getenv("HOME"), upward = true, limit = 1, path = path }
-    local found = vim.fs.find(find, opts)
-	if found ~= nil then
-		return vim.fs.dirname(found[1])
-	end
+    return require("lspconfig.util").find_git_ancestor(path or vim.fn.getcwd())
 end
 
 function M.set_cwd()
-    vim.fn.chdir(M.get_gwd())
+    local dir = M.get_gwd()
+    if dir ~= nil then
+        vim.fn.chdir(dir)
+    end
 end
 
 return M
diff --git a/.config/nvim/lua/plugins/lsp/mason-lspconfig.lua b/.config/nvim/lua/plugins/lsp/mason-lspconfig.lua
index f40e6d34..91e5569c 100644
--- a/.config/nvim/lua/plugins/lsp/mason-lspconfig.lua
+++ b/.config/nvim/lua/plugins/lsp/mason-lspconfig.lua
@@ -23,6 +23,8 @@ end
 
 M.dependencies = { "mason.nvim", "neoconf.nvim", "neodev.nvim" }
 
+M.event = { "BufReadPost", "BufNewFile", "BufNew" }
+
 M.cmd = { "LspInstall", "LspUninstall" }
 
 M.config = function()