-
-
Notifications
You must be signed in to change notification settings - Fork 360
modules/lsp: init #3203
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
modules/lsp: init #3203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| ./highlights.nix | ||
| ./keymaps.nix | ||
| ./lazyload.nix | ||
| ./lsp.nix | ||
| ./lua-loader.nix | ||
| ./opts.nix | ||
| ./output.nix | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| { | ||
| lib, | ||
| config, | ||
| ... | ||
| }: | ||
| let | ||
| inherit (lib) mkOption types; | ||
| inherit (lib.nixvim) toLuaObject; | ||
|
|
||
| cfg = config.lsp; | ||
|
|
||
| serverType = types.submodule { | ||
| options = { | ||
| enable = lib.mkEnableOption "the language server"; | ||
|
|
||
| activate = lib.mkOption { | ||
| type = types.bool; | ||
| description = '' | ||
| Whether to call `vim.lsp.enable()` for this server. | ||
| ''; | ||
| default = true; | ||
| example = false; | ||
| }; | ||
|
|
||
| package = lib.mkOption { | ||
| type = with types; nullOr package; | ||
| default = null; | ||
| description = '' | ||
| Package to use for this language server. | ||
|
|
||
| Alternatively, the language server should be available on your `$PATH`. | ||
| ''; | ||
| }; | ||
|
|
||
| config = mkOption { | ||
| type = with types; attrsOf anything; | ||
| description = '' | ||
| Configurations for each language server. | ||
| ''; | ||
| default = { }; | ||
| example = { | ||
| cmd = [ | ||
| "clangd" | ||
| "--background-index" | ||
| ]; | ||
| root_markers = [ | ||
| "compile_commands.json" | ||
| "compile_flags.txt" | ||
| ]; | ||
| filetypes = [ | ||
| "c" | ||
| "cpp" | ||
| ]; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| in | ||
| { | ||
| options.lsp = { | ||
| luaConfig = lib.mkOption { | ||
| type = lib.types.pluginLuaConfig; | ||
| default = { }; | ||
| description = '' | ||
| Lua code configuring LSP. | ||
| ''; | ||
| }; | ||
|
|
||
| inlayHints = { | ||
| enable = lib.mkEnableOption "inlay hints globally"; | ||
| }; | ||
|
|
||
| servers = mkOption { | ||
| type = types.attrsOf serverType; | ||
| description = '' | ||
| LSP servers to enable and/or configure. | ||
|
|
||
| This option is implemented using neovim's `vim.lsp` lua API. | ||
| If you prefer to use [nvim-lspconfig], see [`plugins.lsp`]. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point, we should tweak this wording to suggest users use both
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be updated in #3234 to reference |
||
|
|
||
| [nvim-lspconfig]: https://github.com/neovim/nvim-lspconfig | ||
| [`plugins.lsp`]: https://nix-community.github.io/nixvim/plugins/lsp/index.html | ||
| ''; | ||
| default = { }; | ||
| example = { | ||
| "*".config = { | ||
| root_markers = [ ".git" ]; | ||
| capabilities.textDocument.semanticTokens = { | ||
| multilineTokenSupport = true; | ||
| }; | ||
| }; | ||
| luals.enable = true; | ||
| clangd = { | ||
| enable = true; | ||
| config = { | ||
| cmd = [ | ||
| "clangd" | ||
| "--background-index" | ||
| ]; | ||
| root_markers = [ | ||
| "compile_commands.json" | ||
| "compile_flags.txt" | ||
| ]; | ||
| filetypes = [ | ||
| "c" | ||
| "cpp" | ||
| ]; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| config = | ||
| let | ||
| enabledServers = lib.filterAttrs (_: v: v.enable) cfg.servers; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we introduce a submodule (
{ name, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.str;
description = "The name of the language server, used as the first argument to `vim.lsp.enable` and `vim.lsp.config`.";
default = name;
};
# ...
};
}
)This would also allow users to configure the same server in different ways, using different attr-names, and decide which to use via the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look at this in a followup PR EDIT: #3239 |
||
| in | ||
| { | ||
| extraPackages = lib.pipe enabledServers [ | ||
| builtins.attrValues | ||
| (builtins.catAttrs "package") | ||
| ]; | ||
|
|
||
| lsp.luaConfig.content = | ||
| let | ||
| mkServerConfig = | ||
| name: props: | ||
| let | ||
| luaName = toLuaObject name; | ||
| in | ||
| '' | ||
| vim.lsp.config(${luaName}, ${toLuaObject props.config}) | ||
| '' | ||
| + lib.optionalString props.activate '' | ||
| vim.lsp.enable(${luaName}) | ||
| ''; | ||
| in | ||
| lib.mkMerge ( | ||
| lib.optional cfg.inlayHints.enable "vim.lsp.inlay_hint.enable(true)" | ||
| ++ lib.mapAttrsToList mkServerConfig enabledServers | ||
| ); | ||
|
|
||
| extraConfigLua = lib.mkIf (cfg.luaConfig.content != "") '' | ||
| -- LSP {{{ | ||
| do | ||
| ${cfg.luaConfig.content} | ||
| end | ||
| -- }}} | ||
| ''; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| example = { | ||
| lsp.servers = { | ||
| "*".config = { | ||
| root_markers = [ ".git" ]; | ||
| capabilities.textDocument.semanticTokens = { | ||
| multilineTokenSupport = true; | ||
| }; | ||
| }; | ||
| luals.enable = true; | ||
| clangd = { | ||
| enable = true; | ||
| config = { | ||
| cmd = [ | ||
| "clangd" | ||
| "--background-index" | ||
| ]; | ||
| root_markers = [ | ||
| "compile_commands.json" | ||
| "compile_flags.txt" | ||
| ]; | ||
| filetypes = [ | ||
| "c" | ||
| "cpp" | ||
| ]; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.