Skip to content

Commit

Permalink
feat: add shebangs to config
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd committed Jul 9, 2023
1 parent 0011c43 commit 5e69493
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5e69493

Please sign in to comment.