-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
9765686
to
b6c706b
Compare
This can easily be solved by adding a filetype detection instead and not adding a bespoke filetype detection implementation to nvim-lspconfig: vim.filetype.add {
pattern = {
[".*"] = {
priority = -math.huge,
function(path, bufnr)
local content = vim.filetype.getlines(bufnr, 1)
if vim.filetype.matchregex(content, [[^#!/usr/bin/env deno]]) then
return "javascript"
end
end,
},
},
} |
The problem is I need to hook to the internals of lspconfig in order to start the lsp server in single file mode in case of a match, or do you have an example on how to do it externally? Also I'm not really sure of the point of the file detection because I still use the ts and js extension (so file type is detected already) as that's what this PR assumes |
Ah if the language server supports single file support the flag could be enabled for it. This could either be done manually or be part of the default server config: lspconfig.denols.setup {
single_file_support = true,
} |
But the point is to enable it only when the shebang exists |
Hey, following up on this - like @sigmaSd mentioned, the usecase mentioned here about disambiguating when to use For example:
Assuming this was implemented flexibly, you could imagine something like a "buffer rule" that determines whether or not the lsp should be attached after the rest of the existing filetype/root file rules already apply. This would also enable additional better custom heuristics like:
I'm not sure what the best way to implement this would be that's flexible enough |
Instead of this, would it make sense for Expecting users to fiddle with another flag for scenarios that can't really be properly detected in the first place, is the wrong approach. |
This is useful for running one off scripts with the lsp
see sigmaSd/deno-nvim#2 for prior discussion
Also for precedence helix also has this feature
example of usage
a.ts
#!/usr/bin/env deno Deno
now the script a.ts will automatically trigger deno lsp