1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-12-22 17:01:13 +01:00

plugins/language-servers/rust-analyzer: drop rust-analyer settings options

This commit is contained in:
Gaetan Lepage 2025-12-21 23:47:40 +01:00 committed by Gaétan Lepage
parent 814894ba73
commit ac9833fdcd
9 changed files with 0 additions and 1884 deletions

View file

@ -17,7 +17,6 @@ lib.fix (self: {
# Derivations that build the generated files
efmls-configs-sources = pkgs.callPackage ./efmls-configs.nix { };
none-ls-builtins = pkgs.callPackage ./none-ls.nix { };
rust-analyzer-options = pkgs.callPackage ./rust-analyzer { };
lspconfig-servers = pkgs.callPackage ./nvim-lspconfig { };
conform-formatters = pkgs.callPackage ./conform-nvim.nix { };
version-info = pkgs.callPackage ./version-info { };

View file

@ -1,6 +1,5 @@
{
writeShellApplication,
rust-analyzer-options,
efmls-configs-sources,
none-ls-builtins,
lspconfig-servers,
@ -42,7 +41,6 @@ writeShellApplication {
mkdir -p "$generated_dir"
generate_json "${rust-analyzer-options}"
generate_json "${efmls-configs-sources}"
generate_json "${none-ls-builtins}"
generate_json "${conform-formatters}"

View file

@ -1,233 +0,0 @@
#
# This derivation creates a JSON file that describes the Nix module that needs to be instantiated
#
# The create file is of the form:
#
# {
# "<rust-analyzer.option.name>": {
# "description": "<option description>",
# "type": {
# "kind": "<name of the type>"
# <Other values depending on the kind, like values for enum or subTypes for oneOf>
# }
# }
# }
#
{
lib,
writers,
rust-analyzer,
pandoc,
runCommand,
}:
let
packageJSON = "${rust-analyzer.src}/editors/code/package.json";
options = (lib.importJSON packageJSON).contributes.configuration;
generatedStart = lib.lists.findFirstIndex (
e: e == { title = "$generated-start"; }
) (throw "missing generated start") options;
generatedEnd = lib.lists.findFirstIndex (
e: e == { title = "$generated-end"; }
) (throw "missing generated end") options;
# Extract only the generated properties, removing vscode specific options
rustAnalyzerProperties = lib.lists.sublist (generatedStart + 1) (
generatedEnd - generatedStart - 1
) options;
mkRustAnalyzerOptionType =
nullable: property_name: property:
let
inner =
{
type ? null,
enum ? null,
minimum ? null,
maximum ? null,
items ? null,
anyOf ? null,
properties ? null,
# Not used in the function, but anyOf values contain it
enumDescriptions ? null,
}@property:
if enum != null then
{
kind = "enum";
values = enum;
}
else if anyOf != null then
let
possibleTypes = lib.filter (
sub: !(sub.type or null == "null" && nullable) && !(sub.deprecated or false)
) anyOf;
in
{
kind = "oneOf";
subTypes = builtins.map (
t: mkRustAnalyzerOptionType nullable "${property_name}-sub" t
) possibleTypes;
}
else
(
assert lib.assertMsg (type != null) "property is neither anyOf nor enum, it must have a type";
if lib.isList type then
(
if lib.head type == "null" then
assert lib.assertMsg (
lib.length type == 2
) "Lists starting with null are assumed to mean nullOr, so length 2";
let
innerType = property // {
type = lib.elemAt type 1;
};
inner = mkRustAnalyzerOptionType nullable "${property_name}-inner" innerType;
in
assert lib.assertMsg nullable "nullOr types are not yet handled";
inner
else
let
innerTypes = builtins.map (
t: mkRustAnalyzerOptionType nullable "${property_name}-inner" (property // { type = t; })
) type;
in
{
kind = "oneOf";
subTypes = innerTypes;
}
)
else if type == "array" then
{
kind = "list";
item = mkRustAnalyzerOptionType false "${property_name}-item" items;
}
else if type == "number" || type == "integer" then
{
kind = type;
inherit minimum maximum;
}
else if type == "object" && properties != null then
{
kind = "submodule";
options = lib.mapAttrs (
name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value
) properties;
}
else if
lib.elem type [
"object"
"string"
"boolean"
]
then
{ kind = type; }
else
throw "Unhandled value in ${property_name}: ${lib.generators.toPretty { } property}"
);
in
builtins.addErrorContext "While creating type for ${property_name}:\n${lib.generators.toPretty { } property}" (
inner property
);
mkRustAnalyzerOption =
property_name:
{
# List all possible values so that we are sure no new values are introduced
default,
markdownDescription,
enum ? null,
enumDescriptions ? null,
anyOf ? null,
minimum ? null,
maximum ? null,
items ? null,
# TODO: add this in the documentation ?
uniqueItems ? null,
type ? null,
}:
let
filteredMarkdownDesc =
# If there is a risk that the string contains an heading filter it out
if lib.hasInfix "# " markdownDescription then
builtins.readFile (
runCommand "filtered-documentation" { inherit markdownDescription; } ''
${lib.getExe pandoc} -o $out -t markdown \
--lua-filter=${./heading_filter.lua} <<<"$markdownDescription"
''
)
else
markdownDescription;
enumDesc =
values: descriptions:
let
valueDesc = builtins.map ({ fst, snd }: ''- ${fst}: ${snd}'') (
lib.lists.zipLists values descriptions
);
in
''
${filteredMarkdownDesc}
Values:
${builtins.concatStringsSep "\n" valueDesc}
'';
in
{
type = mkRustAnalyzerOptionType true property_name {
inherit
type
enum
minimum
maximum
items
anyOf
enumDescriptions
;
};
pluginDefault = default;
description =
let
globalDescription = ''
${filteredMarkdownDesc}
'';
in
if
enum == null && (anyOf == null || builtins.all (subProp: !(lib.hasAttr "enum" subProp)) anyOf)
then
globalDescription
else if enum != null then
assert lib.assertMsg (anyOf == null) "enum + anyOf types are not yet handled";
enumDesc enum enumDescriptions
else
let
subEnums = lib.filter (sub: sub ? enum && !(sub.deprecated or false)) anyOf;
subEnum =
assert lib.assertMsg (lib.length subEnums == 1)
"anyOf types may currently only contain a single enum. Found ${
lib.generators.toPretty { } subEnums
}";
lib.head subEnums;
in
if subEnum ? enumDescriptions then
enumDesc subEnum.enum subEnum.enumDescriptions
else
globalDescription;
};
rustAnalyzerOptions = builtins.map (
v:
let
props = lib.attrsToList v.properties;
prop =
assert lib.assertMsg (
lib.length props == 1
) "Rust analyzer configuration items are only supported with a single element";
lib.head props;
in
{
"${prop.name}" = mkRustAnalyzerOption prop.name prop.value;
}
) rustAnalyzerProperties;
in
writers.writeJSON "rust-analyzer-options.json" (lib.mergeAttrsList rustAnalyzerOptions)

View file

@ -1,3 +0,0 @@
function Header(elem)
return pandoc.Strong(elem.content)
end

View file

@ -67,10 +67,6 @@
"--auto-fix"
"--ignore=sema-unused-def-lambda-witharg-formal"
];
formatter.nixf-diagnose.excludes = [
# sema-unused-def-lambda-noarg-formal
"ci/rust-analyzer/default.nix"
];
};
};

