From 95f95502020a1e8a34fdef5854f61a9ac1e8e48d Mon Sep 17 00:00:00 2001 From: flin16 Date: Sat, 14 Jun 2025 18:27:46 -0500 Subject: [PATCH] feat(lsp): add none-ls.nvim plugin for enhanced LSP support --- lazy-lock.json | 2 +- lazyvim.json | 1 + lua/config/keymaps.lua | 8 ++-- lua/config/options.lua | 2 + lua/plugins/example.lua | 97 ++++++++++++++++++++++++++++++++++------- 5 files changed, 91 insertions(+), 19 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 9ac34ff..1022175 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -5,7 +5,6 @@ "blink.cmp": { "branch": "main", "commit": "022521a8910a5543b0251b21c9e1a1e989745796" }, "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, "catppuccin": { "branch": "main", "commit": "fa42eb5e26819ef58884257d5ae95dd0552b9a66" }, - "coc-code-action-menu.nvim": { "branch": "main", "commit": "42c641ac3ac366d6f0f2536bac4407cba64bae77" }, "coc.nvim": { "branch": "release", "commit": "4fee4938afa69843a3c147f9fdb453de67a1a7a2" }, "codecompanion.nvim": { "branch": "main", "commit": "ac1c3c9d937eb90280eecd00efc12b1b9858b94f" }, "conform.nvim": { "branch": "master", "commit": "8132ec733eed3bf415b97b76797ca41b59f51d7d" }, @@ -34,6 +33,7 @@ "neotest": { "branch": "master", "commit": "ef492755730e59e1d8122c461abbd086bee4c76b" }, "neotest-python": { "branch": "master", "commit": "34c9f6f3dc53fc462ea658b5071238037f95f7aa" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, + "none-ls.nvim": { "branch": "main", "commit": "db2a48b79cfcdab8baa5d3f37f21c78b6705c62e" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-dap": { "branch": "master", "commit": "40a8189b8a57664a1850b0823fdcb3ac95b9f635" }, "nvim-dap-python": { "branch": "master", "commit": "261ce649d05bc455a29f9636dc03f8cdaa7e0e2c" }, diff --git a/lazyvim.json b/lazyvim.json index 60b0892..7a1a06d 100644 --- a/lazyvim.json +++ b/lazyvim.json @@ -11,6 +11,7 @@ "lazyvim.plugins.extras.lang.python", "lazyvim.plugins.extras.lang.tex", "lazyvim.plugins.extras.lang.toml", + "lazyvim.plugins.extras.lsp.none-ls", "lazyvim.plugins.extras.test.core", "lazyvim.plugins.extras.ui.treesitter-context" ], diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 6f05c83..f226cac 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -22,7 +22,7 @@ map_nv("x", '"1x', { desc = "Delete and put the deleted part into secondary clip map_nv("X", '"1X', { desc = "Delete and put the deleted part into secondary clipboard" }) map_nv("", '"1d', { desc = "Delete and put the deleted part into secondary clipboard" }) keyset("n", "", '"1d', { noremap = true, desc = "Backspace in normal mode" }) -keyset("o", "", 'd', { noremap = true, desc = "Backspace in normal mode" }) +keyset("o", "", "d", { noremap = true, desc = "Backspace in normal mode" }) --TODO: This does not work due to which-key keyset({ "x", "v" }, "", '"1x', { noremap = true, desc = "Backspace in normal mode" }) -- keyset("v", "x", '"_x', { noremap = true, desc = "Delete without saving to clipboard" }) @@ -69,6 +69,7 @@ end, { desc = "Print variable (Preview Mode)" }) keyset("n", "r", "(coc-rename)", { desc = "Rename (Coc)" }) keyset("v", "r", "(coc-codeaction-refactor-selected)", { desc = "Refactor Selected (Coc)" }) keyset("n", "cl", "(coc-codelens-action)", { desc = "CodeLens Action (Coc)" }) +-- Code actions are actually twisted by another plugin keyset("n", "ca", "(coc-codeaction)", { desc = "Code Action (Coc)" }) keyset("v", "ca", "(coc-codeaction-selected)", { desc = "Code Action (Coc)" }) @@ -99,7 +100,8 @@ keyset("v", "", '"1d"+gP', { desc = "Remove the selected part and paste fro keyset("v", "", '"+y', { desc = "Copy to clipboard in visual mode" }) keyset("v", "", '"+d', { desc = "Cut to clipboard" }) map_nv("", "ggG", { desc = "Select all" }) --- Test: Code action Menu -vim.keymap.set("n", "m", function() +-- Code action menu +vim.keymap.set({ "n", "v" }, "ca", function() + ---@diagnostic disable-next-line: missing-parameter require("tiny-code-action").code_action() end, { noremap = true, silent = true }) diff --git a/lua/config/options.lua b/lua/config/options.lua index a1e6e9f..0cf8b80 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -5,6 +5,8 @@ if vim.fn.has("gui_running") == 1 then vim.o.clipboard = "" end +vim.g.copilot_no_tab_map = true +vim.api.nvim_set_keymap("i", "", 'copilot#Accept("")', { silent = true, expr = true }) vim.o.guifont = "Monaco:h16" vim.cmd("set wrap") local dap = require("dap") diff --git a/lua/plugins/example.lua b/lua/plugins/example.lua index be78f52..93b769d 100644 --- a/lua/plugins/example.lua +++ b/lua/plugins/example.lua @@ -28,7 +28,7 @@ return { { "c", group = "code", mode = { "n", "v" } }, { "d", group = "debug", mode = { "n", "v" } }, { "r", icon = "󰑕", group = "Rename (COC)" }, - { "a", group = "AI", mode = { "n", "v" } } + { "a", group = "AI", mode = { "n", "v" } }, }, -- name = "\\", -- d = { name = "+debug" }, @@ -42,13 +42,13 @@ return { vim.g.vimtex_view_skim_sync = 1 vim.g.vimtex_view_skim_activate = 1 vim.g.vimtex_compiler_latexmk = { - out_dir = "build", -- use a separate build directory - callback = 1, -- enable callback - continuous = 1, -- enable continuous compilation + out_dir = "build", -- use a separate build directory + callback = 1, -- enable callback + continuous = 1, -- enable continuous compilation options = { - "-pdf", -- use pdf output - "-shell-escape", -- enable shell escape - "-verbose", -- verbose output + "-pdf", -- use pdf output + "-shell-escape", -- enable shell escape + "-verbose", -- verbose output "-file-line-error", -- file line error messages }, } @@ -73,7 +73,7 @@ return { formatters_by_ft = { python = { "black" }, sh = { "shfmt" }, - lua = { "/opt/homebrew/bin/lua" }, + lua = { "stylua" }, tex = { "latexindent" }, }, }, @@ -236,11 +236,39 @@ return { require("utils.codecompanion_fidget_spinner"):init() end, keys = { - { "aa", "CodeCompanionActions", mode = { "n", "v" }, noremap = true, silent = true, desc = "CodeCompanion actions" }, + { + "aa", + "CodeCompanionActions", + mode = { "n", "v" }, + noremap = true, + silent = true, + desc = "CodeCompanion actions", + }, -- Map ai to run CodeCompanion on the selected range in normal and visual modes - { "ai", "'<,'>CodeCompanion", mode = { "n", "v" }, noremap = true, silent = true, desc = "CodeCompanion inline" }, - { "ac", "CodeCompanionChat Toggle", mode = { "n", "v" }, noremap = true, silent = true, desc = "CodeCompanion chat (toggle)" }, - { "ap", "CodeCompanionChat Add", mode = { "v" }, noremap = true, silent = true, desc = "CodeCompanion chat add code" }, + { + "ai", + "'<,'>CodeCompanion", + mode = { "n", "v" }, + noremap = true, + silent = true, + desc = "CodeCompanion inline", + }, + { + "ac", + "CodeCompanionChat Toggle", + mode = { "n", "v" }, + noremap = true, + silent = true, + desc = "CodeCompanion chat (toggle)", + }, + { + "ap", + "CodeCompanionChat Add", + mode = { "v" }, + noremap = true, + silent = true, + desc = "CodeCompanion chat add code", + }, }, opts = { display = { @@ -264,6 +292,7 @@ return { opts = { default_mappings = false, mappings = { + set = "m", set_next = "m,", toggle = "m;", delete_line = "dm-", @@ -275,11 +304,49 @@ return { prev = "[`", -- TODO: This seems not working -- annotate = "m*", - } - } + }, + }, }, { "rachartier/tiny-code-action.nvim" }, - { "xiyaowong/coc-code-action-menu.nvim" }, + { + "nvimtools/none-ls.nvim", + event = "LazyFile", + init = function() + LazyVim.on_very_lazy(function() + -- register the formatter with LazyVim + LazyVim.format.register({ + name = "none-ls.nvim", + priority = 1, -- set higher than conform, the builtin formatter + primary = true, + format = function(buf) + return LazyVim.lsp.format({ + bufnr = buf, + filter = function(client) + return client.name == "null-ls" + end, + }) + end, + sources = function(buf) + local ret = require("null-ls.sources").get_available(vim.bo[buf].filetype, "NULL_LS_FORMATTING") or {} + return vim.tbl_map(function(source) + return source.name + end, ret) + end, + }) + end) + end, + opts = function(_, opts) + local nls = require("null-ls") + opts.root_dir = opts.root_dir + or require("null-ls.utils").root_pattern(".null-ls-root", ".neoconf.json", "Makefile", ".git") + opts.sources = vim.list_extend(opts.sources or {}, { + -- nls.builtins.formatting.fish_indent, + -- nls.builtins.diagnostics.fish, + -- nls.builtins.formatting.stylua, + -- nls.builtins.formatting.shfmt, + }) + end, + }, } -- every spec file under the "plugins" directory will be loaded automatically by lazy.nvim --