Add Trouble setup file

Replace keymaps for common LSP functions with the Trouble
equivalent
This commit is contained in:
Evie Litherland-Smith 2022-11-15 13:33:09 +00:00
parent 4b68cc887c
commit 29e1efe9e3
4 changed files with 66 additions and 14 deletions

View file

@ -6,6 +6,12 @@ vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, opts)
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
@ -15,10 +21,13 @@ local on_attach = function(client, bufnr)
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'gD', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'gd', '<cmd>TroubleToggle lsp_definitions<cr>', bufopts)
vim.keymap.set('n', 'gR', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', 'gr', '<cmd>TroubleToggle lsp_references<cr>', bufopts)
vim.keymap.set('n', 'gI', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', 'gi', '<cmd>TroubleToggle lsp_implementations<cr>', bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
-- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
@ -28,7 +37,6 @@ local on_attach = function(client, bufnr)
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
-- Keep support for deprecated syntax in vim <= 7
if vim.version().minor <= 7 then
vim.keymap.set('n', '<leader>i', function()

View file

@ -0,0 +1,47 @@
require('trouble').setup {
position = "bottom", -- position of the list can be: bottom, top, left, right
height = 10, -- height of the trouble list when position is top or bottom
width = 50, -- width of the list when position is left or right
icons = true, -- use devicons for filenames
mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist"
fold_open = "", -- icon used for open folds
fold_closed = "", -- icon used for closed folds
group = true, -- group results by file
padding = true, -- add an extra new line on top of the list
action_keys = { -- key mappings for actions in the trouble list
-- map to {} to remove a mapping, for example:
-- close = {},
close = "q", -- close the list
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
refresh = "r", -- manually refresh
jump = { "<cr>", "<tab>" }, -- jump to the diagnostic or open / close folds
open_split = { "<c-x>" }, -- open buffer in new split
open_vsplit = { "<c-v>" }, -- open buffer in new vsplit
open_tab = { "<c-t>" }, -- open buffer in new tab
jump_close = { "o" }, -- jump to the diagnostic and close the list
toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode
toggle_preview = "P", -- toggle auto_preview
hover = "K", -- opens a small popup with the full multiline message
preview = "p", -- preview the diagnostic location
close_folds = { "zM", "zm" }, -- close all folds
open_folds = { "zR", "zr" }, -- open all folds
toggle_fold = { "zA", "za" }, -- toggle fold of current file
previous = "k", -- previous item
next = "j" -- next item
},
indent_lines = true, -- add an indent guide below the fold icons
auto_open = false, -- automatically open the list when you have diagnostics
auto_close = true, -- automatically close the list when you have no diagnostics
auto_preview = false, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window
auto_fold = true, -- automatically fold a file trouble list at creation
auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result
signs = {
-- icons / text used for a diagnostic
error = "",
warning = "",
hint = "",
information = "",
other = ""
},
use_diagnostic_signs = false, -- enabling this will use the signs defined in your lsp client
}

View file

@ -29,7 +29,7 @@ nmap('<leader>fe', '<cmd>Telescope diagnostics<cr>')
nmap('<leader>fn', '<cmd>Telescope notify<cr>')
nmap('<leader>ft', '<cmd>Telescope treesitter<cr>')
nmap('<leader>fz', '<cmd>Telescope current_buffer_fuzzy_find<cr>')
nmap('<leader>fg', '<cmd>Telescope live_grep<cr>')
nmap('<leader>fg', '<cmd>Telescope git_status<cr>')
-- Hop
nmap('<leader>hl', '<cmd>HopLine<cr>')
@ -40,14 +40,11 @@ nmap('<leader>nt', '<cmd>NvimTreeToggle<cr>')
nmap('<leader>nf', '<cmd>NvimTreeFindFile<cr>')
-- Trouble
nmap('<leader>tq', '<cmd>TroubleToggle quickfix<cr>')
nmap('<leader>tl', '<cmd>TroubleToggle loclist<cr>')
nmap('<leader>tr', '<cmd>TroubleToggle lsp_references<cr>')
nmap('<leader>td', '<cmd>TroubleToggle lsp_definitions<cr>')
nmap('<leader>tt', '<cmd>TroubleToggle lsp_type_definitions<cr>')
nmap('<leader>ti', '<cmd>TroubleToggle lsp_implementations<cr>')
nmap('<leader>tdd', '<cmd>TroubleToggle document_diagnostics<cr>')
nmap('<leader>twd', '<cmd>TroubleToggle workspace_diagnostics<cr>')
nmap('<leader>xx', '<cmd>TroubleToggle<cr>')
nmap('<leader>xw', '<cmd>TroubleToggle workspace_diagnostics<cr>')
nmap('<leader>xd', '<cmd>TroubleToggle document_diagnostics<cr>')
nmap('<leader>xq', '<cmd>TroubleToggle quickfix<cr>')
nmap('<leader>xl', '<cmd>TroubleToggle loclist<cr>')
-- SnipRun
nmap('<leader>srs', '<cmd>SnipRun<cr>')

View file

@ -115,7 +115,7 @@ require('packer').startup {
use {
'folke/trouble.nvim',
config = function()
require('trouble').setup()
require 'config_plugins.config_trouble'
end
}
use {