File diff suppressed because it is too large Load diff

View file

@ -251,7 +251,6 @@ in
default_settings =
lib.nixvim.mkNullOrStrLuaFnOr
(types.submodule {
options.rust-analyzer = import ../../lsp/language-servers/rust-analyzer-config.nix lib;
freeformType = with types; attrsOf anything;
})
''

View file

@ -50,7 +50,6 @@ let
settings = cfg: { pylsp = cfg; };
};
rust_analyzer = {
settingsOptions = import ./rust-analyzer-config.nix lib;
settings = cfg: { rust-analyzer = cfg; };
};
ts_ls = {

View file

@ -1,82 +0,0 @@
# TODO: make all the types support raw lua
lib:
let
inherit (lib.nixvim) defaultNullOpts;
inherit (lib) types;
rustAnalyzerOptions = lib.importJSON ../../../generated/rust-analyzer-options.json;
mkRustAnalyzerType =
{ kind, ... }@typeInfo:
if kind == "enum" then
types.enum typeInfo.values
else if kind == "oneOf" then
types.oneOf (lib.map mkRustAnalyzerType typeInfo.subTypes)
else if kind == "list" then
types.listOf (mkRustAnalyzerType typeInfo.item)
else if kind == "number" then
let
inherit (typeInfo) minimum maximum;
in
if minimum != null && maximum != null then
types.numbers.between minimum maximum
else if minimum != null then
types.addCheck types.number (x: x >= minimum)
else if maximum != null then
types.addCheck types.number (x: x <= maximum)
else
types.number
else if kind == "integer" then
let
inherit (typeInfo) minimum maximum;
in
if minimum != null && maximum != null then
types.ints.between minimum maximum
else if minimum != null then
types.addCheck types.int (x: x >= minimum)
else if maximum != null then
types.addCheck types.int (x: x <= maximum)
else
types.int
else if kind == "object" then
types.attrsOf types.anything
else if kind == "submodule" then
types.submodule {
options = lib.mapAttrs (
_: ty:
lib.mkOption {
type = mkRustAnalyzerType ty;
description = "";
}
) typeInfo.options;
}
else if kind == "string" then
types.str
else if kind == "boolean" then
types.bool
else
throw "Unknown type: ${kind}";
mkNixOption =
{
description,
pluginDefault,
type,
}:
defaultNullOpts.mkNullable' {
inherit description pluginDefault;
type = mkRustAnalyzerType type;
};
nestOpt =
opt: value:
let
parts = lib.strings.splitString "." opt;
in
lib.setAttrByPath parts value;
nestedNixOptions = lib.mapAttrsToList (
name: value: nestOpt name (mkNixOption value)
) rustAnalyzerOptions;
in
(builtins.foldl' lib.recursiveUpdate { } nestedNixOptions).rust-analyzer