From 9dc8cc8176be54df0d9ff4e7ef904e619deea3c2 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:45:02 +0530 Subject: Added a minimal and full configuration settings to neovim. Added language server support for the full neovim configuration. --- modules/tools/editor/neovim/config/options.lua | 16 +++---- modules/tools/editor/neovim/default.nix | 30 ++++++------- .../editor/neovim/plugins/base16.mustache.lua | 12 ----- modules/tools/editor/neovim/plugins/comment.lua | 1 - .../neovim/plugins/config/base16.mustache.lua | 12 +++++ .../tools/editor/neovim/plugins/config/comment.lua | 1 + .../tools/editor/neovim/plugins/config/default.nix | 19 ++++++++ .../editor/neovim/plugins/config/lsp-config.lua | 51 ++++++++++++++++++++++ .../tools/editor/neovim/plugins/config/lualine.lua | 5 +++ .../editor/neovim/plugins/config/nvim-tree.lua | 13 ++++++ .../editor/neovim/plugins/config/treesitter.nix | 13 ++++++ modules/tools/editor/neovim/plugins/default.nix | 36 ++++++++++----- modules/tools/editor/neovim/plugins/lualine.lua | 5 --- modules/tools/editor/neovim/plugins/nvim-tree.lua | 13 ------ modules/tools/editor/neovim/plugins/treesitter.nix | 13 ------ 15 files changed, 163 insertions(+), 77 deletions(-) delete mode 100644 modules/tools/editor/neovim/plugins/base16.mustache.lua delete mode 100644 modules/tools/editor/neovim/plugins/comment.lua create mode 100644 modules/tools/editor/neovim/plugins/config/base16.mustache.lua create mode 100644 modules/tools/editor/neovim/plugins/config/comment.lua create mode 100644 modules/tools/editor/neovim/plugins/config/default.nix create mode 100644 modules/tools/editor/neovim/plugins/config/lsp-config.lua create mode 100644 modules/tools/editor/neovim/plugins/config/lualine.lua create mode 100644 modules/tools/editor/neovim/plugins/config/nvim-tree.lua create mode 100644 modules/tools/editor/neovim/plugins/config/treesitter.nix delete mode 100644 modules/tools/editor/neovim/plugins/lualine.lua delete mode 100644 modules/tools/editor/neovim/plugins/nvim-tree.lua delete mode 100644 modules/tools/editor/neovim/plugins/treesitter.nix (limited to 'modules') diff --git a/modules/tools/editor/neovim/config/options.lua b/modules/tools/editor/neovim/config/options.lua index 17772ca..450e613 100644 --- a/modules/tools/editor/neovim/config/options.lua +++ b/modules/tools/editor/neovim/config/options.lua @@ -31,11 +31,11 @@ vim.api.nvim_create_autocmd("FileType", { }); -- Exception that use spaces -vim.api.nvim_create_autocmd("FileType", { - pattern = {}, - callback = function() - vim.bo.expandtab = true; - vim.bo.tabstop = 2; - vim.bo.shiftwidth = 2; - end, -}); +-- vim.api.nvim_create_autocmd("FileType", { +-- pattern = {}, +-- callback = function() +-- vim.bo.expandtab = true; +-- vim.bo.tabstop = 2; +-- vim.bo.shiftwidth = 2; +-- end, +-- }); diff --git a/modules/tools/editor/neovim/default.nix b/modules/tools/editor/neovim/default.nix index 87fad55..64f2600 100644 --- a/modules/tools/editor/neovim/default.nix +++ b/modules/tools/editor/neovim/default.nix @@ -3,34 +3,34 @@ { options.tools.editor.neovim = { enable = lib.mkEnableOption "Enables neovim."; + configuration = lib.mkOption { + type = lib.types.enum [ + "minimal" + "full" + ]; + default = "minimal"; + description = "The configuration for neovim to use."; + }; }; - config = lib.mkIf config.tools.editor.neovim.enable { + config = + let + plugins = import ./plugins { inherit config pkgs lib; }; + in lib.mkIf config.tools.editor.neovim.enable { programs.neovim.enable = true; programs.neovim.viAlias = true; programs.neovim.vimAlias = true; programs.neovim.vimdiffAlias = true; programs.neovim.defaultEditor = true; - programs.neovim.extraPackages = with pkgs; [ - gcc # Required for treesitter - ]; + home.packages = plugins.requirements; programs.neovim.extraLuaConfig = '' ${import ./config} -${import ./plugins { inherit config; }} +${plugins.configuration} ''; - programs.neovim.plugins = with pkgs.vimPlugins; [ - comment-nvim - lualine-nvim - nvim-treesitter - nvim-web-devicons - nvim-tree-lua - (base16-vim.overrideAttrs (old: { - patchPhase = "ln -s ${config.scheme base16-vim} colors/base16-scheme.vim"; - })) - ]; + programs.neovim.plugins = plugins.list; }; } diff --git a/modules/tools/editor/neovim/plugins/base16.mustache.lua b/modules/tools/editor/neovim/plugins/base16.mustache.lua deleted file mode 100644 index 3c13fcc..0000000 --- a/modules/tools/editor/neovim/plugins/base16.mustache.lua +++ /dev/null @@ -1,12 +0,0 @@ -vim.o.termguicolors = true; -vim.opt.termguicolors = true; -vim.o.background = "dark"; -vim.g.base16colorspace = 256 -vim.cmd.colorscheme("base16-scheme"); - --- Overrides --- disable the background of line numbers -vim.api.nvim_set_hl(0, "LineNr", { link = "Normal" }); - --- change the color of the pane separator -vim.api.nvim_set_hl(0, "WinSeparator", { fg = "#{{base02-hex}}", bg = "None" }); diff --git a/modules/tools/editor/neovim/plugins/comment.lua b/modules/tools/editor/neovim/plugins/comment.lua deleted file mode 100644 index 9086261..0000000 --- a/modules/tools/editor/neovim/plugins/comment.lua +++ /dev/null @@ -1 +0,0 @@ -require("Comment").setup(); diff --git a/modules/tools/editor/neovim/plugins/config/base16.mustache.lua b/modules/tools/editor/neovim/plugins/config/base16.mustache.lua new file mode 100644 index 0000000..3c13fcc --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/base16.mustache.lua @@ -0,0 +1,12 @@ +vim.o.termguicolors = true; +vim.opt.termguicolors = true; +vim.o.background = "dark"; +vim.g.base16colorspace = 256 +vim.cmd.colorscheme("base16-scheme"); + +-- Overrides +-- disable the background of line numbers +vim.api.nvim_set_hl(0, "LineNr", { link = "Normal" }); + +-- change the color of the pane separator +vim.api.nvim_set_hl(0, "WinSeparator", { fg = "#{{base02-hex}}", bg = "None" }); diff --git a/modules/tools/editor/neovim/plugins/config/comment.lua b/modules/tools/editor/neovim/plugins/config/comment.lua new file mode 100644 index 0000000..9086261 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/comment.lua @@ -0,0 +1 @@ +require("Comment").setup(); diff --git a/modules/tools/editor/neovim/plugins/config/default.nix b/modules/tools/editor/neovim/plugins/config/default.nix new file mode 100644 index 0000000..fb2ac1a --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/default.nix @@ -0,0 +1,19 @@ +{ config }: + +let + extra = if config.tools.editor.neovim.configuration == "full" then +'' +${builtins.readFile ./lsp-config.lua} +'' + else ""; +in +'' +${builtins.readFile ./comment.lua} +${builtins.readFile ./lualine.lua} +${import ./treesitter.nix { inherit config; }} +${builtins.readFile (config.scheme { + template = builtins.readFile ./base16.mustache.lua; +})} +${builtins.readFile ./nvim-tree.lua} +${extra} +'' diff --git a/modules/tools/editor/neovim/plugins/config/lsp-config.lua b/modules/tools/editor/neovim/plugins/config/lsp-config.lua new file mode 100644 index 0000000..43cdb95 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/lsp-config.lua @@ -0,0 +1,51 @@ +local lspconfig = require("lspconfig"); + +local filetype_to_lsp = { + lua = "lua_ls", + cpp = "clangd", + c = "clangd", + python = "pyright", + javascript = "tsserver", + typescript = "tsserver", + go = "gopls", + html = "html", + css = "cssls", + json = "jsonls", + bash = "bashls", + graphql = "graphql", + dockerfile = "dockerls", + php = "phpactor", + rust = "rust_analyzer", + haskell = "hls", + deno = "denols", + vim = "vimls", + elixir = "elixirls", + clojure = "clojure_lsp", + scala = "scala_metals", + ruby = "sorbet", +}; + +-- Keeping track of all the lsps that have been already configured +local lsp_setup_done = {}; + +-- Function to setup LSP based on filetype +local function setup_lsp(filetype) + local lsp_server = filetype_to_lsp[filetype]; + if lsp_server and not lsp_setup_done[lsp_server] then + lsp_setup_done[lsp_server] = true; + lspconfig[lsp_server].setup({}); + end +end + +vim.keymap.set("n", "gd", vim.lsp.buf.definition, { noremap = true, silent = true }); +vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { noremap = true, silent = true }); +vim.keymap.set("n", "gr", vim.lsp.buf.references, { noremap = true, silent = true }); +vim.keymap.set("i", "", vim.lsp.buf.completion, { noremap = true, silent = true }); +vim.keymap.set("n", "gk", vim.lsp.buf.hover, { noremap = true, silent = true }); + +vim.api.nvim_create_autocmd("FileType", { + pattern = "*", -- Match all file types + callback = function() + setup_lsp(vim.bo.filetype); -- Call the setup_lsp function only if the filetype is in the mapping + end, +}); diff --git a/modules/tools/editor/neovim/plugins/config/lualine.lua b/modules/tools/editor/neovim/plugins/config/lualine.lua new file mode 100644 index 0000000..ba2eda6 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/lualine.lua @@ -0,0 +1,5 @@ +require("lualine").setup { + options = { + globalstatus = true, + }, +}; diff --git a/modules/tools/editor/neovim/plugins/config/nvim-tree.lua b/modules/tools/editor/neovim/plugins/config/nvim-tree.lua new file mode 100644 index 0000000..c6c4102 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/nvim-tree.lua @@ -0,0 +1,13 @@ +require("nvim-tree").setup { + filters = { + enable = false + }, + renderer = { + indent_markers = { + enable = true + }, + root_folder_label = function(path) + return vim.fn.fnamemodify(path, ":t") + end, + }, +}; diff --git a/modules/tools/editor/neovim/plugins/config/treesitter.nix b/modules/tools/editor/neovim/plugins/config/treesitter.nix new file mode 100644 index 0000000..be0bdb6 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/treesitter.nix @@ -0,0 +1,13 @@ +{ config }: + +'' +require("nvim-treesitter.configs").setup { + auto_install = true, + highlight = { + enable = true, + }, + parser_install_dir = "${config.xdg.dataHome}/nvim", +}; + +vim.opt.runtimepath:append("${config.xdg.dataHome}/nvim"); +'' diff --git a/modules/tools/editor/neovim/plugins/default.nix b/modules/tools/editor/neovim/plugins/default.nix index ace5379..6e4f844 100644 --- a/modules/tools/editor/neovim/plugins/default.nix +++ b/modules/tools/editor/neovim/plugins/default.nix @@ -1,11 +1,27 @@ -{ config }: +{ config, pkgs, lib }: -'' -${builtins.readFile ./comment.lua} -${builtins.readFile ./lualine.lua} -${import ./treesitter.nix { inherit config; }} -${builtins.readFile (config.scheme { - template = builtins.readFile ./base16.mustache.lua; -})} -${builtins.readFile ./nvim-tree.lua} -'' +{ + configuration = import ./config { inherit config; }; + + list = with pkgs.vimPlugins; lib.mkMerge [ + [ + comment-nvim + lualine-nvim + nvim-treesitter + nvim-web-devicons + nvim-tree-lua + (base16-vim.overrideAttrs (old: { + patchPhase = "ln -s ${config.scheme base16-vim} colors/base16-scheme.vim"; + })) + ] + (if config.tools.editor.neovim.configuration == "full" then + [ + nvim-lspconfig + ] + else null) + ]; + + requirements = with pkgs; [ + gcc # for treesitter + ]; +} diff --git a/modules/tools/editor/neovim/plugins/lualine.lua b/modules/tools/editor/neovim/plugins/lualine.lua deleted file mode 100644 index ba2eda6..0000000 --- a/modules/tools/editor/neovim/plugins/lualine.lua +++ /dev/null @@ -1,5 +0,0 @@ -require("lualine").setup { - options = { - globalstatus = true, - }, -}; diff --git a/modules/tools/editor/neovim/plugins/nvim-tree.lua b/modules/tools/editor/neovim/plugins/nvim-tree.lua deleted file mode 100644 index c6c4102..0000000 --- a/modules/tools/editor/neovim/plugins/nvim-tree.lua +++ /dev/null @@ -1,13 +0,0 @@ -require("nvim-tree").setup { - filters = { - enable = false - }, - renderer = { - indent_markers = { - enable = true - }, - root_folder_label = function(path) - return vim.fn.fnamemodify(path, ":t") - end, - }, -}; diff --git a/modules/tools/editor/neovim/plugins/treesitter.nix b/modules/tools/editor/neovim/plugins/treesitter.nix deleted file mode 100644 index be0bdb6..0000000 --- a/modules/tools/editor/neovim/plugins/treesitter.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ config }: - -'' -require("nvim-treesitter.configs").setup { - auto_install = true, - highlight = { - enable = true, - }, - parser_install_dir = "${config.xdg.dataHome}/nvim", -}; - -vim.opt.runtimepath:append("${config.xdg.dataHome}/nvim"); -'' -- cgit v1.2.3