From b7be3855294b467789978b236f6763e9b545e1ab Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Mon, 25 Mar 2024 22:20:11 +0530 Subject: [PATCH] NVIM: Use Lspsaga for breadcrumbs - Disable statusline breadcrumbs coming from nvim-navic - Use Lspsaga for Hover, Goto References, Peek Definition - Enable Lspsaga Symbol Outline panel - util.lua: Use same icons on Breadcrumbs and Navic Code navigation - Code related shortcuts made for uniform, removed some --- common/.config/nvim/lua/config/util.lua | 56 ++++++++-- .../nvim/lua/plugins/code-formatting.lua | 8 -- .../.config/nvim/lua/plugins/code-generic.lua | 102 ++++++++++++++---- common/.config/nvim/lua/plugins/code-lsp.lua | 6 +- .../nvim/lua/plugins/navigate-code.lua | 10 +- .../nvim/lua/plugins/navigate-files.lua | 22 ++-- common/.config/nvim/lua/plugins/ui.lua | 9 -- 7 files changed, 150 insertions(+), 63 deletions(-) diff --git a/common/.config/nvim/lua/config/util.lua b/common/.config/nvim/lua/config/util.lua index dfe96dc..03294f5 100644 --- a/common/.config/nvim/lua/config/util.lua +++ b/common/.config/nvim/lua/config/util.lua @@ -28,26 +28,26 @@ local M = { Enum = " ", EnumMember = " ", Event = " ", - Field = " ", + Field = " ", File = "󰈙 ", - Folder = " ", - Function = "󰊕 ", + Folder = " ", + Function = "󰡱 ", Interface = " ", Key = "󰌋 ", Keyword = " ", - Method = "󰊕 ", - Module = " ", + Method = "󰡱 ", + Module = " ", Namespace = "󰦮 ", Null = "󰟢 ", Number = "󰎠 ", Object = " ", Operator = " ", - Package = " ", - Property = " ", + Package = " ", + Property = " ", Reference = " ", Snippet = " ", String = " ", - Struct = "󰆼 ", + Struct = " ", TabNine = "󰏚 ", Text = " ", TypeParameter = " ", @@ -55,6 +55,46 @@ local M = { Value = " ", Variable = "󰀫 ", }, + -- Only to keep things in sync with "navbuddy" + kind_lspsaga = { + ["Array"] = { " ", "Type" }, + ["Boolean"] = { "󰨙 ", "Boolean" }, + ["Class"] = { " ", "Include" }, + ["Constant"] = { "󰏿 ", "Constant" }, + ["Constructor"] = { " ", "@constructor" }, + ["Enum"] = { " ", "@number" }, + ["EnumMember"] = { " ", "Number" }, + ["Event"] = { " ", "Constant" }, + ["Field"] = { " ", "@field" }, + ["File"] = { "󰈙 ", "Tag" }, + ["Function"] = { "󰡱 ", "Function" }, + ["Interface"] = { " ", "Type" }, + ["Key"] = { "󰌋 ", "Constant" }, + ["Method"] = { "󰡱 ", "Function" }, + ["Module"] = { " ", "Exception" }, + ["Namespace"] = { "󰦮 ", "Include" }, + ["Null"] = { "󰟢 ", "Constant" }, + ["Number"] = { "󰎠 ", "Number" }, + ["Object"] = { " ", "Type" }, + ["Operator"] = { " ", "Operator" }, + ["Package"] = { " ", "Label" }, + ["Property"] = { " ", "@property" }, + ["String"] = { " ", "String" }, + ["Struct"] = { " ", "Type" }, + ["TypeParameter"] = { " ", "Type" }, + ["Variable"] = { "󰀫 ", "@variable" }, + -- ccls + ["TypeAlias"] = { " ", "Type" }, + ["Parameter"] = { " ", "@parameter" }, + ["StaticMethod"] = { "󰡱 ", "Function" }, + ["Macro"] = { " ", "Macro" }, + -- for completion sb microsoft!!! + ["Text"] = { "󰭷 ", "String" }, + ["Snippet"] = { " ", "@variable" }, + ["Folder"] = { " ", "Title" }, + ["Unit"] = { "󰊱 ", "Number" }, + ["Value"] = { "󰀫 ", "@variable" }, + }, }, } diff --git a/common/.config/nvim/lua/plugins/code-formatting.lua b/common/.config/nvim/lua/plugins/code-formatting.lua index 30803f3..9d3144a 100644 --- a/common/.config/nvim/lua/plugins/code-formatting.lua +++ b/common/.config/nvim/lua/plugins/code-formatting.lua @@ -52,14 +52,6 @@ return { }, }, }) - - vim.keymap.set({ "n", "v" }, "cf", function() - conform.format({ - lsp_fallback = true, - async = false, - timeout_ms = 1000, - }) - end, { desc = "Code Format (visual selection)" }) end, }, } diff --git a/common/.config/nvim/lua/plugins/code-generic.lua b/common/.config/nvim/lua/plugins/code-generic.lua index 5004109..f0b0f10 100644 --- a/common/.config/nvim/lua/plugins/code-generic.lua +++ b/common/.config/nvim/lua/plugins/code-generic.lua @@ -261,29 +261,39 @@ return { end, }, - -- Lsp Breadcrumbs for lualine + -- LspSaga { - "SmiteshP/nvim-navic", - lazy = true, - init = function() - vim.g.navic_silence = true - require("config.util").on_lsp_attach(function(client, buffer) - if client.supports_method("textDocument/documentSymbol") then - require("nvim-navic").attach(client, buffer) - end - end) - end, - opts = function() - return { - separator = " ", - highlight = true, - depth_limit = 5, - icons = require("config.util").icons.kinds, - lazy_update_context = true, - } + "nvimdev/lspsaga.nvim", + dependencies = { + "nvim-treesitter/nvim-treesitter", + "nvim-tree/nvim-web-devicons", + }, + config = function() + require("lspsaga").setup({ + ui = { + kind = require("config.util").icons.kind_lspsaga, + }, + symbol_in_winbar = { + enable = true, + hide_keyword = true, + }, + lightbulb = { + enable = false, + sign = false, + virtual_text = false, + }, + outline = { auto_preview = false }, + }) + + vim.keymap.set("n", "K", "Lspsaga hover_doc", { desc = "Hover Documentation" }) + vim.keymap.set("n", "cR", "Lspsaga finder", { desc = "Code: Goto References" }) + vim.keymap.set("n", "co", "Lspsaga outline", { desc = "Code: Toggle Symbol Outline" }) + vim.keymap.set("n", "cd", "Lspsaga peek_definition", { desc = "Code: Peek definition: Function" }) + vim.keymap.set("n", "cD", "Lspsaga peek_type_definition", { desc = "Code: Peek definition: Class" }) end, }, + -- Search and jump around symbols in the buffer { "SmiteshP/nvim-navbuddy", dependencies = { @@ -295,6 +305,60 @@ return { icons = require("config.util").icons.kinds, }, keys = { + -- Default Mappings on the popup + -- [""] = actions.close(), -- Close and cursor to original location + -- ["q"] = actions.close(), + -- + -- ["j"] = actions.next_sibling(), -- down + -- ["k"] = actions.previous_sibling(), -- up + -- + -- ["h"] = actions.parent(), -- Move to left panel + -- ["l"] = actions.children(), -- Move to right panel + -- ["0"] = actions.root(), -- Move to first panel + -- + -- ["v"] = actions.visual_name(), -- Visual selection of name + -- ["V"] = actions.visual_scope(), -- Visual selection of scope + -- + -- ["y"] = actions.yank_name(), -- Yank the name to system clipboard "+ + -- ["Y"] = actions.yank_scope(), -- Yank the scope to system clipboard "+ + -- + -- ["i"] = actions.insert_name(), -- Insert at start of name + -- ["I"] = actions.insert_scope(), -- Insert at start of scope + -- + -- ["a"] = actions.append_name(), -- Insert at end of name + -- ["A"] = actions.append_scope(), -- Insert at end of scope + -- + -- ["r"] = actions.rename(), -- Rename currently focused symbol + -- + -- ["d"] = actions.delete(), -- Delete scope + -- + -- ["f"] = actions.fold_create(), -- Create fold of current scope + -- ["F"] = actions.fold_delete(), -- Delete fold of current scope + -- + -- ["c"] = actions.comment(), -- Comment out current scope + -- + -- [""] = actions.select(), -- Goto selected symbol + -- ["o"] = actions.select(), + -- + -- ["J"] = actions.move_down(), -- Move focused node down + -- ["K"] = actions.move_up(), -- Move focused node up + -- + -- ["s"] = actions.toggle_preview(), -- Show preview of current node + -- + -- [""] = actions.vsplit(), -- Open selected node in a vertical split + -- [""] = actions.hsplit(), -- Open selected node in a horizontal split + -- + -- ["t"] = actions.telescope({ -- Fuzzy finder at current level. + -- layout_config = { -- All options that can be + -- height = 0.60, -- passed to telescope.nvim's + -- width = 0.60, -- default can be passed here. + -- prompt_position = "top", + -- preview_width = 0.50, + -- }, + -- layout_strategy = "horizontal", + -- }), + -- + -- ["g?"] = actions.help(), -- Open mappings help window { "v", function() diff --git a/common/.config/nvim/lua/plugins/code-lsp.lua b/common/.config/nvim/lua/plugins/code-lsp.lua index b689417..f920cc7 100644 --- a/common/.config/nvim/lua/plugins/code-lsp.lua +++ b/common/.config/nvim/lua/plugins/code-lsp.lua @@ -13,7 +13,7 @@ local on_attach = function(_, bufnr) nmap("cr", vim.lsp.buf.rename, "Rename Symbol") nmap("ca", vim.lsp.buf.code_action, "Code Action") -- See `:help K` for why this keymap - nmap("K", vim.lsp.buf.hover, "Hover Documentation") + -- nmap("K", vim.lsp.buf.hover, "Hover Documentation") -- nmap("", vim.lsp.buf.signature_help, "Signature Documentation") -- Lesser used LSP functionality @@ -153,7 +153,7 @@ return { end, keys = { { - "co", + "cu", function() vim.lsp.buf.code_action({ apply = true, @@ -166,7 +166,7 @@ return { desc = "Typescript: Organize Imports", }, { - "cO", + "cU", function() vim.lsp.buf.code_action({ apply = true, diff --git a/common/.config/nvim/lua/plugins/navigate-code.lua b/common/.config/nvim/lua/plugins/navigate-code.lua index 432aec5..c6c6076 100644 --- a/common/.config/nvim/lua/plugins/navigate-code.lua +++ b/common/.config/nvim/lua/plugins/navigate-code.lua @@ -114,7 +114,6 @@ return { }, textobjects = { - select = { enable = true, lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim @@ -158,11 +157,10 @@ return { enable = true, border = "none", floating_preview_opts = {}, - peek_definition_code = { - -- TIP: Press the shortcut 2 times to enter the floating window - ["cd"] = { query = "@function.outer", desc = "Peek function definition on a popup" }, - ["cD"] = { query = "@class.outer", desc = "Peek class definition on a popup" }, - }, + -- peek_definition_code = { + -- ["cd"] = { query = "@function.outer", desc = "Peek function definition on a popup" }, + -- ["cD"] = { query = "@class.outer", desc = "Peek class definition on a popup" }, + -- }, }, }, }) diff --git a/common/.config/nvim/lua/plugins/navigate-files.lua b/common/.config/nvim/lua/plugins/navigate-files.lua index 7b8f5dd..c98ee6c 100644 --- a/common/.config/nvim/lua/plugins/navigate-files.lua +++ b/common/.config/nvim/lua/plugins/navigate-files.lua @@ -280,21 +280,23 @@ return { vim.keymap.set("n", "ls", require("telescope.builtin").search_history, { desc = "List Search History" }) vim.keymap.set("n", "lv", require("telescope.builtin").vim_options, { desc = "List Vim Options" }) - -- Git things -> Git + -- Git vim.keymap.set("n", "glb", require("telescope.builtin").git_branches, { desc = "List Git Branches" }) vim.keymap.set("n", "glc", require("telescope.builtin").git_commits, { desc = "List Git Commits" }) -- LSP Things -> Coding - vim.keymap.set("n", "cd", require("telescope.builtin").diagnostics, { desc = "Code: List Diagnostics" }) - vim.keymap.set("n", "ci", require("telescope.builtin").lsp_implementations, { desc = "Code: Goto Implementation of the word under cursor" }) - vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "Code: List References for word under cursor" }) - vim.keymap.set("n", "cgt", require("telescope.builtin").lsp_type_definitions, { desc = "Code: Goto definition of the Type under cursor" }) - vim.keymap.set("n", "gd", require("telescope.builtin").lsp_definitions, { desc = "Goto Definition" }) - vim.keymap.set("n", "cgd", require("telescope.builtin").lsp_type_definitions, { desc = "Type Definition" }) - vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "Goto References" }) - vim.keymap.set("n", "cI", require("telescope.builtin").lsp_implementations, { desc = "Goto Implementation" }) - vim.keymap.set("n", "cs", require("telescope.builtin").lsp_document_symbols, { desc = "Document Symbols" }) + vim.keymap.set("n", "cld", require("telescope.builtin").diagnostics, { desc = "Code: List Diagnostics" }) + + vim.keymap.set("n", "ci", require("telescope.builtin").lsp_implementations, { desc = "Code: Goto Implementation" }) + + vim.keymap.set("n", "gd", require("telescope.builtin").lsp_definitions, { desc = "Code: Goto Definition" }) + vim.keymap.set("n", "ct", require("telescope.builtin").lsp_type_definitions, { desc = "Code: Goto Type Definition" }) -- vim.keymap.set("n", "cgD", vim.lsp.buf.declaration, { desc = "Goto Declaration" }) + + vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "Code: Goto References" }) + -- vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "Code: List References for word under cursor" }) + + -- vim.keymap.set("n", "cs", require("telescope.builtin").lsp_document_symbols, { desc = "Document Symbols" }) end, }, } diff --git a/common/.config/nvim/lua/plugins/ui.lua b/common/.config/nvim/lua/plugins/ui.lua index 7c66c2f..74c0571 100644 --- a/common/.config/nvim/lua/plugins/ui.lua +++ b/common/.config/nvim/lua/plugins/ui.lua @@ -220,15 +220,6 @@ return { file_status = true, path = 1, }, - -- Breadcrumbs from "nvim-navic" plugin - { - function() - return require("nvim-navic").get_location() - end, - cond = function() - return package.loaded["nvim-navic"] and require("nvim-navic").is_available() - end, - }, }, lualine_x = {