From 611c361951d04cf24392fdaee4b5ade20c075fd5 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Mon, 29 Jan 2024 01:44:58 +0100 Subject: [PATCH] Change telescope to dropdown, telescope now uses select_drow action, remove the hide telescope borders in tokyonight, change visible dirs and tokens in lspsaga lualine status, clangd header/source toggle now also uses drop over edit --- nvim/lua/language_servers/clangd.lua | 44 ++++++++- nvim/lua/language_servers/cmake.lua | 4 +- nvim/lua/plugs/lspsaga.lua | 4 +- nvim/lua/plugs/mason_lsp.lua | 12 ++- nvim/lua/plugs/telescope.lua | 131 +++++++++++++++++++++++++-- nvim/lua/plugs/tokyonight.lua | 56 ++++++------ 6 files changed, 206 insertions(+), 45 deletions(-) diff --git a/nvim/lua/language_servers/clangd.lua b/nvim/lua/language_servers/clangd.lua index a564707..25169ca 100644 --- a/nvim/lua/language_servers/clangd.lua +++ b/nvim/lua/language_servers/clangd.lua @@ -1 +1,43 @@ -return {} +local function switch_between_header_and_source(bufnr) + local util = require("lspconfig/util") + bufnr = util.validate_bufnr(bufnr) + local clangd_client = util.get_active_client_by_name(bufnr, "clangd") + local params = { uri = vim.uri_from_bufnr(bufnr) } + -- invert this with an early return + if not clangd_client then + print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer" + return + end + + clangd_client.request("textDocument/switchSourceHeader", params, function(err, result) + if err then + error(tostring(err)) + end + if not result then + print("Corresponding file cannot be determined") + return + end + vim.api.nvim_command("drop " .. vim.uri_to_fname(result)) + end, bufnr) +end + +local M = { + commands = { + ClangdSwitchSourceHeader = { + function() + switch_between_header_and_source(0) + end, + description = "Switch between source/header", + }, + }, +} + +function M.post_setup() + require("utils").add_keymaps({ + n = { + ["ko"] = { cmd = ":ClangdSwitchSourceHeader" } + }, + }) +end + +return M diff --git a/nvim/lua/language_servers/cmake.lua b/nvim/lua/language_servers/cmake.lua index a564707..b30bcbd 100644 --- a/nvim/lua/language_servers/cmake.lua +++ b/nvim/lua/language_servers/cmake.lua @@ -1 +1,3 @@ -return {} +return { + +} diff --git a/nvim/lua/plugs/lspsaga.lua b/nvim/lua/plugs/lspsaga.lua index 513f53a..5c2a4d8 100644 --- a/nvim/lua/plugs/lspsaga.lua +++ b/nvim/lua/plugs/lspsaga.lua @@ -13,11 +13,11 @@ return { hide_keyword = true, ignore_patterns = nil, show_file = true, - folder_level = 3, + folder_level = 2, color_mode = true, dely = 300, show_nodes = true, - max_nodes = 3, + max_nodes = 2, }, implement = { enable = false, diff --git a/nvim/lua/plugs/mason_lsp.lua b/nvim/lua/plugs/mason_lsp.lua index df337b7..97817d2 100644 --- a/nvim/lua/plugs/mason_lsp.lua +++ b/nvim/lua/plugs/mason_lsp.lua @@ -22,8 +22,8 @@ return { -- Create a new table which contains the non-lsp setups for Mason (linters, formatters, etc) local mason_installs = vim.list_extend({ "clang-format", - --"cmakelang", - --"luaformater", + "cmakelang", + -- "luaformater", }, server_names) require("mason").setup() @@ -38,7 +38,13 @@ return { for _, server_name in ipairs(server_names) do local server = lspconfig[server_name] if server then - server.setup(require("language_servers/" .. server_name)) + local server_table = require("language_servers/" .. server_name) + server.setup(server_table) + + -- Run the post_setup function if it exists + if server_table.post_setup then + server_table.post_setup() + end else error("LSP server not found: " .. server_name) end diff --git a/nvim/lua/plugs/telescope.lua b/nvim/lua/plugs/telescope.lua index ad39f63..9b8d4b6 100644 --- a/nvim/lua/plugs/telescope.lua +++ b/nvim/lua/plugs/telescope.lua @@ -5,37 +5,148 @@ return { "nvim-telescope/telescope-fzf-native.nvim", }, config = function() - require("telescope").setup({ }) + local actions = require("telescope.actions") + require("telescope").setup({ + pickers = { + buffers = { + mappings = { + i = { + [""] = actions.select_drop, + }, + n = { + [""] = actions.select_drop, + } + } + }, + find_files = { + mappings = { + i = { + [""] = actions.select_drop, + }, + n = { + [""] = actions.select_drop, + } + } + }, + git_files = { + mappings = { + i = { + [""] = actions.select_drop, + }, + n = { + [""] = actions.select_drop, + } + } + }, + old_files = { + mappings = { + i = { + [""] = actions.select_drop, + }, + n = { + [""] = actions.select_drop, + } + } + }, + } + }) require("telescope").load_extension("fzf") + local dropdown_theme = require('telescope.themes').get_dropdown({ + -- results_height = 50, + width = 0.2, + winblend = 20, + prompt_title = "", + borderchars = { + { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, + prompt = {"─", "│", " ", "│", '┌', '┐', "│", "│"}, + results = {"─", "│", "─", "│", "├", "┤", "┘", "└"}, + preview = { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, + } + }) + require("utils").add_keymaps({ n = { -- File search ["to"] = { - cmd = ":Telescope find_files ", + cmd = function() + dropdown_theme.prompt_prefix = "Files>" + dropdown_theme.previewer = false + dropdown_theme.find_command = nil + require("telescope.builtin").find_files(dropdown_theme) + end, }, ["tf"] = { - cmd = ":Telescope current_buffer_fuzzy_find", + cmd = function() + dropdown_theme.prompt_prefix = "Find>" + dropdown_theme.previewer = true + dropdown_theme.find_command = nil + require("telescope.builtin").current_buffer_fuzzy_find(dropdown_theme) + end, }, ["ta"] = { - cmd = ":Telescope live_grep find_command=rg,--ignore-file,.gitignore,--exclude,*.git,--exclude,*.svn,--exclude,*.vs,--exclude,*.idea", + -- cmd = ":lua require('telescope.builtin').live_grep({find_command=rg,--ignore-file,.gitignore,--exclude,*.git,--exclude,*.svn,--exclude,*.vs,--exclude,*.idea}) ", + cmd = function() + dropdown_theme.prompt_prefix = "Grep>" + dropdown_theme.previewer = true + dropdown_theme.find_command = { + find_command = "rg", + "--ignore-file", + ".gitignore", + "--exclude", + "*.git", + "--exclude", + "*.svn", + "--exclude", + "*.vs", + "--exclude", + "*.idea", + } + + require("telescope.builtin").live_grep(dropdown_theme) + end, }, -- Git - ["gc"] = { - cmd = " Telescope git_commits ", + ["gl"] = { + cmd = function() + dropdown_theme.prompt_prefix = "Log>" + dropdown_theme.previewer = true + dropdown_theme.find_command = nil + require("telescope.builtin").git_commits(dropdown_theme) + end, }, ["gs"] = { - cmd = " Telescope git_status ", + cmd = function() + dropdown_theme.prompt_prefix = "Status>" + dropdown_theme.previewer = true + dropdown_theme.find_command = nil + require("telescope.builtin").git_status(dropdown_theme) + end, }, ["gh"] = { - cmd = " Telescope git_bcommits ", + cmd = function() + dropdown_theme.prompt_prefix = "History>" + dropdown_theme.previewer = true + dropdown_theme.find_command = nil + require("telescope.builtin").git_bcommits(dropdown_theme) + end, }, ["gb"] = { - cmd = " Telescope git_branches ", + cmd = function() + dropdown_theme.prompt_prefix = "Branches>" + dropdown_theme.previewer = true + dropdown_theme.find_command = nil + require("telescope.builtin").git_branches(dropdown_theme) + end, }, -- Misc ["tb"] = { - cmd = " Telescope marks ", + cmd = function() + dropdown_theme.prompt_prefix = "Marks>" + dropdown_theme.previewer = true + dropdown_theme.find_command = nil + require("telescope.builtin").marks(dropdown_theme) + end, } } }) diff --git a/nvim/lua/plugs/tokyonight.lua b/nvim/lua/plugs/tokyonight.lua index 2fbf35f..4c8fe34 100644 --- a/nvim/lua/plugs/tokyonight.lua +++ b/nvim/lua/plugs/tokyonight.lua @@ -32,34 +32,34 @@ return { ---@param highlights Highlights ---@param colors ColorScheme on_highlights = function(highlights, colors) - local prompt = "#2d3149" - highlights.TelescopeNormal = { - bg = colors.bg_dark, - fg = colors.fg_dark, - } - highlights.TelescopeBorder = { - bg = colors.bg_dark, - fg = colors.bg_dark, - } - highlights.TelescopePromptNormal = { - bg = prompt, - } - highlights.TelescopePromptBorder = { - bg = prompt, - fg = prompt, - } - highlights.TelescopePromptTitle = { - bg = prompt, - fg = prompt, - } - highlights.TelescopePreviewTitle = { - bg = colors.bg_dark, - fg = colors.bg_dark, - } - highlights.TelescopeResultsTitle = { - bg = colors.bg_dark, - fg = colors.bg_dark, - } + -- local prompt = "#2d3149" + -- highlights.TelescopeNormal = { + -- bg = colors.bg_dark, + -- fg = colors.fg_dark, + -- } + -- highlights.TelescopeBorder = { + -- bg = colors.bg_dark, + -- fg = colors.bg_dark, + -- } + -- highlights.TelescopePromptNormal = { + -- bg = prompt, + -- } + -- highlights.TelescopePromptBorder = { + -- bg = prompt, + -- fg = prompt, + -- } + -- highlights.TelescopePromptTitle = { + -- bg = prompt, + -- fg = prompt, + -- } + -- highlights.TelescopePreviewTitle = { + -- bg = colors.bg_dark, + -- fg = colors.bg_dark, + -- } + -- highlights.TelescopeResultsTitle = { + -- bg = colors.bg_dark, + -- fg = colors.bg_dark, + -- } end, })