From ab7ab51ecdf40201d0fe654a9e89ee22036b51bd Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Sat, 1 Jul 2023 15:43:31 -0500 Subject: [PATCH] edited: lsp and telescope keybinding interaction --- lua/huck/map.lua | 73 ++------------------------------------- lua/plugins/lsp.lua | 73 +++++++++++++++++++++++---------------- lua/plugins/telescope.lua | 63 +++++++++++++++++++++++++++++---- 3 files changed, 103 insertions(+), 106 deletions(-) diff --git a/lua/huck/map.lua b/lua/huck/map.lua index 60372a1..cf6cbb1 100644 --- a/lua/huck/map.lua +++ b/lua/huck/map.lua @@ -2,7 +2,8 @@ vim.keymap.set('n', '', '') vim.keymap.set('n', 'j', 'gj') vim.keymap.set('n', 'k', 'gk') -vim.keymap.set('n', 'w', 'za') + +-- center screen after movements vim.keymap.set('n', 'n', 'nzz') vim.keymap.set('n', 'N', 'Nzz') vim.keymap.set('n', '', 'zz') @@ -36,7 +37,7 @@ vim.keymap.set('n', 'K', 'Jx') -- quick config editing vim.keymap.set('n', '=', 'tabnew ~/.config/nvim/init.lua') vim.keymap.set('n', 'q', 'Lazy') -vim.keymap.set('n', 'Q', 'so') +vim.keymap.set('n', 'Q', 'source %') -- better terminal movement keys vim.keymap.set('t', '', [[]]) @@ -45,71 +46,3 @@ vim.keymap.set('t', '', [[]]) -- quickfix navigation vim.keymap.set('n', '', 'cnext') vim.keymap.set('n', '', 'cprev') - --- lsp diagnostics -vim.keymap.set('n', 'n', vim.diagnostic.goto_next) -vim.keymap.set('n', 'p', vim.diagnostic.goto_prev) -vim.keymap.set('n', 'r', vim.lsp.buf.rename) -vim.keymap.set('n', 'a', vim.lsp.buf.code_action) -vim.keymap.set('n', 'k', vim.lsp.buf.hover) -vim.keymap.set('n', 'K', vim.diagnostic.open_float) - --- toggle lsp diagnostics -vim.keymap.set('n', 'd', - function() - if vim.g.visible_diagnostics then - vim.diagnostic.disable() - vim.g.visible_diagnostics = false - else - vim.diagnostic.enable() - vim.g.visible_diagnostics = true - end - end -) - --- live grep in git repo, or fall back to current directory -vim.keymap.set('n', 'F', - function() - local function is_git_repo() - vim.fn.system("git rev-parse --is-inside-work-tree") - - return vim.v.shell_error == 0 - end - - local function get_git_root() - local dot_git_path = vim.fn.finddir(".git", ".;") - return vim.fn.fnamemodify(dot_git_path, ":h") - end - - local opts = {} - - if is_git_repo() then - opts = { - cwd = get_git_root(), - } - end - - require("telescope.builtin").live_grep(opts) - end -) - --- fuzzy search over git files, or fall back to all files -vim.keymap.set('n', 'f', - function() - local function is_git_repo() - vim.fn.system("git rev-parse --is-inside-work-tree") - return vim.v.shell_error == 0 - end - local function get_git_root() - local dot_git_path = vim.fn.finddir(".git", ".;") - return vim.fn.fnamemodify(dot_git_path, ":h") - end - local opts = {} - if is_git_repo() then - opts = { - cwd = get_git_root(), - } - end - require("telescope.builtin").find_files(opts) - end -) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 22ceeae..d620f0b 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,3 +1,37 @@ +local border = { + { "┏", "FloatBorder" }, + { "━", "FloatBorder" }, + { "┓", "FloatBorder" }, + { "┃", "FloatBorder" }, + { "┛", "FloatBorder" }, + { "━", "FloatBorder" }, + { "┗", "FloatBorder" }, + { "┃", "FloatBorder" }, +} + +local keybinds = function() + vim.keymap.set('n', 'n', vim.diagnostic.goto_next) + vim.keymap.set('n', 'p', vim.diagnostic.goto_prev) + vim.keymap.set('n', 'r', vim.lsp.buf.rename) + vim.keymap.set('n', 'a', vim.lsp.buf.code_action) + vim.keymap.set('n', 'k', vim.lsp.buf.hover) + vim.keymap.set('n', 'K', vim.diagnostic.open_float) + vim.keymap.set('n', '', vim.lsp.buf.definition) + + -- toggle lsp diagnostics + vim.keymap.set('n', 'd', + function() + if vim.g.visible_diagnostics then + vim.diagnostic.disable() + vim.g.visible_diagnostics = false + else + vim.diagnostic.enable() + vim.g.visible_diagnostics = true + end + end + ) +end + return { { "jose-elias-alvarez/null-ls.nvim", @@ -78,13 +112,14 @@ return { config = function() -- servers to setup local lsp = require("lspconfig") - lsp.awk_ls.setup({}) - lsp.bashls.setup({}) - lsp.clangd.setup({}) - lsp.cssls.setup({}) - lsp.html.setup({}) - lsp.lua_ls.setup({}) - lsp.solargraph.setup({}) + + lsp.awk_ls.setup({ on_attach = keybinds }) + lsp.bashls.setup({ on_attach = keybinds }) + lsp.clangd.setup({ on_attach = keybinds }) + lsp.cssls.setup({ on_attach = keybinds }) + lsp.html.setup({ on_attach = keybinds }) + lsp.lua_ls.setup({ on_attach = keybinds }) + lsp.solargraph.setup({ on_attach = keybinds }) -- diagnostic settings vim.lsp.diagnostics = { @@ -104,18 +139,6 @@ return { vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end - -- borders on windows - local border = { - { "┏", "FloatBorder" }, - { "━", "FloatBorder" }, - { "┓", "FloatBorder" }, - { "┃", "FloatBorder" }, - { "┛", "FloatBorder" }, - { "━", "FloatBorder" }, - { "┗", "FloatBorder" }, - { "┃", "FloatBorder" }, - } - local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) opts = opts or {} @@ -148,16 +171,7 @@ return { other_hints_prefix = "-> " }, hover_actions = { - border = { - { "┏", "FloatBorder" }, - { "━", "FloatBorder" }, - { "┓", "FloatBorder" }, - { "┃", "FloatBorder" }, - { "┛", "FloatBorder" }, - { "━", "FloatBorder" }, - { "┗", "FloatBorder" }, - { "┃", "FloatBorder" }, - }, + border = border, auto_focus = true } }, @@ -182,6 +196,7 @@ return { } }, on_attach = function(_, bufnr) + keybinds() vim.keymap.set('n', 'k', rust.hover_actions.hover_actions, { buffer = bufnr }) vim.keymap.set('n', 'a', rust.code_action_group.code_action_group, { buffer = bufnr }) vim.keymap.set('n', 'm', rust.expand_macro.expand_macro, { buffer = bufnr }) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 0e9c002..b8f29a5 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -14,8 +14,6 @@ return { { '', 'Telescope current_buffer_fuzzy_find sorting_strategy=ascending' }, { '', 'Telescope command_history' }, { 'b', 'Telescope buffers' }, - { 'l', 'Telescope diagnostics' }, - { 'R', 'Telescope lsp_references' }, { 'tt', 'Telescope resume' }, { 'tc', 'Telescope commands' }, { 'th', 'Telescope help_tags' }, @@ -30,11 +28,13 @@ return { { 'tgb', 'Telescope git_branches' }, { 'tgs', 'Telescope git_status' }, { 'tft', 'Telescope filetypes' }, - { 'tld', 'Telescope lsp_type_definitions' }, - { 'tlt', 'Telescope lsp_definitions' }, - { 'tli', 'Telescope lsp_implementations' }, - { 'tls', 'Telescope lsp_document_symbols' }, - { 'tlS', 'Telescope lsp_workspace_symbols' }, + { 'll', 'Telescope diagnostics' }, + { 'lr', 'Telescope lsp_references' }, + { 'lt', 'Telescope lsp_type_definitions' }, + { 'ld', 'Telescope lsp_definitions' }, + { 'li', 'Telescope lsp_implementations' }, + { 'ls', 'Telescope lsp_document_symbols' }, + { 'lS', 'Telescope lsp_workspace_symbols' }, }, config = function() local actions = require('telescope.actions') @@ -72,6 +72,55 @@ return { require('telescope').load_extension('fzf') + + -- live grep in git repo, or fall back to current directory + vim.keymap.set('n', 'F', + function() + local function is_git_repo() + vim.fn.system("git rev-parse --is-inside-work-tree") + + return vim.v.shell_error == 0 + end + + local function get_git_root() + local dot_git_path = vim.fn.finddir(".git", ".;") + return vim.fn.fnamemodify(dot_git_path, ":h") + end + + local opts = {} + + if is_git_repo() then + opts = { + cwd = get_git_root(), + } + end + + require("telescope.builtin").live_grep(opts) + end + ) + + -- fuzzy search over git files, or fall back to all files + vim.keymap.set('n', 'f', + function() + local function is_git_repo() + vim.fn.system("git rev-parse --is-inside-work-tree") + return vim.v.shell_error == 0 + end + local function get_git_root() + local dot_git_path = vim.fn.finddir(".git", ".;") + return vim.fn.fnamemodify(dot_git_path, ":h") + end + local opts = {} + if is_git_repo() then + opts = { + cwd = get_git_root(), + } + end + require("telescope.builtin").find_files(opts) + end + ) + + -- give telescope window if opened with no command vim.api.nvim_create_autocmd('VimEnter', { pattern = '*', -- 2.45.2