diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index 21c7e42..6a400f1 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -51,12 +51,15 @@ in cmp-nvim-lsp cmp_luasnip comment-nvim + copilot-cmp + copilot-lua dashboard-nvim + formatter-nvim lsp_lines-nvim + lspkind-nvim lualine-lsp-progress lualine-nvim luasnip - formatter-nvim neogit noice-nvim nui-nvim # for noice-nvim @@ -67,6 +70,7 @@ in nvim-treesitter.withAllGrammars nvim-ts-context-commentstring nvim-web-devicons # for dashboard-nvim + orgmode plenary-nvim # for telescope, neogit telescope-nvim which-key-nvim diff --git a/modules/programs/nvim/init.lua b/modules/programs/nvim/init.lua index 3a5008a..e4b557a 100644 --- a/modules/programs/nvim/init.lua +++ b/modules/programs/nvim/init.lua @@ -92,9 +92,23 @@ require("nvim-treesitter.configs").setup({ }, }) +local lspkind = require("lspkind") +lspkind.init({ + symbol_map = { + Copilot = "", + }, +}) + local cmp = require("cmp") local luasnip = require("luasnip") cmp.setup({ + formatting = { + format = lspkind.cmp_format({ + mode = "symbol", -- show only symbol annotations + maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) + ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) + }), + }, snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) @@ -127,9 +141,11 @@ cmp.setup({ end, { "i", "s" }), }), sources = { - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "buffer" }, + { name = "buffer", priority = 1 }, + { name = "copilot", priority = 8 }, + { name = "luasnip", priority = 7 }, + { name = "nvim_lsp", priority = 9 }, + { name = "orgmode", priority = 9 }, }, }) @@ -190,39 +206,53 @@ wk.register({ ["="] = { "Format", "format (formatter)" }, }, { noremap = true, silent = true }) +local lsp_lines = require("lsp_lines") +lsp_lines.setup() +-- Disable virtual_text since it's redundant due to lsp_lines. +vim.diagnostic.config({ + virtual_text = false, +}) + -- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers.. local capabilities = require("cmp_nvim_lsp").default_capabilities() local lspconfig = require("lspconfig") -local on_attach_def = function(client, bufnr) - local options = { noremap = true, silent = true } -- default options - local buffer_options = table_merge(options, { buffer = bufnr }) -- buffer specific options +local on_attach_def = function(_, bufnr) + local options = { noremap = true, silent = true, buffer = bufnr } - -- set format keybinding - -- prefere lsp formatting over external formatter - if client.server_capabilities.documentFormattingProvider then - local modes = { "n", "v" } - for _, mode in ipairs(modes) do - wk.register({ - ["="] = { + wk.register({ + K = { vim.lsp.buf.hover, "show info" }, + [""] = { + l = { + name = "lsp", + d = { vim.diagnostic.open_float, "open diagnostic window" }, + n = { vim.diagnostic.goto_next, "next error" }, + p = { vim.diagnostic.goto_prev, "prev error" }, + c = { vim.lsp.buf.code_action, "code action" }, + r = { vim.lsp.buf.rename, "rename" }, + f = { function() vim.lsp.buf.format({ async = true }) end, "format (lsp)", + mode = { "n", "v" }, }, - }, table_merge(buffer_options, { mode = mode })) - end - end - - wk.register({ - K = { vim.lsp.buf.hover, "show info" }, - ["l"] = { - name = "lsp", - d = { vim.diagnostic.open_float, "open diagnostic window" }, - n = { vim.diagnostic.goto_next, "next error" }, - p = { vim.diagnostic.goto_prev, "prev error" }, - c = { vim.lsp.buf.code_action, "code action" }, - r = { vim.lsp.buf.rename, "rename" }, + }, + w = { + name = "workspace", + a = { vim.lsp.buf.add_workspace_folder, "add workspace folder" }, + r = { vim.lsp.buf.remove_workspace_folder, "remove workspace folder" }, + l = { + function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, + "list workspace folders", + }, + }, + t = { + name = "toggle", + l = { lsp_lines.toggle, "lsp lines" }, + }, }, g = { name = "goto", @@ -232,7 +262,7 @@ local on_attach_def = function(client, bufnr) i = { vim.lsp.buf.implementation, "implementation" }, t = { vim.lsp.buf.type_definition, "type defininition" }, }, - }, buffer_options) + }, options) end local lspconfig_default_options = { @@ -286,20 +316,6 @@ lspconfig_setup("lua_ls", { }, }) -local lsp_lines = require("lsp_lines") -lsp_lines.setup() --- Disable virtual_text since it's redundant due to lsp_lines. -vim.diagnostic.config({ - virtual_text = false, -}) -wk.register({ - t = { - name = "toggle", - l = { lsp_lines.toggle, "lsp lines" }, - }, - { prefix = "" }, -}) - require("dashboard").setup({ theme = "hyper", config = { @@ -372,3 +388,28 @@ require("nvim-treesitter.configs").setup({ keymaps = { ["."] = "textsubjects-smart" }, }, }) + +require("copilot").setup({ + suggestion = { enabled = false }, + panel = { enabled = false }, +}) +require("copilot_cmp").setup() + +local orgmode = require("orgmode") +-- Load custom treesitter grammar for org filetype +orgmode.setup_ts_grammar() +-- Treesitter configuration +require("nvim-treesitter.configs").setup({ + -- If TS highlights are not enabled at all, or disabled via `disable` prop, + -- highlighting will fallback to default Vim syntax highlighting + highlight = { + enable = true, + -- Required for spellcheck, some LaTex highlights and + -- code block highlights that do not have ts grammar + additional_vim_regex_highlighting = { "org" }, + }, +}) +orgmode.setup({ + org_agenda_files = { "~/Notes/org" }, + org_default_notes_file = "~/Notes/org/refile.org", +})