mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-22 08:53:28 +02:00
plugins/lsp/rust-analyzer: Use the newly generated options
This commit is contained in:
parent
a4cf6c6ffe
commit
954876bef7
4 changed files with 49 additions and 148 deletions
|
@ -123,7 +123,7 @@ in
|
||||||
standalone file support
|
standalone file support
|
||||||
setting it to false may improve startup time
|
setting it to false may improve startup time
|
||||||
'';
|
'';
|
||||||
}; # // (import ../../lsp/language-servers/rust-analyzer-config.nix lib pkgs);
|
} // (import ../../lsp/language-servers/rust-analyzer-config.nix lib helpers);
|
||||||
};
|
};
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
extraPlugins = with pkgs.vimPlugins; [
|
extraPlugins = with pkgs.vimPlugins; [
|
||||||
|
|
|
@ -257,8 +257,7 @@ with lib;
|
||||||
settings =
|
settings =
|
||||||
helpers.mkNullOrStrLuaFnOr
|
helpers.mkNullOrStrLuaFnOr
|
||||||
(types.submodule {
|
(types.submodule {
|
||||||
# options = import ../../../lsp/language-servers/rust-analyzer-config.nix lib pkgs;
|
options = import ../../../lsp/language-servers/rust-analyzer-config.nix lib helpers;
|
||||||
options = { };
|
|
||||||
freeformType = with types; attrsOf anything;
|
freeformType = with types; attrsOf anything;
|
||||||
})
|
})
|
||||||
''
|
''
|
||||||
|
|
|
@ -488,7 +488,7 @@ let
|
||||||
description = "rust-analyzer for Rust";
|
description = "rust-analyzer for Rust";
|
||||||
serverName = "rust_analyzer";
|
serverName = "rust_analyzer";
|
||||||
|
|
||||||
# settingsOptions = import ./rust-analyzer-config.nix lib pkgs;
|
settingsOptions = import ./rust-analyzer-config.nix lib helpers;
|
||||||
settings = cfg: { rust-analyzer = cfg; };
|
settings = cfg: { rust-analyzer = cfg; };
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,167 +1,69 @@
|
||||||
lib: pkgs:
|
# TODO: make all the types support raw lua
|
||||||
# Future improvements:
|
lib: helpers:
|
||||||
# - extra documentation from anyOf types, they can have `enumDescriptions` that are valuable
|
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
packageJson = "${pkgs.rust-analyzer.src}/editors/code/package.json";
|
rustAnalyzerOptions = import ../../../generated/rust-analyzer.nix;
|
||||||
|
|
||||||
options = (trivial.importJSON packageJson).contributes.configuration.properties;
|
|
||||||
|
|
||||||
packageJsonTxt = strings.splitString "\n" (builtins.readFile packageJson);
|
|
||||||
vscodeStart = lists.findFirstIndex (
|
|
||||||
x: x == " \"configuration\": {"
|
|
||||||
) (throw "no configuration") packageJsonTxt;
|
|
||||||
vscodeEnd =
|
|
||||||
lists.findFirstIndex (strings.hasInfix "generated-start") (throw "no generated start")
|
|
||||||
packageJsonTxt;
|
|
||||||
vscodeOptions = lists.sublist vscodeStart (vscodeEnd - vscodeStart) packageJsonTxt;
|
|
||||||
|
|
||||||
vscodeOptionNames = builtins.map (
|
|
||||||
x: strings.removeSuffix "\": {" (strings.removePrefix " \"" x)
|
|
||||||
) (lists.filter (strings.hasPrefix " \"rust-analyzer.") vscodeOptions);
|
|
||||||
|
|
||||||
rustAnalyzerOptions = builtins.removeAttrs options (
|
|
||||||
vscodeOptionNames
|
|
||||||
++ [
|
|
||||||
"\$generated-start"
|
|
||||||
"\$generated-end"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
nullType = mkOptionType {
|
|
||||||
name = "nullType";
|
|
||||||
description = "null";
|
|
||||||
descriptionClass = "noun";
|
|
||||||
merge = mergeEqualOption;
|
|
||||||
check = e: e == null;
|
|
||||||
};
|
|
||||||
|
|
||||||
mkRustAnalyzerType =
|
mkRustAnalyzerType =
|
||||||
opt:
|
{ kind, ... }@typeInfo:
|
||||||
{
|
if kind == "enum" then
|
||||||
type,
|
lib.types.enum typeInfo.values
|
||||||
enum ? null,
|
else if kind == "oneOf" then
|
||||||
minimum ? null,
|
lib.types.oneOf (lib.map mkRustAnalyzerType typeInfo.subTypes)
|
||||||
maximum ? null,
|
else if kind == "list" then
|
||||||
items ? null,
|
lib.types.listOf (mkRustAnalyzerType typeInfo.item)
|
||||||
anyOf ? null,
|
else if kind == "number" then
|
||||||
uniqueItems ? null,
|
let
|
||||||
# unused, but for exhaustivness
|
inherit (typeInfo) minimum maximum;
|
||||||
enumDescriptions ? null,
|
in
|
||||||
}@def:
|
|
||||||
if enum != null then
|
|
||||||
types.enum enum
|
|
||||||
else if anyOf != null then
|
|
||||||
types.oneOf (builtins.map (mkRustAnalyzerType opt) anyOf)
|
|
||||||
else if builtins.isList type then
|
|
||||||
if builtins.length type == 2 && builtins.head type == "null" then
|
|
||||||
types.nullOr (mkRustAnalyzerType opt (def // { type = builtins.elemAt type 1; }))
|
|
||||||
else
|
|
||||||
types.oneOf (builtins.map (t: mkRustAnalyzerType opt (def // { type = t; })) type)
|
|
||||||
else if type == "boolean" then
|
|
||||||
types.bool
|
|
||||||
else if type == "object" then
|
|
||||||
types.attrsOf types.anything
|
|
||||||
else if type == "string" then
|
|
||||||
types.str
|
|
||||||
else if type == "null" then
|
|
||||||
nullType
|
|
||||||
else if type == "array" then
|
|
||||||
types.listOf (
|
|
||||||
mkRustAnalyzerType "${opt}-items" (
|
|
||||||
if items == null then throw "null items with array type (in ${opt})" else items
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else if type == "number" then
|
|
||||||
if minimum != null && maximum != null then
|
if minimum != null && maximum != null then
|
||||||
types.numbers.between minimum maximum
|
lib.types.numbers.between minimum maximum
|
||||||
else if minimum != null then
|
else if minimum != null then
|
||||||
types.addCheck types.number (x: x >= minimum)
|
lib.types.addCheck lib.types.number (x: x >= minimum)
|
||||||
else if maximum != null then
|
else if maximum != null then
|
||||||
types.addCheck types.number (x: x <= maximum)
|
lib.types.addCheck lib.types.number (x: x <= maximum)
|
||||||
else
|
else
|
||||||
types.number
|
lib.types.number
|
||||||
else if type == "integer" then
|
else if kind == "integer" then
|
||||||
|
let
|
||||||
|
inherit (typeInfo) minimum maximum;
|
||||||
|
in
|
||||||
if minimum != null && maximum != null then
|
if minimum != null && maximum != null then
|
||||||
types.ints.between minimum maximum
|
lib.types.ints.between minimum maximum
|
||||||
else if minimum != null then
|
else if minimum != null then
|
||||||
types.addCheck types.int (x: x >= minimum)
|
lib.types.addCheck lib.types.int (x: x >= minimum)
|
||||||
else if maximum != null then
|
else if maximum != null then
|
||||||
types.addCheck types.int (x: x <= maximum)
|
lib.types.addCheck lib.types.int (x: x <= maximum)
|
||||||
else
|
else
|
||||||
types.int
|
lib.types.int
|
||||||
|
else if kind == "object" then
|
||||||
|
lib.types.attrsOf lib.types.anything
|
||||||
|
else if kind == "string" then
|
||||||
|
lib.types.str
|
||||||
|
else if kind == "boolean" then
|
||||||
|
lib.types.bool
|
||||||
else
|
else
|
||||||
throw "unhandled type `${builtins.toJSON type}` (in ${opt})";
|
throw "Unknown type: ${kind}";
|
||||||
|
|
||||||
mkRustAnalyzerOption =
|
mkNixOption =
|
||||||
opt:
|
|
||||||
{
|
{
|
||||||
default,
|
description,
|
||||||
markdownDescription,
|
pluginDefault,
|
||||||
type ? null,
|
type,
|
||||||
anyOf ? null,
|
|
||||||
# Enum types
|
|
||||||
enum ? null,
|
|
||||||
enumDescriptions ? null,
|
|
||||||
# Int types
|
|
||||||
minimum ? null,
|
|
||||||
maximum ? null,
|
|
||||||
# List types
|
|
||||||
items ? null,
|
|
||||||
uniqueItems ? false,
|
|
||||||
}:
|
}:
|
||||||
mkOption {
|
helpers.defaultNullOpts.mkNullable' {
|
||||||
type = types.nullOr (
|
inherit description pluginDefault;
|
||||||
mkRustAnalyzerType opt {
|
type = mkRustAnalyzerType type;
|
||||||
inherit
|
|
||||||
type
|
|
||||||
enum
|
|
||||||
minimum
|
|
||||||
maximum
|
|
||||||
items
|
|
||||||
anyOf
|
|
||||||
uniqueItems
|
|
||||||
;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
default = null;
|
|
||||||
description =
|
|
||||||
if enum != null then
|
|
||||||
let
|
|
||||||
valueDesc = builtins.map ({ fst, snd }: ''- ${fst}: ${snd}'') (
|
|
||||||
lists.zipLists enum enumDescriptions
|
|
||||||
);
|
|
||||||
in
|
|
||||||
''
|
|
||||||
${markdownDescription}
|
|
||||||
|
|
||||||
Values:
|
|
||||||
${builtins.concatStringsSep "\n" valueDesc}
|
|
||||||
|
|
||||||
```nix
|
|
||||||
${generators.toPretty { } default}
|
|
||||||
```
|
|
||||||
''
|
|
||||||
else
|
|
||||||
''
|
|
||||||
${markdownDescription}
|
|
||||||
|
|
||||||
default:
|
|
||||||
```nix
|
|
||||||
${generators.toPretty { } default}
|
|
||||||
```
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
nixOptions = builtins.mapAttrs mkRustAnalyzerOption rustAnalyzerOptions;
|
|
||||||
|
|
||||||
nestOpt =
|
nestOpt =
|
||||||
opt: value:
|
opt: value:
|
||||||
let
|
let
|
||||||
parts = strings.splitString "." opt;
|
parts = lib.strings.splitString "." opt;
|
||||||
in
|
in
|
||||||
builtins.foldl' (current: segment: { ${segment} = current; }) value (lists.reverseList parts);
|
lib.setAttrByPath parts value;
|
||||||
|
|
||||||
nestedNixOptions = attrsets.mapAttrsToList nestOpt nixOptions;
|
nestedNixOptions = lib.attrsets.mapAttrsToList (
|
||||||
|
name: value: nestOpt name (mkNixOption value)
|
||||||
|
) rustAnalyzerOptions;
|
||||||
in
|
in
|
||||||
(builtins.foldl' attrsets.recursiveUpdate { } nestedNixOptions).rust-analyzer
|
(builtins.foldl' lib.attrsets.recursiveUpdate { } nestedNixOptions).rust-analyzer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue