Merge branch 'nvim-rust-tools' of git.shimun.net:shimun/configuration.nix into nvim-rust-tools
This commit is contained in:
commit
5754f9b7a9
157
default.nix
157
default.nix
@ -101,163 +101,6 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
programs.git.ignores = [ ".nvim_session" ];
|
programs.git.ignores = [ ".nvim_session" ];
|
||||||
xdg.configFile."nvim/coc-settings.json".text =
|
|
||||||
let
|
|
||||||
preferProjectEnv = binName: alternate: pkgs.writeShellScript "${binName}-switcher" ''
|
|
||||||
if command -v ${binName}; then
|
|
||||||
${binName} ''${@}
|
|
||||||
else
|
|
||||||
${alternate} ''${@}
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
addSDK = { name, lsp, sdk }: with pkgs; runCommandLocal name
|
|
||||||
{
|
|
||||||
nativeBuildInputs = [ makeWrapper ];
|
|
||||||
} ''
|
|
||||||
makeWrapper ${lsp} $out \
|
|
||||||
--prefix PATH : ${lib.makeBinPath sdk}
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
builtins.toJSON {
|
|
||||||
python = {
|
|
||||||
pythonPath = preferProjectEnv "python3" (pkgs.python3 + "/bin/python3");
|
|
||||||
formatting.autopep8Path = "${pkgs.python3Packages.autopep8}/bin/autopep8";
|
|
||||||
};
|
|
||||||
pyright = {
|
|
||||||
enable = true;
|
|
||||||
};
|
|
||||||
# https://rust-analyzer.github.io/manual.html
|
|
||||||
rust-analyzer = {
|
|
||||||
cargo = {
|
|
||||||
allFeatures = true;
|
|
||||||
runBuildScripts = true;
|
|
||||||
autoreload = true;
|
|
||||||
};
|
|
||||||
completion = {
|
|
||||||
autoimport.enable = true;
|
|
||||||
privateEditable.enable = true;
|
|
||||||
fullFunctionSignatures.enable = true; # https://github.com/rust-lang/rust-analyzer/pull/15582
|
|
||||||
snippets = {
|
|
||||||
"return Err(..)" = {
|
|
||||||
postfix = [ "reterr" ];
|
|
||||||
body = ''return Err($${receiver});'';
|
|
||||||
description = "return expression as Err";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"format!(..)" = {
|
|
||||||
postfix = [ "fmt" ];
|
|
||||||
body = ''format!($${receiver})'';
|
|
||||||
description = "use receiver as format string";
|
|
||||||
scope = "expr";
|
|
||||||
|
|
||||||
};
|
|
||||||
"wrap { .. }" = {
|
|
||||||
postfix = [ "brace" "wrap" ];
|
|
||||||
body = ''{$${receiver}}'';
|
|
||||||
description = "wrap this type in { .. }";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"async move { .. }" = {
|
|
||||||
postfix = [ "asyncm" ];
|
|
||||||
body = ''async move {$${receiver}}'';
|
|
||||||
description = "wrap this type in async move { .. }";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"try { .. }" = {
|
|
||||||
postfix = [ "try" ];
|
|
||||||
body = ''let result: Result<_,_> = try {$${receiver}};'';
|
|
||||||
description = "wrap this type in try { .. }";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"while let Some(item) = { .. } {}" = {
|
|
||||||
postfix = [ "letwhile" ];
|
|
||||||
body = ''while let Some(item) = $${receiver} {}'';
|
|
||||||
description = "wrap this type in while let Some";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"let $x = $x.clone()" = {
|
|
||||||
postfix = [ "cloned" ];
|
|
||||||
body = ''let $${receiver} = $${receiver}.clone();'';
|
|
||||||
description = "clone a variable into a new binding";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"let $x = $x.into()" = {
|
|
||||||
postfix = [ "into" ];
|
|
||||||
body = ''let $${receiver} = $${receiver}.clone();'';
|
|
||||||
description = "call into() and create a new binding";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
"assert_eq!($x, .. );" = {
|
|
||||||
postfix = [ "asseq" ];
|
|
||||||
body = ''assert_eq!($${receiver}, );'';
|
|
||||||
description = "create an assertion for the expression";
|
|
||||||
scope = "expr";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
procMacro = { enable = true; attributes.enable = true; };
|
|
||||||
serverPath = addSDK {
|
|
||||||
name = "rust-env";
|
|
||||||
lsp = "${rust-analyzer}/bin/rust-analyzer";
|
|
||||||
sdk = [ rust-sdk ];
|
|
||||||
};
|
|
||||||
imports.group.enable = true;
|
|
||||||
inlayHints = {
|
|
||||||
closureReturnTypeHints.enable = false;
|
|
||||||
};
|
|
||||||
highlightRelated = {
|
|
||||||
yieldPoints.enable = true;
|
|
||||||
references.enable = true;
|
|
||||||
exitPoints.enable = true;
|
|
||||||
breakPoints.enable = true;
|
|
||||||
};
|
|
||||||
checkOnSave = {
|
|
||||||
#https://github.com/rust-lang/rust-clippy/issues/9560
|
|
||||||
enable = false;
|
|
||||||
allFeatures = true;
|
|
||||||
command = "clippy";
|
|
||||||
# extraArgs = [ "--message-format=json" ];
|
|
||||||
};
|
|
||||||
diagnostics = {
|
|
||||||
enable = true;
|
|
||||||
experimental.enable = true;
|
|
||||||
};
|
|
||||||
files.excludeDirs = [ "result" "target" ];
|
|
||||||
extraEnv = {
|
|
||||||
RA_LOG = "debug";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
languageserver = {
|
|
||||||
ccls = {
|
|
||||||
command = preferProjectEnv "ccls" "${pkgs.ccls}/bin/ccls";
|
|
||||||
filetypes = [ "c" "cc" "cpp" "c++" "objc" "objcpp" ];
|
|
||||||
rootPatterns = [ ".ccls" "compile_commands.json" ".git/" ".hg/" ];
|
|
||||||
initializationOptions = {
|
|
||||||
cache = {
|
|
||||||
directory = "${config.xdg.cacheHome}/ccls";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
clang.extraOptions = [ "-std=c++20" ];
|
|
||||||
};
|
|
||||||
nix = {
|
|
||||||
command = "${pkgs.nil}/bin/nil";
|
|
||||||
formatting.command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt";
|
|
||||||
flake = {
|
|
||||||
autoArchive = true;
|
|
||||||
autoEvalInputs = true;
|
|
||||||
};
|
|
||||||
maxMemoryMB = 1024 * 4;
|
|
||||||
rootPatterns = [ "flake.nix" ];
|
|
||||||
filetypes = [ "nix" ];
|
|
||||||
};
|
|
||||||
diagnostic-languageserver = {
|
|
||||||
filetypes = {
|
|
||||||
sh = [ "${pkgs.shellcheck}/bin/shellcheck" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
cSpell = { diagnosticLevel = "hint"; };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
home.sessionVariables = rec {
|
home.sessionVariables = rec {
|
||||||
EDITOR = "nvim";
|
EDITOR = "nvim";
|
||||||
VISUAL_EDITOR = EDITOR;
|
VISUAL_EDITOR = EDITOR;
|
||||||
|
13
init.lua
13
init.lua
@ -130,16 +130,21 @@ lspconfig.typst_lsp.setup {
|
|||||||
cmd = {(deps["typst-lsp_path"] .. "/bin/typst-lsp")},
|
cmd = {(deps["typst-lsp_path"] .. "/bin/typst-lsp")},
|
||||||
settings = {
|
settings = {
|
||||||
exportPdf = "onType", -- Choose onType, onSave or never.
|
exportPdf = "onType", -- Choose onType, onSave or never.
|
||||||
serverPath = (deps["typst-lsp_path"] .. "/bin/typst-lsp") -- Normally, there is no need to uncomment it.
|
serverPath = (deps["typst-lsp_path"] .. "/bin/typst-lsp"), -- Normally, there is no need to uncomment it.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lspconfig.nil_ls.setup {
|
lspconfig.nil_ls.setup {
|
||||||
cmd = {(deps.nil_path .. "/bin/nil")},
|
cmd = {(deps.nil_path .. "/bin/nil")},
|
||||||
-- https://github.com/oxalica/nil/blob/main/docs/configuration.md
|
-- https://github.com/oxalica/nil/blob/main/docs/configuration.md
|
||||||
settings = {command = {formatting = "nixpkgs-fmt"}},
|
settings = {
|
||||||
flake = {autoArchive = true, autoEvalInputs = true}
|
command = {
|
||||||
|
formatting = "nixpkgs-fmt", },
|
||||||
|
},
|
||||||
|
flake = {
|
||||||
|
autoArchive = true,
|
||||||
|
autoEvalInputs = true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require("lsp-inlayhints").setup()
|
require("lsp-inlayhints").setup()
|
||||||
require("rust.lua")
|
|
||||||
require("completion")
|
require("completion")
|
||||||
|
135
rust.lua
135
rust.lua
@ -114,7 +114,11 @@ vim.g.rustaceanvim = {
|
|||||||
-- standalone file support
|
-- standalone file support
|
||||||
-- setting it to false may improve startup time
|
-- setting it to false may improve startup time
|
||||||
standalone = true,
|
standalone = true,
|
||||||
|
<<<<<<< HEAD
|
||||||
cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")},
|
cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")},
|
||||||
|
=======
|
||||||
|
cmd = {(deps.rust-analyzer_path .. "/bin/rust-analyzer")},
|
||||||
|
>>>>>>> f1a0d412d3356e2c660bfbbc06e083e3ef6c6f05
|
||||||
capabilities = require("cmp_nvim_lsp").default_capabilities(c),
|
capabilities = require("cmp_nvim_lsp").default_capabilities(c),
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
require("lsp-inlayhints").on_attach(client, bufnr)
|
require("lsp-inlayhints").on_attach(client, bufnr)
|
||||||
@ -165,3 +169,134 @@ vim.g.rustaceanvim = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
local rt = require("rust-tools")
|
||||||
|
local deps = require("nvim-deps")
|
||||||
|
|
||||||
|
rt.setup({
|
||||||
|
tools = { -- rust-tools options
|
||||||
|
|
||||||
|
-- how to execute terminal commands
|
||||||
|
-- options right now: termopen / quickfix / toggleterm / vimux
|
||||||
|
executor = require("rust-tools.executors").termopen,
|
||||||
|
|
||||||
|
-- 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"
|
||||||
|
on_initialized = nil,
|
||||||
|
|
||||||
|
-- automatically call RustReloadWorkspace when writing to a Cargo.toml file.
|
||||||
|
reload_workspace_from_cargo_toml = true,
|
||||||
|
|
||||||
|
-- These apply to the default RustSetInlayHints command
|
||||||
|
inlay_hints = {
|
||||||
|
-- automatically set inlay hints (type hints)
|
||||||
|
-- default: true
|
||||||
|
auto = true,
|
||||||
|
|
||||||
|
-- Only show inlay hints for the current line
|
||||||
|
only_current_line = false,
|
||||||
|
|
||||||
|
-- whether to show parameter hints with the inlay hints or not
|
||||||
|
-- default: true
|
||||||
|
show_parameter_hints = true,
|
||||||
|
|
||||||
|
-- prefix for parameter hints
|
||||||
|
-- default: "<-"
|
||||||
|
parameter_hints_prefix = "<- ",
|
||||||
|
|
||||||
|
-- prefix for all the other hints (type, chaining)
|
||||||
|
-- default: "=>"
|
||||||
|
other_hints_prefix = "=> ",
|
||||||
|
|
||||||
|
-- whether to align to the length of the longest line in the file
|
||||||
|
max_len_align = false,
|
||||||
|
|
||||||
|
-- padding from the left if max_len_align is true
|
||||||
|
max_len_align_padding = 1,
|
||||||
|
|
||||||
|
-- whether to align to the extreme right or not
|
||||||
|
right_align = false,
|
||||||
|
|
||||||
|
-- padding from the right if right_align is true
|
||||||
|
right_align_padding = 7,
|
||||||
|
|
||||||
|
-- The color of the hints
|
||||||
|
highlight = "Comment"
|
||||||
|
},
|
||||||
|
|
||||||
|
-- options same as lsp hover / vim.lsp.util.open_floating_preview()
|
||||||
|
hover_actions = {
|
||||||
|
|
||||||
|
-- the border that is used for the hover window
|
||||||
|
-- see vim.api.nvim_open_win()
|
||||||
|
border = {
|
||||||
|
{"╭", "FloatBorder"}, {"─", "FloatBorder"},
|
||||||
|
{"╮", "FloatBorder"}, {"│", "FloatBorder"},
|
||||||
|
{"╯", "FloatBorder"}, {"─", "FloatBorder"},
|
||||||
|
{"╰", "FloatBorder"}, {"│", "FloatBorder"}
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Maximal width of the hover window. Nil means no max.
|
||||||
|
max_width = nil,
|
||||||
|
|
||||||
|
-- Maximal height of the hover window. Nil means no max.
|
||||||
|
max_height = nil,
|
||||||
|
|
||||||
|
-- whether the hover action window gets automatically focused
|
||||||
|
-- default: false
|
||||||
|
auto_focus = false
|
||||||
|
},
|
||||||
|
|
||||||
|
-- settings for showing the crate graph based on graphviz and the dot
|
||||||
|
-- command
|
||||||
|
crate_graph = {
|
||||||
|
-- Backend used for displaying the graph
|
||||||
|
-- see: https://graphviz.org/docs/outputs/
|
||||||
|
-- default: x11
|
||||||
|
backend = "x11",
|
||||||
|
-- where to store the output, nil for no output stored (relative
|
||||||
|
-- path from pwd)
|
||||||
|
-- default: nil
|
||||||
|
output = nil,
|
||||||
|
-- true for all crates.io and external crates, false only the local
|
||||||
|
-- crates
|
||||||
|
-- default: true
|
||||||
|
full = true,
|
||||||
|
|
||||||
|
-- List of backends found on: https://graphviz.org/docs/outputs/
|
||||||
|
-- Is used for input validation and autocompletion
|
||||||
|
-- Last updated: 2021-08-26
|
||||||
|
enabled_graphviz_backends = {
|
||||||
|
"bmp", "cgimage", "canon", "dot", "gv", "xdot", "xdot1.2",
|
||||||
|
"xdot1.4", "eps", "exr", "fig", "gd", "gd2", "gif", "gtk",
|
||||||
|
"ico", "cmap", "ismap", "imap", "cmapx", "imap_np", "cmapx_np",
|
||||||
|
"jpg", "jpeg", "jpe", "jp2", "json", "json0", "dot_json",
|
||||||
|
"xdot_json", "pdf", "pic", "pct", "pict", "plain", "plain-ext",
|
||||||
|
"png", "pov", "ps", "ps2", "psd", "sgi", "svg", "svgz", "tga",
|
||||||
|
"tiff", "tif", "tk", "vml", "vmlz", "wbmp", "webp", "xlib",
|
||||||
|
"x11"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
-- all the opts to send to nvim-lspconfig
|
||||||
|
-- these override the defaults set by rust-tools.nvim
|
||||||
|
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
|
||||||
|
server = {
|
||||||
|
-- standalone file support
|
||||||
|
-- setting it to false may improve startup time
|
||||||
|
standalone = true,
|
||||||
|
cmd = {(deps.rust-analyzer_path .. "/bin/rust-analyzer")}
|
||||||
|
}, -- rust-analyzer options
|
||||||
|
|
||||||
|
-- debugging stuff
|
||||||
|
dap = {
|
||||||
|
adapter = {
|
||||||
|
type = "executable",
|
||||||
|
command = deps.lldb_path .. "lldb-vscode",
|
||||||
|
name = "rt_lldb"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
>>>>>>> f1a0d412d3356e2c660bfbbc06e083e3ef6c6f05
|
||||||
|
Loading…
x
Reference in New Issue
Block a user