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:
Noah Masur 2024-02-10 21:04:37 -05:00
parent 2217568a59
commit cf77adb366
7 changed files with 182 additions and 161 deletions

View File

@ -1,22 +1,5 @@
{
"nodes": {
"Comment-nvim-src": {
"flake": false,
"locked": {
"lastModified": 1681214440,
"narHash": "sha256-48hy+hiaDJLlgWqC7IeZI3dT+VwWkRo4atQbyPxu/ys=",
"owner": "numToStr",
"repo": "Comment.nvim",
"rev": "e51f2b142d88bb666dcaa77d93a07f4b419aca70",
"type": "github"
},
"original": {
"owner": "numToStr",
"ref": "v0.8.0",
"repo": "Comment.nvim",
"type": "github"
}
},
"baleia-nvim-src": {
"flake": false,
"locked": {
@ -82,6 +65,23 @@
"type": "github"
}
},
"comment-nvim-src": {
"flake": false,
"locked": {
"lastModified": 1681214440,
"narHash": "sha256-48hy+hiaDJLlgWqC7IeZI3dT+VwWkRo4atQbyPxu/ys=",
"owner": "numToStr",
"repo": "Comment.nvim",
"rev": "e51f2b142d88bb666dcaa77d93a07f4b419aca70",
"type": "github"
},
"original": {
"owner": "numToStr",
"ref": "v0.8.0",
"repo": "Comment.nvim",
"type": "github"
}
},
"darwin": {
"inputs": {
"nixpkgs": [
@ -390,22 +390,6 @@
"type": "github"
}
},
"null-ls-nvim-src": {
"flake": false,
"locked": {
"lastModified": 1691810493,
"narHash": "sha256-cWA0rzkOp/ekVKaFee7iea1lhnqKtWUIU+fW5M950wI=",
"owner": "jose-elias-alvarez",
"repo": "null-ls.nvim",
"rev": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7",
"type": "github"
},
"original": {
"owner": "jose-elias-alvarez",
"repo": "null-ls.nvim",
"type": "github"
}
},
"nur": {
"locked": {
"lastModified": 1707013032,
@ -421,6 +405,22 @@
"type": "github"
}
},
"nvim-lint-src": {
"flake": false,
"locked": {
"lastModified": 1707389610,
"narHash": "sha256-o2XCMJOySY7A40yS8/aFqhOSpPWTleD4DnOMssSKmXc=",
"owner": "mfussenegger",
"repo": "nvim-lint",
"rev": "966ab3dc37eee3e413692264b44a3011b05a6060",
"type": "github"
},
"original": {
"owner": "mfussenegger",
"repo": "nvim-lint",
"type": "github"
}
},
"nvim-lspconfig-src": {
"flake": false,
"locked": {
@ -518,11 +518,11 @@
},
"root": {
"inputs": {
"Comment-nvim-src": "Comment-nvim-src",
"baleia-nvim-src": "baleia-nvim-src",
"bufferline-nvim-src": "bufferline-nvim-src",
"bypass-paywalls-clean": "bypass-paywalls-clean",
"cmp-nvim-lsp-src": "cmp-nvim-lsp-src",
"comment-nvim-src": "comment-nvim-src",
"darwin": "darwin",
"disko": "disko",
"fidget-nvim-src": "fidget-nvim-src",
@ -537,8 +537,8 @@
"nix2vim": "nix2vim",
"nixos-generators": "nixos-generators",
"nixpkgs": "nixpkgs",
"null-ls-nvim-src": "null-ls-nvim-src",
"nur": "nur",
"nvim-lint-src": "nvim-lint-src",
"nvim-lspconfig-src": "nvim-lspconfig-src",
"nvim-tree-lua-src": "nvim-tree-lua-src",
"nvim-treesitter-src": "nvim-treesitter-src",

View File

@ -69,16 +69,12 @@
url = "github:hrsh7th/cmp-nvim-lsp";
flake = false;
};
null-ls-nvim-src = {
url = "github:jose-elias-alvarez/null-ls.nvim";
flake = false;
};
baleia-nvim-src = {
# https://github.com/m00qek/baleia.nvim/tags
url = "github:m00qek/baleia.nvim";
flake = false;
};
Comment-nvim-src = {
comment-nvim-src = {
# https://github.com/numToStr/Comment.nvim/releases
url = "github:numToStr/Comment.nvim/v0.8.0";
flake = false;
@ -124,6 +120,10 @@
url = "github:mikesmithgh/kitty-scrollback.nvim";
flake = false;
};
nvim-lint-src = {
url = "github:mfussenegger/nvim-lint";
flake = false;
};
# Tree-Sitter Grammars
tree-sitter-bash = {
@ -375,6 +375,10 @@
path = ./templates/haskell;
description = "Haskell template";
};
rust = {
path = ./templates/rust;
description = "Rust template";
};
};
};

View File

@ -6,23 +6,12 @@
options.kubernetes =
lib.mkEnableOption "Whether to enable Kubernetes features";
config =
let
terraformFormat = if config.terraform then ''
require("null-ls").builtins.formatting.terraform_fmt.with({
command = "${pkgs.terraform}/bin/terraform",
extra_filetypes = { "hcl" },
}),
'' else
"";
in {
config = {
plugins = [
pkgs.vimPlugins.nvim-lspconfig
pkgs.vimPlugins.null-ls-nvim
pkgs.vimPlugins.conform-nvim
pkgs.vimPlugins.fidget-nvim
pkgs.vimPlugins.nvim-lint
];
setup.fidget = { };
@ -59,50 +48,60 @@
};
};
vim.api.nvim_create_augroup = dsl.callWith [ "LspFormatting" { } ];
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")
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,
})
'';
};

View File

@ -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

View File

@ -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";

View File

@ -1,4 +1,4 @@
{ config, lib, ... }: {
{ config, pkgs, lib, ... }: {
options = {
@ -31,11 +31,22 @@
};
# Allow writing custom scripts outside of Nix
# Probably shouldn't make this a habit
environment.localBinInPath = true;
home-manager.users.${config.user}.xdg = {
# Allow Nix to manage the default applications list
mimeApps.enable = true;
# Create a desktop option for Burp
desktopEntries.burp = lib.mkIf pkgs.stdenv.isLinux {
name = "Burp";
exec = "${config.homePath}/.local/bin/burp.sh";
categories = [ "Application" ];
};
# Set directories for application defaults
userDirs = {
enable = true;

View File

@ -16,21 +16,26 @@ let
in {
nvim-lspconfig = withSrc prev.vimPlugins.nvim-lspconfig inputs.nvim-lspconfig;
cmp-nvim-lsp = withSrc prev.vimPlugins.cmp-nvim-lsp inputs.cmp-nvim-lsp;
null-ls-nvim = withSrc prev.vimPlugins.null-ls-nvim inputs.null-ls-nvim;
comment-nvim = withSrc prev.vimPlugins.comment-nvim inputs.comment-nvim;
vimPlugins = prev.vimPlugins // {
nvim-lspconfig =
withSrc prev.vimPlugins.nvim-lspconfig inputs.nvim-lspconfig-src;
cmp-nvim-lsp = withSrc prev.vimPlugins.cmp-nvim-lsp inputs.cmp-nvim-lsp-src;
comment-nvim = withSrc prev.vimPlugins.comment-nvim inputs.comment-nvim-src;
nvim-treesitter =
withSrc prev.vimPlugins.nvim-treesitter inputs.nvim-treesitter;
telescope-nvim = withSrc prev.vimPlugins.telescope-nvim inputs.telescope-nvim;
withSrc prev.vimPlugins.nvim-treesitter inputs.nvim-treesitter-src;
telescope-nvim =
withSrc prev.vimPlugins.telescope-nvim inputs.telescope-nvim-src;
telescope-project-nvim = withSrc prev.vimPlugins.telescope-project-nvim
inputs.telescope-project-nvim;
inputs.telescope-project-nvim-src;
toggleterm-nvim =
withSrc prev.vimPlugins.toggleterm-nvim inputs.toggleterm-nvim;
withSrc prev.vimPlugins.toggleterm-nvim inputs.toggleterm-nvim-src;
bufferline-nvim =
withSrc prev.vimPlugins.bufferline-nvim inputs.bufferline-nvim;
nvim-tree-lua = withSrc prev.vimPlugins.nvim-tree-lua inputs.nvim-tree-lua;
fidget-nvim = withSrc prev.vimPlugins.fidget-nvim inputs.fidget-nvim;
withSrc prev.vimPlugins.bufferline-nvim inputs.bufferline-nvim-src;
nvim-tree-lua =
withSrc prev.vimPlugins.nvim-tree-lua inputs.nvim-tree-lua-src;
fidget-nvim = withSrc prev.vimPlugins.fidget-nvim inputs.fidget-nvim-src;
nvim-lint = withSrc prev.vimPlugins.nvim-lint inputs.nvim-lint-src;
# Packaging plugins entirely with Nix
baleia-nvim = plugin "baleia-nvim" inputs.baleia-nvim-src;
@ -38,4 +43,6 @@ in {
kitty-scrollback-nvim =
plugin "kitty-scrollback-nvim" inputs.kitty-scrollback-nvim-src;
};
}