blob: 955703093ba284d42ead8dec7a33f6ffc5c19d16 (
plain)
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
|
{lib}: let
inherit (builtins) isString getAttr;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) listOf bool str submodule attrsOf anything either nullOr uniq;
inherit (lib.nvim.attrsets) mapListToAttrs;
inherit (lib.nvim.types) luaInline;
in {
# TODO: remove
/**
Convert a list of diagnostic provider entries to a DAG-compatible attribute set.
Accepts either plain strings (provider type names) or attrsets with `type`
and `package` fields, and produces named entries suitable for merging into
a null-ls/none-ls DAG.
# Type
```
diagnosticsToLua :: { lang :: String; config :: [String | { type :: String; package :: Derivation }]; diagnosticsProviders :: AttrSet } -> AttrSet
```
# Arguments
- `lang`: Language identifier used to prefix generated entry names.
- `config`: List of provider names (strings) or `{ type; package }` records.
- `diagnosticsProviders`: Attribute set mapping provider type names to `{ package; nullConfig }` records.
# Example
```nix
diagnosticsToLua { lang = "python"; config = [ "flake8" ]; diagnosticsProviders = { flake8 = { package = pkgs.python3Packages.flake8; nullConfig = pkg: "..."; }; }; }
=> { "python-diagnostics-flake8" = "..."; }
```
*/
diagnosticsToLua = {
lang,
config,
diagnosticsProviders,
}:
mapListToAttrs
(v: let
type =
if isString v
then v
else getAttr v.type;
package =
if isString v
then diagnosticsProviders.${type}.package
else v.package;
in {
name = "${lang}-diagnostics-${type}";
value = diagnosticsProviders.${type}.nullConfig package;
})
config;
/**
Build a boolean NixOS option that enables a language feature for all enabled languages.
# Type
```
mkEnable :: String -> Option
```
# Arguments
- `desc`: Short description of the feature being enabled (interpolated into the option description).
# Example
```nix
mkEnable "LSP support"
=> mkOption { default = false; type = bool; description = "Turn on LSP support for enabled languages by default"; }
```
*/
mkEnable = desc:
mkOption {
default = false;
type = bool;
description = "Turn on ${desc} for enabled languages by default";
};
/**
A freeform submodule type for LSP server options.
Provides a structured set of well-known LSP configuration fields
(`enable`, `capabilities`, `on_attach`, `filetypes`, `cmd`, `root_markers`)
while allowing arbitrary extra fields via `freeformType`.
# Type
```
lspOptions :: SubmoduleType
```
# Example
```nix
vim.languages.rust.lsp.options = {
enable = true;
root_markers = [ "Cargo.toml" ];
};
```
*/
lspOptions = submodule {
freeformType = attrsOf anything;
options = {
enable = mkEnableOption "this LSP server" // {default = true;};
capabilities = mkOption {
type = nullOr (either luaInline (attrsOf anything));
default = null;
description = "LSP capabilities to pass to LSP server configuration";
};
on_attach = mkOption {
type = nullOr luaInline;
default = null;
description = "Function to execute when an LSP server attaches to a buffer";
};
filetypes = mkOption {
type = nullOr (listOf str);
default = null;
description = "Filetypes to auto-attach LSP server in";
};
cmd = mkOption {
type = nullOr (either luaInline (uniq (listOf str)));
default = null;
description = "Command used to start the LSP server";
};
root_markers = mkOption {
type = nullOr (listOf str);
default = null;
description = ''
"root markers" used to determine the root directory of the workspace, and
the filetypes associated with this LSP server.
'';
};
};
};
}
|