From ad0712f1f63c61b05d14686424ebf45ca77a935f Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Thu, 6 Jun 2024 21:59:17 +0930 Subject: [PATCH] feat: add back trouble --- .config/nvim/lua/tovi/plugins/flash.lua | 69 +++++-- .../nvim/lua/tovi/plugins/lsp/lspconfig.lua | 188 +++++++++--------- .config/nvim/lua/tovi/plugins/nvim-cmp.lua | 51 +++-- .config/nvim/lua/tovi/plugins/telescope.lua | 2 + .config/nvim/lua/tovi/plugins/trouble.lua | 37 ++++ 5 files changed, 210 insertions(+), 137 deletions(-) create mode 100644 .config/nvim/lua/tovi/plugins/trouble.lua diff --git a/.config/nvim/lua/tovi/plugins/flash.lua b/.config/nvim/lua/tovi/plugins/flash.lua index 9200110..d8d4f10 100644 --- a/.config/nvim/lua/tovi/plugins/flash.lua +++ b/.config/nvim/lua/tovi/plugins/flash.lua @@ -1,20 +1,53 @@ return { - "folke/flash.nvim", - event = "VeryLazy", - ---@type Flash.Config - opts = { - modes = { - char = { - enabled = false, - } - } - }, - -- stylua: ignore - keys = { - { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, - { "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, - { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, - { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, - { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, - }, + "folke/flash.nvim", + event = "VeryLazy", + opts = { + modes = { + char = { + enabled = false, + }, + }, + }, + keys = { + { + "s", + mode = { "n", "x", "o" }, + function() + require("flash").jump() + end, + desc = "Flash", + }, + { + "S", + mode = { "n", "x", "o" }, + function() + require("flash").treesitter() + end, + desc = "Flash Treesitter", + }, + { + "r", + mode = "o", + function() + require("flash").remote() + end, + desc = "Remote Flash", + }, + { + "R", + mode = { "o", "x" }, + function() + require("flash").treesitter_search() + end, + desc = "Treesitter Search", + }, + { + "", + mode = { "c" }, + function() + require("flash").toggle() + end, + desc = "Toggle Flash Search", + }, + }, } diff --git a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua index 20a4ecd..a6917ca 100644 --- a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua +++ b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua @@ -8,7 +8,7 @@ return { config = function() -- import lspconfig plugin local lspconfig = require("lspconfig") - local util = require("lspconfig.util") + local util = require("lspconfig.util") -- import cmp-nvim-lsp plugin local cmp_nvim_lsp = require("cmp_nvim_lsp") @@ -79,13 +79,16 @@ return { vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) end, opts) + opts.desc = "Show documentation for what is under cursor" + keymap.set("n", "ld", vim.diagnostic.setqflist, opts) -- show documentation for what is under cursor + opts.desc = "Show documentation for what is under cursor" keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor end -- override default floating window border if not set local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview - ---@diagnostic disable-next-line: duplicate-set-field + ---@diagnostic disable-next-line: duplicate-set-field function vim.lsp.util.open_floating_preview(contents, syntax, options, ...) options = options or {} options.border = options.border or "rounded" @@ -107,72 +110,72 @@ return { on_attach = on_attach, }) - -- Function to detect the operating system - local function get_os() - local handle = io.popen('uname') - if not handle then - return error("Failed to detect operating system") - end - local result = handle:read("*a") - handle:close() - return result:lower():gsub("%s+", "") - end - - -- Set the base path based on the operating system - local os = get_os() - local base_path = "" - - if os == "darwin" then - base_path = "/opt/homebrew/lib/node_modules" - elseif os == "linux" then - base_path = "/usr/local/lib/node_modules" - end - - lspconfig.tsserver.setup({ - init_options = { - plugins = { - { - name = "@vue/typescript-plugin", - location = base_path .. "/@vue/typescript-plugin", - languages = { "javascript", "typescript", "vue" }, - }, - }, - }, - filetypes = { - "javascript", - "typescript", - "vue", - }, - capabilities = capabilities, - }) - - local function get_typescript_server_path(root_dir) - local global_ts = base_path .. '/typescript/lib' - local found_ts = '' - local function check_dir(path) - found_ts = util.path.join(path, 'node_modules', 'typescript', 'lib') - if util.path.exists(found_ts) then - return path - end - end - if util.search_ancestors(root_dir, check_dir) then - return found_ts - else - return global_ts - end - end + -- Function to detect the operating system + local function get_os() + local handle = io.popen("uname") + if not handle then + return error("Failed to detect operating system") + end + local result = handle:read("*a") + handle:close() + return result:lower():gsub("%s+", "") + end + + -- Set the base path based on the operating system + local os = get_os() + local base_path = "" + + if os == "darwin" then + base_path = "/opt/homebrew/lib/node_modules" + elseif os == "linux" then + base_path = "/usr/local/lib/node_modules" + end + + lspconfig.tsserver.setup({ + init_options = { + plugins = { + { + name = "@vue/typescript-plugin", + location = base_path .. "/@vue/typescript-plugin", + languages = { "javascript", "typescript", "vue" }, + }, + }, + }, + filetypes = { + "javascript", + "typescript", + "vue", + }, + capabilities = capabilities, + }) + + local function get_typescript_server_path(root_dir) + local global_ts = base_path .. "/typescript/lib" + local found_ts = "" + local function check_dir(path) + found_ts = util.path.join(path, "node_modules", "typescript", "lib") + if util.path.exists(found_ts) then + return path + end + end + if util.search_ancestors(root_dir, check_dir) then + return found_ts + else + return global_ts + end + end lspconfig.volar.setup({ capabilities = capabilities, on_attach = on_attach, - filetypes = { - "javascript", - "typescript", - "vue", - }, - on_new_config = function(new_config, new_root_dir) - new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir) - end, + filetypes = { + "javascript", + "typescript", + "vue", + }, + on_new_config = function(new_config, new_root_dir) + new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir) + end, }) -- configure css server @@ -183,39 +186,38 @@ return { -- configure php server lspconfig["intelephense"].setup({ - root_dir = function(pattern) - ---@diagnostic disable-next-line: undefined-field - local cwd = vim.loop.cwd() - local root = util.root_pattern('composer.json')(pattern) - - -- prefer cwd if root is a descendant - return util.path.is_descendant(cwd, root) and cwd or root - end, + root_dir = function(pattern) + ---@diagnostic disable-next-line: undefined-field + local cwd = vim.loop.cwd() + local root = util.root_pattern("composer.json")(pattern) + + -- prefer cwd if root is a descendant + return util.path.is_descendant(cwd, root) and cwd or root + end, capabilities = capabilities, on_attach = on_attach, - init_options = { - licenceKey = vim.fn.expand('$HOME/.local/share/nvim/intelephense-licence.txt') - }, - settings = { - } + init_options = { + licenceKey = vim.fn.expand("$HOME/.local/share/nvim/intelephense-licence.txt"), + }, + settings = {}, }) - lspconfig.gopls.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = {"gopls"}, - filetypes = { "go", "gomod", "gowork", "gotmpl" }, - root_dir = util.root_pattern("go.work", "go.mod", ".git"), - settings = { - gopls = { - completeUnimported = true, - usePlaceholders = true, - analyses = { - unusedparams = true, - }, - }, - }, - } + lspconfig.gopls.setup({ + on_attach = on_attach, + capabilities = capabilities, + cmd = { "gopls" }, + filetypes = { "go", "gomod", "gowork", "gotmpl" }, + root_dir = util.root_pattern("go.work", "go.mod", ".git"), + settings = { + gopls = { + completeUnimported = true, + usePlaceholders = true, + analyses = { + unusedparams = true, + }, + }, + }, + }) -- configure lua server (with special settings) lspconfig["lua_ls"].setup({ diff --git a/.config/nvim/lua/tovi/plugins/nvim-cmp.lua b/.config/nvim/lua/tovi/plugins/nvim-cmp.lua index 0de8f41..d60bcc2 100644 --- a/.config/nvim/lua/tovi/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/tovi/plugins/nvim-cmp.lua @@ -9,7 +9,7 @@ return { "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets", "onsails/lspkind.nvim", - "kristijanhusak/vim-dadbod-completion", + "kristijanhusak/vim-dadbod-completion", }, config = function() local cmp = require("cmp") @@ -21,10 +21,10 @@ return { -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) require("luasnip.loaders.from_vscode").lazy_load({ paths = { "~/.config/nvim/snippets" } }) - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil - end + local has_words_before = function() + local line, col = table.unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end cmp.setup({ completion = { @@ -77,36 +77,35 @@ return { -- sources for autocompletion sources = cmp.config.sources({ { name = "nvim_lsp" }, - { name = "copilot" }, + { name = "copilot" }, { name = "luasnip" }, { name = "buffer" }, { name = "path" }, - { name = "vim-dadbod-completion" }, + { name = "vim-dadbod-completion" }, }), -- configure lspkind for vs-code like pictograms in completion menu formatting = { format = lspkind.cmp_format({ - mode = "symbol_text", - -- with_text = true, - menu = { - nvim_lua = "[api]", - nvim_lsp = "[LSP]", - luasnip = "[snip]", - vim_dadbod_completion = "[DB]", - path = "[path]", - buffer = "[Buffer]", - }, + mode = "symbol_text", + menu = { + nvim_lua = "[api]", + nvim_lsp = "[LSP]", + luasnip = "[snip]", + vim_dadbod_completion = "[DB]", + path = "[path]", + buffer = "[Buffer]", + }, }), }, - event = { - on = { - CompleteChanged = function(data) - if data.entry then - vim.lsp.buf.hover() - end - end, - }, - }, + event = { + on = { + CompleteChanged = function(data) + if data.entry then + vim.lsp.buf.hover() + end + end, + }, + }, }) end, } diff --git a/.config/nvim/lua/tovi/plugins/telescope.lua b/.config/nvim/lua/tovi/plugins/telescope.lua index 8422b36..41af924 100644 --- a/.config/nvim/lua/tovi/plugins/telescope.lua +++ b/.config/nvim/lua/tovi/plugins/telescope.lua @@ -126,6 +126,8 @@ return { keymap.set("n", "fo", builtin.oldfiles, {}) keymap.set("n", "m", builtin.marks, {}) + + keymap.set("n", "cc", builtin.commands, {}) keymap.set("n", "ch", builtin.command_history, {}) keymap.set("n", "gb", function() diff --git a/.config/nvim/lua/tovi/plugins/trouble.lua b/.config/nvim/lua/tovi/plugins/trouble.lua new file mode 100644 index 0000000..da1f027 --- /dev/null +++ b/.config/nvim/lua/tovi/plugins/trouble.lua @@ -0,0 +1,37 @@ +return { + "folke/trouble.nvim", + opts = {}, + cmd = "Trouble", + keys = { + { + "xx", + "Trouble diagnostics toggle", + desc = "Diagnostics (Trouble)", + }, + { + "xX", + "Trouble diagnostics toggle filter.buf=0", + desc = "Buffer Diagnostics (Trouble)", + }, + { + "cs", + "Trouble symbols toggle focus=false", + desc = "Symbols (Trouble)", + }, + { + "cl", + "Trouble lsp toggle focus=false win.position=right", + desc = "LSP Definitions / references / ... (Trouble)", + }, + { + "xL", + "Trouble loclist toggle", + desc = "Location List (Trouble)", + }, + { + "xQ", + "Trouble qflist toggle", + desc = "Quickfix List (Trouble)", + }, + }, +}