-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
Copy path_mk-lsp.nix
157 lines (143 loc) · 4.28 KB
/
_mk-lsp.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#########
# mkLsp #
#########
#
# Helper function that returns the Nix module `plugins.lsp.servers.<name>`.
#
{ pkgs, ... }:
{
name,
description ? "Enable ${name}.",
serverName ? name,
package ? pkgs.${name},
url ? package.meta.homepage or null,
cmd ? (cfg: null),
settings ? (cfg: cfg),
settingsOptions ? { },
extraConfig ? cfg: { },
extraOptions ? { },
...
}:
# returns a module
{
pkgs,
config,
helpers,
lib,
...
}:
with lib;
let
cfg = config.plugins.lsp.servers.${name};
in
{
meta.nixvimInfo = {
# TODO: description
inherit url;
path = [
"plugins"
"lsp"
"servers"
name
];
};
options = {
plugins.lsp.servers.${name} = {
enable = mkEnableOption description;
package = mkOption {
default = package;
type = types.nullOr types.package;
description = "Which package to use for ${name}.";
};
cmd = mkOption {
type = with types; nullOr (listOf str);
default = if (cfg.package or null) != null then cmd cfg else null;
description = ''
A list where each entry corresponds to the blankspace delimited part of the command that
launches the server.
The first entry is the binary used to run the language server.
Additional entries are passed as arguments.
'';
};
filetypes = helpers.mkNullOrOption (types.listOf types.str) ''
Set of filetypes for which to attempt to resolve {root_dir}.
May be empty, or server may specify a default value.
'';
autostart = helpers.defaultNullOpts.mkBool true ''
Controls if the `FileType` autocommand that launches a language server is created.
If `false`, allows for deferring language servers until manually launched with
`:LspStart` (|lspconfig-commands|).
'';
rootDir = helpers.defaultNullOpts.mkLuaFn "nil" ''
A function (or function handle) which returns the root of the project used to
determine if lspconfig should launch a new language server, or attach a previously
launched server when you open a new buffer matching the filetype of the server.
'';
onAttach = helpers.mkCompositeOption "Server specific on_attach behavior." {
override = mkOption {
type = types.bool;
default = false;
description = "Override the global `plugins.lsp.onAttach` function.";
};
function = mkOption {
type = types.lines;
description = ''
Body of the on_attach function.
The argument `client` and `bufnr` is provided.
'';
};
};
settings = helpers.mkSettingsOption {
description = "The settings for this LSP.";
options = settingsOptions;
};
extraOptions = mkOption {
default = { };
type = types.attrsOf types.anything;
description = "Extra options for the ${name} language server.";
};
} // extraOptions;
};
config = mkIf cfg.enable {
extraPackages = [ cfg.package ];
plugins.lsp.enabledServers = [
{
name = serverName;
extraOptions = {
inherit (cfg) cmd filetypes autostart;
root_dir = cfg.rootDir;
on_attach = helpers.ifNonNull' cfg.onAttach (
helpers.mkRaw ''
function(client, bufnr)
${optionalString (!cfg.onAttach.override) config.plugins.lsp.onAttach}
${cfg.onAttach.function}
end
''
);
settings = settings cfg.settings;
} // cfg.extraOptions;
}
];
};
imports =
let
basePath = [
"plugins"
"lsp"
"servers"
];
basePluginPath = basePath ++ [ name ];
basePluginPathString = concatStringsSep "." basePluginPath;
in
[
(mkRemovedOptionModule (
basePluginPath ++ [ "extraSettings" ]
) "You can use `${basePluginPathString}.extraOptions.settings` instead.")
(extraConfig cfg)
]
# Add an alias (with warning) for the lspconfig server name, if different to `name`.
# Note: users may use lspconfig's docs to guess the `plugins.lsp.servers.*` name
++ (optional (name != serverName) (
mkRenamedOptionModule (basePath ++ [ serverName ]) basePluginPath
));
}