Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce "shebangs" config flag #2708

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,6 +159,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 +315,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