feat(neovim): add lsp, autoformat and completions

This commit is contained in:
uku 2025-01-08 12:15:55 +01:00
parent e3a513794a
commit 7723267fd5
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o
2 changed files with 39 additions and 1 deletions

View file

@ -6,14 +6,19 @@
extraLuaConfig = builtins.readFile ./init.lua; extraLuaConfig = builtins.readFile ./init.lua;
extraPackages = with pkgs; [ extraPackages = with pkgs; [
(lua5_1.withPackages (ps: with ps; [ luarocks ])) lua5_1
nixfmt-rfc-style
tree-sitter tree-sitter
]; ];
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
barbar-nvim barbar-nvim
catppuccin-nvim catppuccin-nvim
cmp-nvim-lsp
lsp-format-nvim
lualine-nvim lualine-nvim
nvim-cmp
nvim-lspconfig
nvim-treesitter.withAllGrammars nvim-treesitter.withAllGrammars
nvim-web-devicons # for lualine nvim-web-devicons # for lualine
]; ];

View file

@ -36,6 +36,11 @@ vim.opt.inccommand = "split"
-- highlight the line the cursor is on -- highlight the line the cursor is on
vim.opt.cursorline = true vim.opt.cursorline = true
-- set default tab size
vim.opt.shiftwidth = 2
vim.opt.tabstop = 2
vim.opt.expandtab = true
-- sync os clipboard and neovim -- sync os clipboard and neovim
vim.schedule(function() vim.schedule(function()
vim.opt.clipboard = "unnamedplus" vim.opt.clipboard = "unnamedplus"
@ -78,3 +83,31 @@ require("lualine").setup({
}, },
extensions = { "trouble" }, extensions = { "trouble" },
}) })
local cmp = require("cmp")
local cmp_caps = require("cmp_nvim_lsp").default_capabilities()
cmp.setup({
mapping = cmp.mapping.preset.insert({
-- accept completion with enter
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
sources = {
{ name = "nvim_lsp" },
},
})
local lspformat = require("lsp-format")
lspformat.setup({})
local lspconfig = require("lspconfig")
lspconfig.nixd.setup({
on_attach = lspformat.on_attach,
capabilities = cmp_caps,
settings = {
["nixd"] = {
formatting = {
command = { "nixfmt" },
},
},
},
})