2023-01-22 03:32:08 +00:00
|
|
|
{ pkgs
|
|
|
|
, config
|
|
|
|
, lib
|
|
|
|
, helpers
|
|
|
|
, ...
|
2023-01-21 19:52:56 +01:00
|
|
|
}:
|
|
|
|
with lib; {
|
2023-01-22 03:32:08 +00:00
|
|
|
options.plugins.rust-tools =
|
|
|
|
let
|
|
|
|
mkNullableOptionWithDefault =
|
|
|
|
{ type
|
|
|
|
, description
|
|
|
|
, default
|
|
|
|
,
|
|
|
|
}:
|
|
|
|
mkOption {
|
|
|
|
type = types.nullOr type;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
${description}
|
|
|
|
|
|
|
|
default: `${default}`
|
|
|
|
'';
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
mkNullableBoolDefault = default: description:
|
|
|
|
mkNullableOptionWithDefault {
|
|
|
|
inherit description;
|
|
|
|
type = types.bool;
|
|
|
|
default = toString default;
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
mkNullableStrDefault = default: description:
|
|
|
|
mkNullableOptionWithDefault {
|
|
|
|
inherit description;
|
|
|
|
type = types.str;
|
|
|
|
default = ''"${default}"'';
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
mkNullableIntDefault = default: description:
|
|
|
|
mkNullableOptionWithDefault {
|
|
|
|
inherit description;
|
|
|
|
type = types.int;
|
|
|
|
default = toString default;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
enable = mkEnableOption "rust tools plugins";
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.vimPlugins.rust-tools-nvim;
|
|
|
|
description = "Package to use for rust-tools";
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
2023-01-24 02:31:32 +01:00
|
|
|
serverPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.rust-analyzer;
|
|
|
|
description = "Package to use for rust-analyzer";
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
executor = mkNullableOptionWithDefault {
|
|
|
|
type = types.enum [ "termopen" "quickfix" ];
|
|
|
|
default = ''"termopen"'';
|
|
|
|
description = "how to execute terminal commands";
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
onIntialized = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Callback to execute once rust-analyzer is done initializing the workspace
|
|
|
|
The callback receives one parameter indicating the `health` of the server:
|
|
|
|
"ok" | "warning" | "error"
|
|
|
|
'';
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
reloadWorkspaceFromCargoToml = mkNullableBoolDefault true ''
|
|
|
|
Automatically call RustReloadWorkspace when writing to a Cargo.toml file.
|
2023-01-21 19:52:56 +01:00
|
|
|
'';
|
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
inlayHints = {
|
|
|
|
auto = mkNullableBoolDefault true "automatically set inlay hints (type hints)";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
onlyCurrentLine = mkNullableBoolDefault false "Only show for current line";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
showParameterHints =
|
|
|
|
mkNullableBoolDefault true
|
|
|
|
"whether to show parameter hints with the inlay hints or not";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
parameterHintsPrefix = mkNullableStrDefault "<- " "prefix for parameter hints";
|
|
|
|
otherHintsPrefix = mkNullableStrDefault "=> " "prefix for all the other hints (type, chaining)";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
maxLenAlign =
|
|
|
|
mkNullableBoolDefault false
|
|
|
|
"whether to align to the length of the longest line in the file";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
maxLenAlignPadding = mkNullableIntDefault 1 "padding from the left if max_len_align is true";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
rightAlign = mkNullableBoolDefault false "whether to align to the extreme right or not";
|
|
|
|
rightAlignPadding = mkNullableIntDefault 7 "padding from the right if right_align is true";
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
highlight = mkNullableStrDefault "Comment" "The color of the hints";
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
hoverActions = {
|
|
|
|
border = mkOption {
|
|
|
|
type = types.nullOr types.anything;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
the border that is used for the hover window. see vim.api.nvim_open_win()
|
|
|
|
'';
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
maxWidth = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
description = "Maximal width of the hover window. Nil means no max.";
|
|
|
|
};
|
|
|
|
maxHeight = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
description = "Maximal height of the hover window. Nil means no max.";
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
autoFocus = mkNullableBoolDefault false "whether the hover action window gets automatically focused";
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
crateGraph = {
|
|
|
|
backend = mkNullableStrDefault "x11" ''
|
|
|
|
Backend used for displaying the graph
|
|
|
|
see: https://graphviz.org/docs/outputs/
|
|
|
|
'';
|
2023-01-21 19:52:56 +01:00
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
output = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "where to store the output, nil for no output stored";
|
|
|
|
};
|
|
|
|
|
|
|
|
full = mkNullableBoolDefault true ''
|
|
|
|
true for all crates.io and external crates, false only the local crates
|
2023-01-21 19:52:56 +01:00
|
|
|
'';
|
2023-01-22 03:32:08 +00:00
|
|
|
|
|
|
|
enabledGraphvizBackends = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
List of backends found on: https://graphviz.org/docs/outputs/
|
|
|
|
Is used for input validation and autocompletion
|
|
|
|
'';
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
|
|
|
|
2023-01-22 03:32:08 +00:00
|
|
|
server =
|
|
|
|
{
|
|
|
|
standalone = mkNullableBoolDefault true ''
|
|
|
|
standalone file support
|
|
|
|
setting it to false may improve startup time
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
// (import ../nvim-lsp/rust-analyzer-config.nix lib);
|
|
|
|
};
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.plugins.rust-tools;
|
|
|
|
in
|
2023-01-21 19:52:56 +01:00
|
|
|
mkIf cfg.enable {
|
2023-01-22 03:32:08 +00:00
|
|
|
extraPlugins = with pkgs.vimPlugins; [ nvim-lspconfig cfg.package ];
|
2023-01-24 02:31:32 +01:00
|
|
|
extraPackages = [ cfg.serverPackage ];
|
2023-01-22 03:32:08 +00:00
|
|
|
|
|
|
|
plugins.lsp.postConfig =
|
|
|
|
let
|
|
|
|
setupOptions = {
|
|
|
|
tools = {
|
|
|
|
executor =
|
|
|
|
if cfg.executor != null
|
|
|
|
then { __raw = ''require("rust-tools.executors").${cfg.executor}''; }
|
|
|
|
else null;
|
|
|
|
|
|
|
|
on_initialized =
|
|
|
|
if cfg.onIntialized != null
|
|
|
|
then { __raw = cfg.onIntialized; }
|
|
|
|
else null;
|
|
|
|
|
|
|
|
reload_workspace_from_cargo_toml = cfg.reloadWorkspaceFromCargoToml;
|
|
|
|
inlay_hints =
|
|
|
|
let
|
|
|
|
cfgIH = cfg.inlayHints;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
auto = cfgIH.auto;
|
|
|
|
only_current_line = cfgIH.onlyCurrentLine;
|
|
|
|
show_parameter_hints = cfgIH.showParameterHints;
|
|
|
|
parameter_hints_prefix = cfgIH.parameterHintsPrefix;
|
|
|
|
other_hints_prefix = cfgIH.otherHintsPrefix;
|
|
|
|
max_len_align = cfgIH.maxLenAlign;
|
|
|
|
max_len_align_padding = cfgIH.maxLenAlignPadding;
|
|
|
|
right_align = cfgIH.rightAlign;
|
|
|
|
right_align_padding = cfgIH.rightAlignPadding;
|
|
|
|
highlight = cfgIH.highlight;
|
|
|
|
};
|
|
|
|
|
|
|
|
hover_actions =
|
|
|
|
let
|
|
|
|
cfgHA = cfg.hoverActions;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
border = cfgHA.border;
|
|
|
|
max_width = cfgHA.maxWidth;
|
|
|
|
max_height = cfgHA.maxHeight;
|
|
|
|
auto_focus = cfgHA.autoFocus;
|
|
|
|
};
|
|
|
|
|
|
|
|
crate_graph =
|
|
|
|
let
|
|
|
|
cfgCG = cfg.crateGraph;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
backend = cfgCG.backend;
|
|
|
|
output = cfgCG.output;
|
|
|
|
full = cfgCG.full;
|
|
|
|
enabled_graphviz_backends = cfgCG.enabledGraphvizBackends;
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
2023-01-22 03:32:08 +00:00
|
|
|
server = {
|
|
|
|
standalone = cfg.server.standalone;
|
|
|
|
settings.rust-analyzer = lib.filterAttrs (n: v: n != "standalone") cfg.server;
|
|
|
|
on_attach = { __raw = "__lspOnAttach"; };
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
|
|
|
};
|
2023-01-22 03:32:08 +00:00
|
|
|
in
|
|
|
|
''
|
|
|
|
require('rust-tools').setup(${helpers.toLuaObject setupOptions})
|
|
|
|
'';
|
2023-01-21 19:52:56 +01:00
|
|
|
};
|
|
|
|
}
|