From 1110787f1b464888c59a044c48c5119d14078044 Mon Sep 17 00:00:00 2001 From: Afiq Nazrie Date: Sun, 15 Dec 2024 17:31:32 +0700 Subject: fix(lua_ls): return longest root path This commit doesn't address the case when root path == vim.env.HOME as the case lack return when it's true (#2110) Fix #3508 --- lua/lspconfig/configs/lua_ls.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/configs/lua_ls.lua b/lua/lspconfig/configs/lua_ls.lua index a545b34b..4253337d 100644 --- a/lua/lspconfig/configs/lua_ls.lua +++ b/lua/lspconfig/configs/lua_ls.lua @@ -15,16 +15,15 @@ return { cmd = { 'lua-language-server' }, filetypes = { 'lua' }, root_dir = function(fname) - local root = util.root_pattern(unpack(root_files))(fname) - if root and root ~= vim.env.HOME then - return root - end + local root_file = util.root_pattern(unpack(root_files))(fname) or '' local root_lua = util.root_pattern 'lua/'(fname) or '' local root_git = vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1]) or '' - if root_lua == '' and root_git == '' then + if root_file == '' and root_lua == '' and root_git == '' then return end - return #root_lua >= #root_git and root_lua or root_git + local root = #root_file >= #root_lua and root_file or root_lua + root = #root >= #root_git and root or root_git + return root end, single_file_support = true, log_level = vim.lsp.protocol.MessageType.Warning, -- cgit v1.2.3-70-g09d2