Skip to content
Merged
55 changes: 48 additions & 7 deletions dot_config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,11 @@ require('lazy').setup({
},

-- LSP Plugins
-- JSON/YAML schemas (package.json, tsconfig.json, GitHub workflows, ...).
-- Not an lspconfig dependency: lazy.nvim loads it on the first
-- require('schemastore') from the jsonls/yamlls before_init hooks.
{ 'b0o/SchemaStore.nvim', lazy = true, version = false },

{
-- Main LSP Configuration
'neovim/nvim-lspconfig',
Expand Down Expand Up @@ -1263,10 +1268,25 @@ require('lazy').setup({

local servers = {
gopls = {},
jsonls = {},
yamlls = {},
jsonls = {
settings = { json = { validate = { enable = true } } },
before_init = function(_, config) config.settings.json.schemas = require('schemastore').json.schemas() end,
},
yamlls = {
settings = {
yaml = {
-- Use SchemaStore.nvim's catalog instead of yamlls's own download.
schemaStore = { enable = false, url = '' },
},
},
before_init = function(_, config) config.settings.yaml.schemas = require('schemastore').yaml.schemas() end,
},
html = {},
cssls = {},
-- Diagnostics and fix-all code actions; uses the project's eslint.
eslint = {},
-- Only attaches where a biome.json[c] exists; prefers node_modules/.bin/biome.
biome = {},
pyright = {
settings = {
python = {
Expand All @@ -1289,6 +1309,8 @@ require('lazy').setup({
end,
},
markdown_oxide = {},
-- TOML (Cargo.toml, mise.toml, ...): schema-aware completion and formatting.
taplo = {},
}

-- Built, registered, and enabled on the first Kotlin buffer (or Kotlin
Expand Down Expand Up @@ -1378,6 +1400,7 @@ require('lazy').setup({
'ktlint',
'dart-debug-adapter',
'markdown-oxide',
'taplo',
'tree-sitter-cli',
}

Expand All @@ -1388,8 +1411,8 @@ require('lazy').setup({
'json-lsp',
'html-lsp',
'css-lsp',
'typescript-language-server',
'eslint_d',
'eslint-lsp',
'biome',
'prettierd',
})
end
Expand Down Expand Up @@ -1609,6 +1632,11 @@ require('lazy').setup({
{ '<leader>tf', function() require('neotest').run.run(vim.fn.expand '%:p') end, desc = 'Run test file' },
{ '<leader>to', function() require('neotest').output.open() end, desc = 'Test output' },
{ '<leader>tO', function() require('neotest').output_panel.toggle() end, desc = 'Test panel' },
{ '<leader>tr', function() require('neotest').run.run() end, desc = 'Run nearest test' },
{ '<leader>tl', function() require('neotest').run.run_last() end, desc = 'Rerun last test' },
{ '<leader>td', function() require('neotest').run.run { strategy = 'dap' } end, desc = 'Debug nearest test' },
{ '<leader>ts', function() require('neotest').summary.toggle() end, desc = 'Test summary' },
{ '<leader>tS', function() require('neotest').run.stop() end, desc = 'Stop test run' },
},
dependencies = {
'nvim-neotest/nvim-nio',
Expand All @@ -1617,6 +1645,7 @@ require('lazy').setup({
'nvim-treesitter/nvim-treesitter',
'nvim-neotest/neotest-python',
'marilari88/neotest-vitest',
'nvim-neotest/neotest-jest',
},
config = function()
local neotest = require 'neotest'
Expand All @@ -1631,6 +1660,10 @@ require('lazy').setup({
-- pytest_command = { 'python3', '-m', 'pytest' },
},
require 'neotest-vitest',
-- Only claims files in projects that depend on jest.
require 'neotest-jest' {},
-- Provided by rustaceanvim (do not also add neotest-rust).
require 'rustaceanvim.neotest',
},
}
end,
Expand All @@ -1654,7 +1687,9 @@ require('lazy').setup({
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
-- toml: taplo would reformat every hand-edited TOML file on save;
-- format those explicitly with <leader>f instead.
local disable_filetypes = { c = true, cpp = true, toml = true }
if disable_filetypes[vim.bo[bufnr].filetype] then
return nil
else
Expand Down Expand Up @@ -1874,6 +1909,7 @@ require('lazy').setup({
'mermaid',
'powershell',
'query',
'rust',
'thrift',
'toml',
'tsx',
Expand Down Expand Up @@ -1927,7 +1963,12 @@ require('lazy').setup({
{}
)

if vim.fn.executable 'tree-sitter' == 1 then require('nvim-treesitter').install(parsers) end
-- mason installs tree-sitter-cli, but its bin dir is often not on PATH
-- yet when this runs, so a PATH search walks the slow /mnt/c entries
-- on WSL before reaching a mise shim (~65-125 ms per startup). Stat
-- mason's copy first; search PATH only when mason does not have one.
local mason_tree_sitter = vim.fn.stdpath 'data' .. '/mason/bin/tree-sitter'
if vim.uv.fs_stat(mason_tree_sitter) or vim.fn.executable 'tree-sitter' == 1 then require('nvim-treesitter').install(parsers) end
vim.api.nvim_create_autocmd('FileType', {
pattern = filetypes,
callback = function() pcall(vim.treesitter.start) end,
Expand All @@ -1947,7 +1988,7 @@ require('lazy').setup({
-- Here are some example plugins that I've included in the Kickstart repository.
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
--
-- require 'kickstart.plugins.debug',
require 'kickstart.plugins.debug',
-- require 'kickstart.plugins.indent_line',
-- require 'kickstart.plugins.lint',
-- require 'kickstart.plugins.autopairs',
Expand Down
8 changes: 8 additions & 0 deletions dot_config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
"LuaSnip": { "branch": "master", "commit": "642b0c595e11608b4c18219e93b88d7637af27bc" },
"SchemaStore.nvim": { "branch": "main", "commit": "b3025386000bbaacb3d63565011f33e726084116" },
"blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" },
"codecompanion.nvim": { "branch": "main", "commit": "14b4993a24fac8bb122ce524e25bb0f7f392afd6" },
"conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" },
"crates.nvim": { "branch": "main", "commit": "afcd1cc3eeceb5783676fc8464389b9216a29d05" },
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
"fidget.nvim": { "branch": "main", "commit": "9e0201673e08e997e7cf52afca5565c70bd117f3" },
"gitlinker.nvim": { "branch": "master", "commit": "e035542b103876f7ecafaf5c7f1ff4764ca6ff55" },
Expand All @@ -14,14 +16,19 @@
"jj.nvim": { "branch": "main", "commit": "9b1dca730f459b664f8a03f93e0d282693d7d5f8" },
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "443f1ef8b5e6bf47045cb2217b6f748a223cf7dc" },
"mason.nvim": { "branch": "main", "commit": "2a6940af80375532e5e9e7c1f2fc6319a1b7a69d" },
"mini.nvim": { "branch": "main", "commit": "b8a0af521530f8ee68c738657429eab59de6a2ae" },
"neogit": { "branch": "master", "commit": "17929b7b0b9c05fe3dfc788fbba9881eb9c1cbec" },
"neotest": { "branch": "master", "commit": "27bf921498043f7ecd821d6db68d05de244bbd02" },
"neotest-jest": { "branch": "main", "commit": "0e7979d51301dfae5ef839d771bd28cf593fde3f" },
"neotest-python": { "branch": "master", "commit": "1b56ca4ba51c6014f986d6548ee629bdc95589d1" },
"neotest-vitest": { "branch": "main", "commit": "b0c265743c877058068dbc40d104ea5d40e6b257" },
"nvim-allium": { "branch": "main", "commit": "ae0bade344973347f695991f15dfe76ea0299253" },
"nvim-dap": { "branch": "master", "commit": "cfa2d58f4537aca6ca83e2de1a0d9f1491121264" },
"nvim-dap-go": { "branch": "main", "commit": "b4421153ead5d726603b02743ea40cf26a51ed5f" },
"nvim-dap-ui": { "branch": "master", "commit": "cc9dd33aade7f20bae414d0cba163bc60d4d4b43" },
"nvim-lint": { "branch": "master", "commit": "6bf29b9dbdad60b38b489b23309c22ba6d4c915a" },
"nvim-lspconfig": { "branch": "master", "commit": "4648fd8ba5c678d7e2db75ae44ffac269bb589d8" },
"nvim-nio": { "branch": "master", "commit": "edcc181a875301dd21840189aa2f2f9ad69fc172" },
Expand All @@ -30,6 +37,7 @@
"nvim-web-devicons": { "branch": "master", "commit": "0dc0cfb0c6858041174a53c7aa4adaf65e994b3c" },
"plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" },
"render-markdown.nvim": { "branch": "main", "commit": "a67f826164c38c836fc6060f32b275c4c43317a7" },
"rustaceanvim": { "branch": "main", "commit": "b7ca983c6ec88c94cf25e5deaad96df9a68b9a98" },
"smear-cursor.nvim": { "branch": "main", "commit": "f6cb57c342268177f719acc3968b9d8de3ecc969" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "b25b749b9db64d375d782094e2b9dce53ad53a40" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
Expand Down
97 changes: 97 additions & 0 deletions dot_config/nvim/lua/custom/plugins/rust.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-- Rust: rustaceanvim owns rust-analyzer (do not also enable `rust_analyzer`
-- through vim.lsp.enable). rust-analyzer comes from rustup:
-- rustup component add rust-analyzer rust-src
return {
{
'mrcjkb/rustaceanvim',
version = '^9',
lazy = false, -- the plugin lazy-loads itself on the rust filetype
init = function()
-- rustaceanvim probes PATH for cargo-nextest while building its
-- defaults (config/internal.lua), before vim.g.rustaceanvim is merged,
-- so `tools.enable_nextest` cannot skip it. On WSL a miss walks every
-- /mnt/c PATH entry (~80 ms on the first .rs buffer). Answer from
-- cargo's bin dir instead, for this one module load only. If the plugin
-- renames the module this hook never fires and the slow probe returns.
package.preload['rustaceanvim.config.internal'] = function(modname)
local path = vim.api.nvim_get_runtime_file('lua/rustaceanvim/config/internal.lua', false)[1]
local executable = vim.fn.executable
vim.fn.executable = function(name)
if name ~= 'cargo-nextest' then return executable(name) end
local cargo_home = vim.env.CARGO_HOME or (vim.env.HOME .. '/.cargo')
return vim.uv.fs_stat(cargo_home .. '/bin/cargo-nextest') and 1 or 0
end
local ok, mod = pcall(function() return assert(loadfile(path))(modname) end)
vim.fn.executable = executable -- restored even if the load failed
if not ok then error(mod, 0) end
return mod
end

-- A function so blink.cmp is only required when the first Rust buffer opens.
vim.g.rustaceanvim = function()
return {
server = {
capabilities = require('blink.cmp').get_lsp_capabilities(),
on_attach = function(_, bufnr)
local map = function(lhs, rhs, desc) vim.keymap.set('n', lhs, rhs, { buffer = bufnr, desc = desc }) end

map('<leader>rr', function() vim.cmd.RustLsp 'runnables' end, 'Rust: runnables')
map('<leader>rR', function() vim.cmd.RustLsp { 'runnables', bang = true } end, 'Rust: rerun last runnable')
map('<leader>rt', function() vim.cmd.RustLsp 'testables' end, 'Rust: testables')
map('<leader>rd', function() vim.cmd.RustLsp 'debuggables' end, 'Rust: debuggables')
map('<leader>rm', function() vim.cmd.RustLsp 'expandMacro' end, 'Rust: expand macro')
map('<leader>re', function() vim.cmd.RustLsp 'explainError' end, 'Rust: explain error')
map('<leader>rD', function() vim.cmd.RustLsp 'renderDiagnostic' end, 'Rust: render diagnostic')
map('<leader>rc', function() vim.cmd.RustLsp 'openCargo' end, 'Rust: open Cargo.toml')
map('<leader>rp', function() vim.cmd.RustLsp 'parentModule' end, 'Rust: parent module')
map('<leader>rj', function() vim.cmd.RustLsp 'joinLines' end, 'Rust: join lines')
map('K', function() vim.cmd.RustLsp { 'hover', 'actions' } end, 'Rust: hover actions')
end,
default_settings = {
['rust-analyzer'] = {
-- Run clippy instead of `cargo check` on save.
check = { command = 'clippy' },
cargo = { allFeatures = true },
procMacro = { enable = true },
},
},
},
}
end
end,
},

{
-- Crate versions, features and docs inside Cargo.toml, served through an
-- in-process language server so completion reaches blink.cmp and code
-- actions show up under gra.
'saecki/crates.nvim',
version = '^0.7',
event = { 'BufRead Cargo.toml' },
opts = {
lsp = {
enabled = true,
actions = true,
completion = true,
hover = true,
},
},
},

{
'folke/which-key.nvim',
optional = true,
opts = function(_, opts)
opts.spec = opts.spec or {}
table.insert(opts.spec, { '<leader>r', group = '[R]ust/Cargo' })
end,
},

{
'stevearc/conform.nvim',
opts = function(_, opts)
opts.formatters_by_ft = opts.formatters_by_ft or {}
opts.formatters_by_ft.rust = { 'rustfmt' }
end,
},
}
37 changes: 24 additions & 13 deletions dot_config/nvim/lua/custom/plugins/typescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ return {
'neovim/nvim-lspconfig',
},
ft = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' },
init = function()
-- The eslint server comes from vim.lsp.enable in init.lua; its
-- LspEslintFixAll command is buffer-local, so map it on attach.
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('eslint-attach', { clear = true }),
callback = function(event)
local client = vim.lsp.get_client_by_id(event.data.client_id)
if not client or client.name ~= 'eslint' then return end
vim.keymap.set('n', '<leader>cE', '<cmd>LspEslintFixAll<CR>', { buffer = event.buf, desc = 'ESLint: fix all' })
end,
})
end,
config = function()
require('typescript-tools').setup {
settings = {
Expand Down Expand Up @@ -39,10 +51,15 @@ return {
'stevearc/conform.nvim',
opts = function(_, opts)
opts.formatters_by_ft = opts.formatters_by_ft or {}
opts.formatters_by_ft.javascript = { 'prettierd', 'prettier', stop_after_first = true }
opts.formatters_by_ft.javascriptreact = { 'prettierd', 'prettier', stop_after_first = true }
opts.formatters_by_ft.typescript = { 'prettierd', 'prettier', stop_after_first = true }
opts.formatters_by_ft.typescriptreact = { 'prettierd', 'prettier', stop_after_first = true }
-- Biome projects (biome.json[c] above the file) format with biome;
-- everything else keeps prettier.
local function js_formatters(bufnr)
if vim.fs.root(bufnr, { 'biome.json', 'biome.jsonc' }) then return { 'biome' } end
return { 'prettierd', 'prettier', stop_after_first = true }
end
for _, ft in ipairs { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' } do
opts.formatters_by_ft[ft] = js_formatters
end

local previous = opts.format_on_save
opts.format_on_save = function(bufnr)
Expand All @@ -67,27 +84,21 @@ return {
config = function()
local lint = require 'lint'
lint.linters_by_ft = lint.linters_by_ft or {}
lint.linters_by_ft.javascript = { 'eslint_d' }
lint.linters_by_ft.javascriptreact = { 'eslint_d' }
lint.linters_by_ft.typescript = { 'eslint_d' }
lint.linters_by_ft.typescriptreact = { 'eslint_d' }
-- JS/TS: ESLint runs as a language server (see `eslint` in init.lua),
-- which also supplies its fixes as code actions.

-- Prose: Vale (on PATH via mise). markdownlint removed in favour of Vale rules.
lint.linters_by_ft.markdown = { 'vale' }
lint.linters_by_ft.text = { 'vale' }
lint.linters_by_ft.rst = { 'vale' }

local lint_autocmd_ft = {
javascript = true,
javascriptreact = true,
typescript = true,
typescriptreact = true,
markdown = true,
text = true,
rst = true,
}

local lint_augroup = vim.api.nvim_create_augroup('lint-typescript', { clear = true })
local lint_augroup = vim.api.nvim_create_augroup('lint-prose', { clear = true })
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
group = lint_augroup,
callback = function()
Expand Down
Loading
Loading