-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from NotAShelf/bash-lsp
languages/bash: add LSP
- Loading branch information
Showing
7 changed files
with
214 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{ | ||
pkgs, | ||
config, | ||
lib, | ||
... | ||
}: | ||
with builtins; let | ||
inherit (lib) mkOption mkEnableOption types; | ||
|
||
cfg = config.vim.languages.bash; | ||
|
||
defaultServer = "bash-ls"; | ||
servers = { | ||
bash-ls = { | ||
package = pkgs.nodePackages.bash-language-server; | ||
lspConfig = '' | ||
lspconfig.bashls.setup{ | ||
capabilities = capabilities; | ||
on_attach = default_on_attach; | ||
cmd = ${ | ||
if isList cfg.lsp.package | ||
then nvim.lua.expToLua cfg.lsp.package | ||
else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}'' | ||
}; | ||
} | ||
''; | ||
}; | ||
}; | ||
|
||
defaultFormat = "shfmt"; | ||
formats = { | ||
shfmt = { | ||
package = pkgs.shfmt; | ||
nullConfig = '' | ||
table.insert( | ||
ls_sources, | ||
null_ls.builtins.formatting.shfmt.with({ | ||
command = "${pkgs.shfmt}/bin/shfmt", | ||
}) | ||
) | ||
''; | ||
}; | ||
}; | ||
|
||
defaultDiagnostics = ["shellcheck"]; | ||
diagnostics = { | ||
shellcheck = { | ||
package = pkgs.shellcheck; | ||
nullConfig = pkg: '' | ||
table.insert( | ||
ls_sources, | ||
null_ls.builtins.diagnostics.shellcheck.with({ | ||
command = "${pkg}/bin/shellcheck", | ||
}) | ||
) | ||
''; | ||
}; | ||
}; | ||
in { | ||
options.vim.languages.bash = { | ||
enable = mkEnableOption "Bash language support"; | ||
|
||
treesitter = { | ||
enable = mkEnableOption "Bash treesitter" // {default = config.vim.languages.enableTreesitter;}; | ||
package = lib.nvim.types.mkGrammarOption pkgs "bash"; | ||
}; | ||
|
||
lsp = { | ||
enable = mkEnableOption "Enable Bash LSP support" // {default = config.vim.languages.enableLSP;}; | ||
|
||
server = mkOption { | ||
description = "Bash LSP server to use"; | ||
type = with types; enum (attrNames servers); | ||
default = defaultServer; | ||
}; | ||
|
||
package = mkOption { | ||
description = "bash-language-server package, or the command to run as a list of strings"; | ||
example = lib.literalExpression ''[lib.getExe pkgs.nodePackages.bash-language-server "start"]''; | ||
type = with types; either package (listOf str); | ||
default = pkgs.nodePackages.bash-language-server; | ||
}; | ||
}; | ||
|
||
format = { | ||
enable = mkOption { | ||
description = "Enable Bash formatting"; | ||
type = types.bool; | ||
default = config.vim.languages.enableFormat; | ||
}; | ||
type = mkOption { | ||
description = "Bash formatter to use"; | ||
type = with types; enum (attrNames formats); | ||
default = defaultFormat; | ||
}; | ||
|
||
package = mkOption { | ||
description = "Bash formatter package"; | ||
type = types.package; | ||
default = formats.${cfg.format.type}.package; | ||
}; | ||
}; | ||
|
||
extraDiagnostics = { | ||
enable = mkEnableOption "extra Bash diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; | ||
|
||
types = lib.nvim.types.diagnostics { | ||
langDesc = "Bash"; | ||
inherit diagnostics; | ||
inherit defaultDiagnostics; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
pkgs, | ||
config, | ||
lib, | ||
... | ||
}: | ||
with lib; | ||
with builtins; let | ||
cfg = config.vim.languages.bash; | ||
diagnostics = { | ||
shellcheck = { | ||
package = pkgs.shellcheck; | ||
nullConfig = pkg: '' | ||
table.insert( | ||
ls_sources, | ||
null_ls.builtins.diagnostics.shellcheck.with({ | ||
command = "${pkg}/bin/shellcheck", | ||
}) | ||
) | ||
''; | ||
}; | ||
}; | ||
|
||
formats = { | ||
shfmt = { | ||
package = pkgs.shfmt; | ||
nullConfig = '' | ||
table.insert( | ||
ls_sources, | ||
null_ls.builtins.formatting.shfmt.with({ | ||
command = "${pkgs.shfmt}/bin/shfmt", | ||
}) | ||
) | ||
''; | ||
}; | ||
}; | ||
|
||
servers = { | ||
bash-ls = { | ||
package = pkgs.nodePackages.bash-language-server; | ||
lspConfig = '' | ||
lspconfig.bashls.setup{ | ||
capabilities = capabilities; | ||
on_attach = default_on_attach; | ||
cmd = ${ | ||
if isList cfg.lsp.package | ||
then nvim.lua.expToLua cfg.lsp.package | ||
else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}'' | ||
}; | ||
} | ||
''; | ||
}; | ||
}; | ||
in { | ||
config = mkIf cfg.enable (mkMerge [ | ||
(mkIf cfg.treesitter.enable { | ||
vim.treesitter.enable = true; | ||
vim.treesitter.grammars = [cfg.treesitter.package]; | ||
}) | ||
|
||
(mkIf cfg.lsp.enable { | ||
vim.lsp.lspconfig.enable = true; | ||
vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig; | ||
}) | ||
|
||
(mkIf cfg.format.enable { | ||
vim.lsp.null-ls.enable = true; | ||
vim.lsp.null-ls.sources.bash-format = formats.${cfg.format.type}.nullConfig; | ||
}) | ||
|
||
(mkIf cfg.extraDiagnostics.enable { | ||
vim.lsp.null-ls.enable = true; | ||
vim.lsp.null-ls.sources = lib.nvim.languages.diagnosticsToLua { | ||
lang = "bash"; | ||
config = cfg.extraDiagnostics.types; | ||
inherit diagnostics; | ||
}; | ||
}) | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
_: { | ||
imports = [ | ||
./bash.nix | ||
./config.nix | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters