Skip to content

Commit 2f2b62c

Browse files
committed
feat(nvim): rust setup
1 parent 6e5be0c commit 2f2b62c

File tree

8 files changed

+127
-76
lines changed

8 files changed

+127
-76
lines changed

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Agent Guidelines for Dotfiles Repository
22

3+
Be extremely concise. Sacrifice grammar for the sake of concision.
4+
35
## Build/Test Commands
46

57
- `drs` - Apply Nix configuration with darwin-rebuild

nix/modules/home-manager.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ in
2929
git
3030
httpie
3131
jq
32+
just
3233
neovim
3334
nixfmt-rfc-style
3435
ripgrep

nix/modules/shell.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# disable welcome message
1414
set -g fish_greeting
1515
16+
# cargo
17+
fish_add_path $HOME/.cargo/bin
18+
1619
# pnpm
1720
set -gx PNPM_HOME "$HOME/.local/share/pnpm"
1821
set -gx PATH "$PNPM_HOME" $PATH

nvim/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TODO
22

3-
lazy c20c4022958780617424a090eee2360d560eb939
3+
lazy 3aa2916569df2664cb68e1c7c38882868f36f8d0
44

55
## Plugins
66

nvim/lazy-lock.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
{
22
"blink.cmp": { "branch": "main", "commit": "327fff91fe6af358e990be7be1ec8b78037d2138" },
3-
"conform.nvim": { "branch": "master", "commit": "b4aab989db276993ea5dcb78872be494ce546521" },
4-
"flash.nvim": { "branch": "main", "commit": "3c942666f115e2811e959eabbdd361a025db8b63" },
3+
"conform.nvim": { "branch": "master", "commit": "9fd3d5e0b689ec1bf400c53cbbec72c6fdf24081" },
4+
"flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" },
55
"friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" },
6-
"gitsigns.nvim": { "branch": "main", "commit": "f780609807eca1f783a36a8a31c30a48fbe150c5" },
7-
"grug-far.nvim": { "branch": "main", "commit": "50d9ee2b5a19634670441948e7e4afaa042f1059" },
8-
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
9-
"lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" },
6+
"gitsigns.nvim": { "branch": "main", "commit": "20ad4419564d6e22b189f6738116b38871082332" },
7+
"grug-far.nvim": { "branch": "main", "commit": "3e72397465f774b01aa38e4fe8e6eecf23d766d9" },
8+
"lazy.nvim": { "branch": "main", "commit": "f0f5bbb9e5bfae5e6468f9359ffea3d151418176" },
9+
"lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" },
1010
"lush.nvim": { "branch": "main", "commit": "9c60ec2279d62487d942ce095e49006af28eed6e" },
1111
"mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" },
1212
"mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" },
13-
"mini.icons": { "branch": "main", "commit": "f9a177c11daa7829389b7b6eaaec8b8a5c47052d" },
14-
"mini.pairs": { "branch": "main", "commit": "3738ea30ff33e0cbf2983dc67319a5468d25b0a9" },
15-
"mini.surround": { "branch": "main", "commit": "e170a2dde4b0a8905c9bb218ed428be94ec0b255" },
16-
"noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" },
13+
"mini.icons": { "branch": "main", "commit": "284798619aed9f4c1ac1b9417b9a5e3b4b85ef3a" },
14+
"mini.pairs": { "branch": "main", "commit": "b9aada8c0e59f2b938e98fbf4eae0799eba96ad9" },
15+
"mini.surround": { "branch": "main", "commit": "da5a221b4317c52447df6d9c18610d19b88ea0f4" },
16+
"noice.nvim": { "branch": "main", "commit": "5099348591f7d3ba9e547b1e631c694c65bbe0b9" },
1717
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
1818
"nvim-lspconfig": { "branch": "master", "commit": "d9879110d0422a566fa01d732556f4d5515e1738" },
1919
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
20-
"nvim-treesitter-context": { "branch": "master", "commit": "41847d3dafb5004464708a3db06b14f12bde548a" },
20+
"nvim-treesitter-context": { "branch": "master", "commit": "ec308c7827b5f8cb2dd0ad303a059c945dd21969" },
2121
"nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" },
22-
"oil.nvim": { "branch": "master", "commit": "07f80ad645895af849a597d1cac897059d89b686" },
23-
"snacks.nvim": { "branch": "main", "commit": "da230e3ca8146da4b73752daaf0a1d07d343c12d" },
24-
"trouble.nvim": { "branch": "main", "commit": "3fb3bd737be8866e5f3a170abc70b4da8b5dd45a" },
25-
"ts-comments.nvim": { "branch": "main", "commit": "1bd9d0ba1d8b336c3db50692ffd0955fe1bb9f0c" },
26-
"twoslash-queries.nvim": { "branch": "main", "commit": "b92622c7b71eceefabd02eef24236041069904b1" },
22+
"oil.nvim": { "branch": "master", "commit": "7e1cd7703ff2924d7038476dcbc04b950203b902" },
23+
"rustaceanvim": { "branch": "master", "commit": "be0d1d14b8504c1c0965b608dc7ed39f2d588c91" },
24+
"snacks.nvim": { "branch": "main", "commit": "78c875b222c938e7ecc91034602e385a409dd30b" },
25+
"trouble.nvim": { "branch": "main", "commit": "bd67efe408d4816e25e8491cc5ad4088e708a69a" },
26+
"ts-comments.nvim": { "branch": "main", "commit": "123a9fb12e7229342f807ec9e6de478b1102b041" },
27+
"twoslash-queries.nvim": { "branch": "main", "commit": "1262c20cad5abd6e89995dc4bc0eaab0e2e4e0b9" },
2728
"vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" },
28-
"which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" }
29+
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }
2930
}

