mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-05 10:20:14 +00:00
neovim lsp refactor
remove null-ls (archived, deprecated) replace formatting with conform.nvim replace diagnostics with nvim-lint fixed issue where overlay neovim plugins weren't being applied
This commit is contained in:
@ -6,105 +6,104 @@
|
||||
options.kubernetes =
|
||||
lib.mkEnableOption "Whether to enable Kubernetes features";
|
||||
|
||||
config =
|
||||
config = {
|
||||
plugins = [
|
||||
pkgs.vimPlugins.nvim-lspconfig
|
||||
pkgs.vimPlugins.conform-nvim
|
||||
pkgs.vimPlugins.fidget-nvim
|
||||
pkgs.vimPlugins.nvim-lint
|
||||
];
|
||||
|
||||
let
|
||||
|
||||
terraformFormat = if config.terraform then ''
|
||||
require("null-ls").builtins.formatting.terraform_fmt.with({
|
||||
command = "${pkgs.terraform}/bin/terraform",
|
||||
extra_filetypes = { "hcl" },
|
||||
}),
|
||||
'' else
|
||||
"";
|
||||
|
||||
in {
|
||||
plugins = [
|
||||
pkgs.vimPlugins.nvim-lspconfig
|
||||
pkgs.vimPlugins.null-ls-nvim
|
||||
pkgs.vimPlugins.fidget-nvim
|
||||
];
|
||||
|
||||
setup.fidget = { };
|
||||
|
||||
use.lspconfig.lua_ls.setup = dsl.callWith {
|
||||
settings = { Lua = { diagnostics = { globals = [ "vim" "hs" ]; }; }; };
|
||||
capabilities =
|
||||
dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
|
||||
cmd = [ "${pkgs.lua-language-server}/bin/lua-language-server" ];
|
||||
};
|
||||
|
||||
use.lspconfig.nil_ls.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.nil}/bin/nil" ];
|
||||
capabilities =
|
||||
dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
|
||||
};
|
||||
|
||||
use.lspconfig.pyright.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.pyright}/bin/pyright-langserver" "--stdio" ];
|
||||
};
|
||||
|
||||
use.lspconfig.terraformls.setup = dsl.callWith {
|
||||
cmd = if config.terraform then [
|
||||
"${pkgs.terraform-ls}/bin/terraform-ls"
|
||||
"serve"
|
||||
] else
|
||||
[ "echo" ];
|
||||
};
|
||||
|
||||
use.lspconfig.rust_analyzer.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.rust-analyzer}/bin/rust-analyzer" ];
|
||||
settings = {
|
||||
"['rust-analyzer']" = { check = { command = "clippy"; }; };
|
||||
};
|
||||
};
|
||||
|
||||
vim.api.nvim_create_augroup = dsl.callWith [ "LspFormatting" { } ];
|
||||
|
||||
lua = ''
|
||||
${builtins.readFile ./lsp.lua}
|
||||
|
||||
-- Prevent infinite log size (change this when debugging)
|
||||
vim.lsp.set_log_level("off")
|
||||
|
||||
require("null-ls").setup({
|
||||
sources = {
|
||||
require("null-ls").builtins.formatting.stylua.with({ command = "${pkgs.stylua}/bin/stylua" }),
|
||||
require("null-ls").builtins.formatting.black.with({ command = "${pkgs.black}/bin/black" }),
|
||||
require("null-ls").builtins.diagnostics.ruff.with({ command = "${pkgs.ruff}/bin/ruff" }),
|
||||
require("null-ls").builtins.formatting.fish_indent.with({ command = "${pkgs.fish}/bin/fish_indent" }),
|
||||
require("null-ls").builtins.formatting.nixfmt.with({ command = "${pkgs.nixfmt}/bin/nixfmt" }),
|
||||
require("null-ls").builtins.formatting.rustfmt.with({ command = "${pkgs.rustfmt}/bin/rustfmt" }),
|
||||
require("null-ls").builtins.diagnostics.shellcheck.with({ command = "${pkgs.shellcheck}/bin/shellcheck" }),
|
||||
require("null-ls").builtins.formatting.shfmt.with({
|
||||
command = "${pkgs.shfmt}/bin/shfmt",
|
||||
extra_args = { "-i", "4", "-ci" },
|
||||
}),
|
||||
${terraformFormat}
|
||||
},
|
||||
|
||||
on_attach = function(client, bufnr)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
-- Auto-format on save
|
||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format({ bufnr = bufnr })
|
||||
end,
|
||||
})
|
||||
-- Use internal formatting for bindings like gq.
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
callback = function(args)
|
||||
vim.bo[args.buf].formatexpr = nil
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
'';
|
||||
setup.fidget = { };
|
||||
|
||||
use.lspconfig.lua_ls.setup = dsl.callWith {
|
||||
settings = { Lua = { diagnostics = { globals = [ "vim" "hs" ]; }; }; };
|
||||
capabilities =
|
||||
dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
|
||||
cmd = [ "${pkgs.lua-language-server}/bin/lua-language-server" ];
|
||||
};
|
||||
|
||||
use.lspconfig.nil_ls.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.nil}/bin/nil" ];
|
||||
capabilities =
|
||||
dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
|
||||
};
|
||||
|
||||
use.lspconfig.pyright.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.pyright}/bin/pyright-langserver" "--stdio" ];
|
||||
};
|
||||
|
||||
use.lspconfig.terraformls.setup = dsl.callWith {
|
||||
cmd = if config.terraform then [
|
||||
"${pkgs.terraform-ls}/bin/terraform-ls"
|
||||
"serve"
|
||||
] else
|
||||
[ "echo" ];
|
||||
};
|
||||
|
||||
use.lspconfig.rust_analyzer.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.rust-analyzer}/bin/rust-analyzer" ];
|
||||
settings = {
|
||||
"['rust-analyzer']" = { check = { command = "clippy"; }; };
|
||||
};
|
||||
};
|
||||
|
||||
setup.conform = {
|
||||
format_on_save = {
|
||||
# These options will be passed to conform.format()
|
||||
timeout_ms = 500;
|
||||
lsp_fallback = true;
|
||||
};
|
||||
formatters_by_ft = {
|
||||
lua = [ "stylua" ];
|
||||
python = [ "black" ];
|
||||
fish = [ "fish_indent" ];
|
||||
nix = [ "nixfmt" ];
|
||||
rust = [ "rustfmt" ];
|
||||
sh = [ "shfmt" ];
|
||||
terraform = if config.terraform then [ "terraform_fmt" ] else [ ];
|
||||
hcl = if config.terraform then [ "terraform_fmt" ] else [ ];
|
||||
};
|
||||
formatters = {
|
||||
lua.command = "${pkgs.stylua}/bin/stylua";
|
||||
black.command = "${pkgs.black}/bin/black";
|
||||
fish_indent.command = "${pkgs.fish}/bin/fish_indent";
|
||||
nixfmt.command = "${pkgs.nixfmt}/bin/nixfmt";
|
||||
rustfmt = {
|
||||
command = "${pkgs.rustfmt}/bin/rustfmt";
|
||||
prepend_args = [ "--edition" "2021" ];
|
||||
};
|
||||
shfmt = {
|
||||
command = "${pkgs.shfmt}/bin/shfmt";
|
||||
prepend_args = [ "-i" "4" "-ci" ];
|
||||
};
|
||||
terraform_fmt.command =
|
||||
if config.terraform then "${pkgs.terraform}/bin/terraform" else "";
|
||||
};
|
||||
};
|
||||
|
||||
use.lint = {
|
||||
linters_by_ft = dsl.toTable {
|
||||
python = [ "ruff" ];
|
||||
sh = [ "shellcheck" ];
|
||||
};
|
||||
};
|
||||
|
||||
vim.api.nvim_create_autocmd = dsl.callWith [
|
||||
(dsl.toTable [ "BufEnter" "BufWritePost" ])
|
||||
(dsl.rawLua "{ callback = function() require('lint').try_lint() end }")
|
||||
];
|
||||
|
||||
lua = ''
|
||||
${builtins.readFile ./lsp.lua}
|
||||
|
||||
local ruff = require('lint').linters.ruff; ruff.cmd = "${pkgs.ruff}/bin/ruff"
|
||||
local shellcheck = require('lint').linters.shellcheck; shellcheck.cmd = "${pkgs.shellcheck}/bin/shellcheck"
|
||||
|
||||
-- Prevent infinite log size (change this when debugging)
|
||||
vim.lsp.set_log_level("off")
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
pkgs.vimPlugins.glow-nvim # Markdown preview popup
|
||||
pkgs.vimPlugins.nvim-colorizer-lua # Hex color previews
|
||||
pkgs.vimPlugins.which-key-nvim # Keybind helper
|
||||
pkgs.kitty-scrollback-nvim # Scrollback pager for kitty
|
||||
pkgs.vimPlugins.kitty-scrollback-nvim # Scrollback pager for kitty
|
||||
];
|
||||
|
||||
# Initialize some plugins
|
||||
|
@ -24,8 +24,8 @@
|
||||
pkgs.vimPlugins.playground # Tree-sitter experimenting
|
||||
pkgs.vimPlugins.nginx-vim
|
||||
pkgs.vimPlugins.vim-helm
|
||||
pkgs.baleia-nvim # Clean ANSI from kitty scrollback
|
||||
# pkgs.hmts-nvim # Tree-sitter injections for home-manager
|
||||
pkgs.vimPlugins.baleia-nvim # Clean ANSI from kitty scrollback
|
||||
# pkgs.vimPlugins.hmts-nvim # Tree-sitter injections for home-manager
|
||||
(pkgs.vimUtils.buildVimPlugin {
|
||||
pname = "nmasur";
|
||||
version = "0.1";
|
||||
|
Reference in New Issue
Block a user