From 5e69493522978b24f1384d7018557f9548b0a823 Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Sun, 9 Jul 2023 11:37:40 +0100 Subject: [PATCH 1/2] feat: add shebangs to config --- lua/lspconfig/configs.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index e74570f11e..adff465719 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -158,6 +158,21 @@ function configs.__newindex(t, config_name, config_def) end end end + elseif config.shebangs and #config.shebangs ~= 0 then + if not api.nvim_buf_is_valid(bufnr) or (#bufname ~= 0 and not util.bufname_valid(bufname)) then + return + end + local maybeshebang = api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] + if not maybeshebang:match '^#!' then + return + end + for _, shebang in ipairs(config.shebangs) do + if maybeshebang:find(shebang) then + local pseudo_root = #bufname == 0 and pwd or util.path.dirname(util.path.sanitize(bufname)) + M.manager.add(pseudo_root, true, bufnr) + break + end + end elseif config.single_file_support then -- This allows on_new_config to use the parent directory of the file -- Effectively this is the root from lspconfig's perspective, as we use @@ -299,6 +314,18 @@ function configs.__newindex(t, config_name, config_def) if root_dir then manager.add(root_dir, false, bufnr) + elseif config.shebangs and #config.shebangs ~= 0 then + local maybeshebang = api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] + if not maybeshebang:match '^#!' then + return + end + for _, shebang in ipairs(config.shebangs) do + if maybeshebang:find(shebang) then + local pseudo_root = #bufname == 0 and pwd or util.path.dirname(buf_path) + manager.add(pseudo_root, true, bufnr) + break + end + end elseif config.single_file_support then local pseudo_root = #bufname == 0 and pwd or util.path.dirname(buf_path) manager.add(pseudo_root, true, bufnr) From 27b1697b9456f2d82644e648be73f3d0391b00ea Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Sun, 9 Jul 2023 18:43:51 +0100 Subject: [PATCH 2/2] feat: validate shebangs --- lua/lspconfig/configs.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index adff465719..2ed8308b9b 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -74,6 +74,7 @@ function configs.__newindex(t, config_name, config_def) on_new_config = { user_config.on_new_config, 'f', true }, on_attach = { user_config.on_attach, 'f', true }, commands = { user_config.commands, 't', true }, + shebangs = { user_config.shebangs, 't', true }, } if user_config.commands then for k, v in pairs(user_config.commands) do