nvim/lua/plugins.lua

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ return {
44
-- blink.cmp (https://github.com/saghen/blink.cmp)
55
{
66
"saghen/blink.cmp",
7-
event = "InsertEnter",
7+
event = { "InsertEnter", "CmdlineEnter" },
88
version = not vim.g.lazyvim_blink_main and "*",
99
build = vim.g.lazyvim_blink_main and "cargo build --release",
1010
opts_extend = {
@@ -27,6 +27,20 @@ return {
2727
},
2828
cmdline = {
2929
enabled = false,
30+
keymap = {
31+
preset = "cmdline",
32+
["<Right>"] = false,
33+
["<Left>"] = false,
34+
},
35+
completion = {
36+
list = { selection = { preselect = false } },
37+
menu = {
38+
auto_show = function(_ctx)
39+
return vim.fn.getcmdtype() == ":"
40+
end,
41+
},
42+
ghost_text = { enabled = true },
43+
},
3044
},
3145
completion = {
3246
accept = {
@@ -566,7 +580,7 @@ return {
566580
-- nvim-lspconfig (https://github.com/neovim/nvim-lspconfig)
567581
{
568582
"neovim/nvim-lspconfig",
569-
event = "VeryLazy",
583+
event = { "BufReadPre", "BufNewFile", "BufWritePre" },
570584
dependencies = {
571585
-- https://github.com/mason-org/mason.nvim
572586
{ "mason-org/mason.nvim", version = "^1.0.0" },
@@ -703,6 +717,7 @@ return {
703717
},
704718
},
705719
nil_ls = {},
720+
rust_analyzer = { enabled = false },
706721
tailwindcss = {
707722
filetypes_exclude = { "markdown" },
708723
filetypes_include = {},
@@ -826,11 +841,10 @@ return {
826841
-- Specify * to use this function as a fallback for any server
827842
-- ["*"] = function(server, opts) end,
828843
tailwindcss = function(_, opts)
829-
local tw = require("util.lsp").get_raw_config("tailwindcss")
830844
opts.filetypes = opts.filetypes or {}
831845

832846
-- Add default filetypes
833-
vim.list_extend(opts.filetypes, tw.default_config.filetypes)
847+
vim.list_extend(opts.filetypes, vim.lsp.config.tailwindcss.filetypes)
834848

835849
-- Remove excluded filetypes
836850
--- @param ft string
@@ -859,14 +873,14 @@ return {
859873
local action, uri, range = unpack(command.arguments)
860874

861875
local function move(newf)
862-
client.request("workspace/executeCommand", {
876+
client:request("workspace/executeCommand", {
863877
command = command.command,
864878
arguments = { action, uri, range, newf },
865879
})
866880
end
867881

868882
local fname = vim.uri_to_fname(uri)
869-
client.request("workspace/executeCommand", {
883+
client:request("workspace/executeCommand", {
870884
command = "typescript.tsserverRequest",
871885
arguments = {
872886
"getMoveToRefactoringFileSuggestions",
@@ -960,14 +974,13 @@ return {
960974
end
961975

962976
if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then
963-
opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and ""
964-
or function(diagnostic)
965-
for d, icon in pairs(icons) do
966-
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
967-
return icon
968-
end
977+
opts.diagnostics.virtual_text.prefix = function(diagnostic)
978+
for d, icon in pairs(icons.diagnostics) do
979+
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
980+
return icon
969981
end
970982
end
983+
end
971984
end
972985

973986
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
@@ -1084,13 +1097,15 @@ return {
10841097
"nix",
10851098
"regex",
10861099
"rust",
1100+
"ron",
10871101
"svelte",
10881102
"toml",
10891103
"tsx",
10901104
"typescript",
10911105
"vim",
10921106
"vimdoc",
10931107
"vue",
1108+
"yaml",
10941109
},
10951110
highlight = { enable = true },
10961111
indent = { enable = true },
@@ -1232,6 +1247,76 @@ return {
12321247
end,
12331248
},
12341249

1250+
-- rustaceanvim (https://github.com/mrcjkb/rustaceanvim)
1251+
{
1252+
"mrcjkb/rustaceanvim",
1253+
ft = { "rust" },
1254+
opts = {
1255+
server = {
1256+
on_attach = function(_, bufnr)
1257+
vim.keymap.set("n", "<leader>cR", function()
1258+
vim.cmd.RustLsp("codeAction")
1259+
end, { desc = "Code Action", buffer = bufnr })
1260+
vim.keymap.set("n", "<leader>dr", function()
1261+
vim.cmd.RustLsp("debuggables")
1262+
end, { desc = "Rust Debuggables", buffer = bufnr })
1263+
end,
1264+
default_settings = {
1265+
-- rust-analyzer language server configuration
1266+
["rust-analyzer"] = {
1267+
cargo = {
1268+
allFeatures = true,
1269+
loadOutDirsFromCheck = true,
1270+
buildScripts = {
1271+
enable = true,
1272+
},
1273+
},
1274+
checkOnSave = true,
1275+
diagnostics = {
1276+
enable = true,
1277+
},
1278+
procMacro = {
1279+
enable = true,
1280+
},
1281+
files = {
1282+
exclude = {
1283+
".direnv",
1284+
".git",
1285+
".jj",
1286+
".github",
1287+
".gitlab",
1288+
"bin",
1289+
"node_modules",
1290+
"target",
1291+
"venv",
1292+
".venv",
1293+
},
1294+
-- Avoid Roots Scanned hanging, see https://github.com/rust-lang/rust-analyzer/issues/12613#issuecomment-2096386344
1295+
watcher = "client",
1296+
},
1297+
},
1298+
},
1299+
},
1300+
},
1301+
config = function(_, opts)
1302+
-- if LazyVim.has("mason.nvim") then
1303+
-- local codelldb = vim.fn.exepath("codelldb")
1304+
-- local codelldb_lib_ext = io.popen("uname"):read("*l") == "Linux" and ".so" or ".dylib"
1305+
-- local library_path = vim.fn.expand("$MASON/opt/lldb/lib/liblldb" .. codelldb_lib_ext)
1306+
-- opts.dap = {
1307+
-- adapter = require("rustaceanvim.config").get_codelldb_adapter(codelldb, library_path),
1308+
-- }
1309+
-- end
1310+
vim.g.rustaceanvim = vim.tbl_deep_extend("keep", vim.g.rustaceanvim or {}, opts or {})
1311+
if vim.fn.executable("rust-analyzer") == 0 then
1312+
require("util.init").error(
1313+
"**rust-analyzer** not found in PATH, please install it.\nhttps://rust-analyzer.github.io/",
1314+
{ title = "rustaceanvim" }
1315+
)
1316+
end
1317+
end,
1318+
},
1319+
12351320
-- snacks.nvim (https://github.com/folke/snacks.nvim)
12361321
{
12371322
"folke/snacks.nvim",

nvim/lua/util/keymaps.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function M.has(buffer, method)
5353
method = method:find("/") and method or "textDocument/" .. method
5454
local clients = require("util.lsp").get_clients({ bufnr = buffer })
5555
for _, client in ipairs(clients) do
56-
if client.supports_method(method) then
56+
if client:supports_method(method) then
5757
return true
5858
end
5959
end

nvim/lua/util/lsp.lua

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@ local M = {}
33

44
function M.get_clients(opts)
55
local ret = {}
6-
if vim.lsp.get_clients then
7-
ret = vim.lsp.get_clients(opts)
8-
else
9-
---@diagnostic disable-next-line: deprecated
10-
ret = vim.lsp.get_active_clients(opts)
11-
if opts and opts.method then
12-
ret = vim.tbl_filter(function(client)
13-
return client.supports_method(opts.method, { bufnr = opts.bufnr })
14-
end, ret)
15-
end
16-
end
6+
ret = vim.lsp.get_clients(opts)
177
return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret
188
end
199

@@ -67,7 +57,7 @@ function M._check_methods(client, buffer)
6757
for method, clients in pairs(M._supports_method) do
6858
clients[client] = clients[client] or {}
6959
if not clients[client][buffer] then
70-
if client.supports_method and client.supports_method(method, { bufnr = buffer }) then
60+
if client.supports_method and client:supports_method(method, buffer) then
7161
clients[client][buffer] = true
7262
vim.api.nvim_exec_autocmds("User", {
7363
pattern = "LspSupportsMethod",
@@ -106,37 +96,6 @@ function M.on_supports_method(method, fn)
10696
})
10797
end
10898

109-
function M.get_config(server)
110-
local configs = require("lspconfig.configs")
111-
return rawget(configs, server)
112-
end
113-
114-
function M.get_raw_config(server)
115-
local ok, ret = pcall(require, "lspconfig.configs." .. server)
116-
if ok then
117-
return ret
118-
end
119-
return require("lspconfig.configs." .. server)
120-
end
121-
122-
function M.is_enabled(server)
123-
local c = M.get_config(server)
124-
return c and c.enabled ~= false
125-
end
126-
127-
---@param server string
128-
---@param cond fun( root_dir, config): boolean
129-
function M.disable(server, cond)
130-
local util = require("lspconfig.util")
131-
local def = M.get_config(server)
132-
---@diagnostic disable-next-line: undefined-field
133-
def.document_config.on_new_config = util.add_hook_before(def.document_config.on_new_config, function(config, root_dir)
134-
if cond(root_dir, config) then
135-
config.enabled = false
136-
end
137-
end)
138-
end
139-
14099
function M.formatter(opts)
141100
opts = opts or {}
142101
local filter = opts.filter or {}
@@ -151,8 +110,8 @@ function M.formatter(opts)
151110
sources = function(buf)
152111
local clients = M.get_clients(require("util.init").merge({}, filter, { bufnr = buf }))
153112
local ret = vim.tbl_filter(function(client)
154-
return client.supports_method("textDocument/formatting")
155-
or client.supports_method("textDocument/rangeFormatting")
113+
return client:supports_method("textDocument/formatting")
114+
or client:supports_method("textDocument/rangeFormatting")
156115
end, clients)
157116
return vim.tbl_map(function(client)
158117
return client.name

0 commit comments

Comments
 (0)