From 7723267fd5c86ff71e7afba1f0631f1f018e5d61 Mon Sep 17 00:00:00 2001 From: uku Date: Wed, 8 Jan 2025 12:15:55 +0100 Subject: [PATCH] feat(neovim): add lsp, autoformat and completions --- programs/neovim/default.nix | 7 ++++++- programs/neovim/init.lua | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/programs/neovim/default.nix b/programs/neovim/default.nix index 4bc95e6..1334570 100644 --- a/programs/neovim/default.nix +++ b/programs/neovim/default.nix @@ -6,14 +6,19 @@ extraLuaConfig = builtins.readFile ./init.lua; extraPackages = with pkgs; [ - (lua5_1.withPackages (ps: with ps; [ luarocks ])) + lua5_1 + nixfmt-rfc-style tree-sitter ]; plugins = with pkgs.vimPlugins; [ barbar-nvim catppuccin-nvim + cmp-nvim-lsp + lsp-format-nvim lualine-nvim + nvim-cmp + nvim-lspconfig nvim-treesitter.withAllGrammars nvim-web-devicons # for lualine ]; diff --git a/programs/neovim/init.lua b/programs/neovim/init.lua index c9ea72f..86aa43e 100644 --- a/programs/neovim/init.lua +++ b/programs/neovim/init.lua @@ -36,6 +36,11 @@ vim.opt.inccommand = "split" -- highlight the line the cursor is on 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 vim.schedule(function() vim.opt.clipboard = "unnamedplus" @@ -78,3 +83,31 @@ require("lualine").setup({ }, 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 + [""] = 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" }, + }, + }, + }, +})