my-nvim-lua/lua/custom/plugins/configs/navigator.lua

287 lines
11 KiB
Lua
Raw Normal View History

2022-08-26 14:28:12 +00:00
local present, navigator = pcall(require, "navigator")
2023-08-06 12:15:51 +00:00
2022-08-26 14:28:12 +00:00
if not present then
return
end
2022-08-29 14:46:20 +00:00
M = {}
2023-02-22 18:50:20 +00:00
local get_current_gomod = function()
local file = io.open('go.mod', 'r')
if file == nil then
return nil
end
local first_line = file:read()
local mod_name = first_line:gsub('module ', '')
file:close()
return mod_name
end
2023-08-06 12:15:51 +00:00
-- default config
-- "~/.local/share/nvim/site/pack/packer/opt/navigator.lua/lua/navigator.lua"
2022-08-26 14:28:12 +00:00
local config = {
2022-09-29 18:49:40 +00:00
debug = false,
2022-08-29 14:46:20 +00:00
transparency = 5,
lsp_signature_help = false, -- needs plugin lsp_signature
2022-09-25 03:03:21 +00:00
default_mapping = false,
on_attach = require('plugins.configs.lspconfig').on_attach,
keymaps = {
{ key = 'gr', func = require('navigator.reference').async_ref, desc = 'lsp async_ref' },
2022-10-25 00:13:21 +00:00
-- { key = '<Leader>gr', func = require('navigator.reference').reference, desc = 'lsp reference' }, -- reference deprecated
2022-09-23 00:50:02 +00:00
-- { key = '<C-i>', func = vim.lsp.buf.signature_help, desc = 'lsp signature_help' },
{ key = 'g0', func = require('navigator.symbols').document_symbols, desc = 'lsp document_symbols' },
{ key = 'gW', func = require('navigator.workspace').workspace_symbol_live, desc = 'lsp workspace_symbol_live' },
{ key = '<c-]>', func = require('navigator.definition').definition, desc = 'lsp definition' },
{ key = 'gd', func = require('navigator.definition').definition, desc = 'lsp definition' },
2023-08-06 12:15:51 +00:00
{ key = 'gp', func = require('navigator.definition').definition_preview, desc = 'lsp definition preview' },
{ key = 'gP', func = require('navigator.definition').type_definition_preview, desc = 'lsp type definition preview' },
2023-01-28 03:01:20 +00:00
-- handled by main mappings
-- { key = '<Leader>gt', func = require('navigator.treesitter').buf_ts, desc = 'lsp buf_ts' },
-- { key = '<Leader>gT', func = require('navigator.treesitter').bufs_ts, desc = 'lsp bufs_ts' },
-- { key = '<Leader>ct', func = require('navigator.ctags').ctags, desc = 'lsp ctags' },
-- handled by main mappings (lspconfig section)
-- { key = 'gD', func = vim.lsp.buf.declaration, desc = 'lsp declaration' },
-- {
-- key = '<M-i>',
-- mode = 'i',
-- func = vim.lsp.buf.signature_help,
-- desc = 'lsp signature_help'
-- },
-- { key = 'K', func = vim.lsp.buf.hover, desc = 'lsp hover' },
-- { key = '<Leader>gm', func = vim.lsp.buf.implementation, desc = 'lsp implementation' },
-- { key = '<Space>D', func = vim.lsp.buf.type_definition, desc = 'lsp type_definition' },
-- { key = ']d', func = vim.diagnostic.goto_next, desc = 'lsp next diagnostics' },
-- { key = '[d', func = vim.diagnostic.goto_prev, desc = 'lsp prev diagnostics' },
-- { key = ']O', func = vim.diagnostic.setloclist, desc = 'lsp diagnostics set loclist' },
-- { key = '<space>fm', func = vim.lsp.buf.format, mode = 'n', desc = 'lsp format' },
-- { key = '<Leader>gi', func = vim.lsp.buf.incoming_calls, desc = 'lsp incoming_calls' },
-- { key = '<Leader>go', func = vim.lsp.buf.outgoing_calls, desc = 'lsp outgoing_calls' },
-- { key = '<C-LeftMouse>', func = vim.lsp.buf.definition, desc = 'lsp definition' },
-- { key = 'g<LeftMouse>', func = vim.lsp.buf.implementation, desc = 'lsp implementation' },
2022-10-09 02:51:47 +00:00
{ key = '<M-a>', mode = 'n', func = require('navigator.codeAction').code_action, desc = 'lsp code_action' },
2022-10-16 23:50:45 +00:00
{ key = '<M-a>', mode = 'i', func = require('navigator.codeAction').code_action, desc = 'lsp code_action' },
{ key = '<BS><Right>', mode = 'n', func = require('navigator.symbols').side_panel, desc = 'toggle lsp outline pannel'},
{
2022-10-09 02:51:47 +00:00
key = '<M-a>',
mode = 'v',
func = require('navigator.codeAction').range_code_action,
desc = 'lsp range_code_action',
},
-- { key = '<Leader>re', func = 'rename()' },
{ key = '<Space>rn', func = require('navigator.rename').rename, desc = 'lsp rename' },
{ key = 'gL', func = require('navigator.diagnostics').show_diagnostics, desc = 'lsp show_diagnostics' },
{ key = 'gG', func = require('navigator.diagnostics').show_buf_diagnostics, desc = 'lsp show_buf_diagnostics' },
2023-01-28 03:01:20 +00:00
-- { key = '<Leader>dt', func = require('navigator.diagnostics').toggle_diagnostics, desc = 'lsp toggle_diagnostics' },
-- { key = '<Leader>td', func = require('spike.diagnostics').toggle, desc = 'lsp toggle_diagnostics' },
{ key = ']r', func = require('navigator.treesitter').goto_next_usage, desc = 'lsp goto_next_usage' },
{ key = '[r', func = require('navigator.treesitter').goto_previous_usage, desc = 'lsp goto_previous_usage' },
{ key = '<Leader>k', func = require('navigator.dochighlight').hi_symbol, desc = 'lsp hi_symbol' },
{ key = '<leader>wa', func = require('navigator.workspace').add_workspace_folder, desc = 'lsp add_workspace_folder' },
{
key = '<leader>wr',
func = require('navigator.workspace').remove_workspace_folder,
desc = 'lsp lsp remove_workspace_folder',
},
2022-09-25 03:03:21 +00:00
-- { key = '<Space>ff', func = vim.lsp.buf.range_formatting, mode = 'v', desc = 'lsp range format' },
-- DEPRECATED
-- {
-- key = '<Space>gm',
-- func = require('navigator.formatting').range_format,
-- mode = 'n',
-- desc = 'lsp range format operator e.g gmip',
-- },
{ key = '<leader>wl', func = require('navigator.workspace').list_workspace_folders, desc = 'lsp list_workspace_folders' },
{ key = '<leader>ll', mode = 'n', func = require('navigator.codelens').run_action, desc = 'lsp run code lens action' },
},
2022-08-29 14:46:20 +00:00
icons = {
icons = true, -- set to false to use system default ( if you using a terminal does not have nerd/icon)
-- Code action
2023-08-06 12:15:51 +00:00
code_action_icon = '', -- "",
2022-08-29 14:46:20 +00:00
-- code lens
code_lens_action_icon = '',
2022-08-29 14:46:20 +00:00
-- Diagnostics
2022-08-29 14:46:20 +00:00
diagnostic_head = '', -- default diagnostic head on dialogs
2023-08-07 12:40:31 +00:00
diagnostic_err = '', -- severity 1
2022-08-29 14:46:20 +00:00
diagnostic_warn = '', -- 2
2023-08-06 12:15:51 +00:00
diagnostic_info = '', -- 3
2022-08-29 14:46:20 +00:00
diagnostic_hint = '', -- 4
2022-08-29 14:46:20 +00:00
-- used in the diagnostics summary window
diagnostic_head_severity_1 = '',
diagnostic_head_severity_2 = '',
diagnostic_head_severity_3 = 'i',
diagnostic_head_description = ' ',
diagnostic_virtual_text = '',
2023-08-06 12:15:51 +00:00
diagnostic_file = '',
2023-07-31 16:39:56 +00:00
-- Values
2023-07-31 16:39:56 +00:00
--
2022-10-09 19:18:15 +00:00
value_changed = '',
2023-07-31 16:39:56 +00:00
value_definition = ':', -- it is easier to see than 🦕
side_panel = {
section_separator = '',
line_num_left = '',
line_num_right = '',
inner_node = '├○',
outer_node = '╰○',
bracket_left = '',
bracket_right = '',
},
-- Treesitter
match_kinds = {
2023-07-31 16:39:56 +00:00
var = '',
method = 'ƒ ',
['function'] = '',
parameter = '',
2022-10-09 19:18:15 +00:00
associated = '',
namespace = '',
type = '',
2022-10-09 19:18:15 +00:00
field = '',
module = '',
flag = '',
},
2023-08-06 12:15:51 +00:00
treesitter_defult = '',
doc_symbols = '',
},
2022-09-23 00:50:02 +00:00
mason = true,
mason_disabled_for = {"ccls"}, -- disable mason for specified lspclients
2022-08-26 14:28:12 +00:00
lsp = {
document_highlight = false,
format_on_save = false, -- applies to all formatting feature of neovim
-- including auto-fold
2022-08-29 14:46:20 +00:00
diagnostic = {
underline = true,
virtual_text = {
spacing = 3,
source = true
}, -- show virtual for diagnostic message
update_in_insert = false, -- update diagnostic message in insert mode
2022-11-05 18:46:15 +00:00
severity_sort = { reverse = false },
2022-08-29 14:46:20 +00:00
},
2023-08-06 12:15:51 +00:00
code_action = {
delay = 5000, -- 5 sec delay
virtual_text_icon = false,
},
diagnostic_scrollbar_sign = false,
2023-04-29 18:38:10 +00:00
display_diagnostic_qf = false,
2022-10-10 22:12:27 +00:00
disable_lsp = {"clangd", "rust_analyzer"},
2022-08-29 14:46:20 +00:00
-- disable auto start of lsp per language
-- set global default on lspconfig (see lspconfig doc)
gopls = {
2022-12-05 13:44:06 +00:00
-- cmd = { "nc", "localhost", "9999" },
2022-11-13 17:34:52 +00:00
-- cmd = {"socat", "-" ,"tcp:localhost:4444"},
2022-09-29 18:49:40 +00:00
-- on_attach = require("spike.lsp.go").custom_attach,
on_attach = require("spike.lsp.go").gopls_onattach,
settings = {
2023-02-22 18:50:20 +00:00
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
gopls = {
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
analyses = {
unreachable = true,
nilness = true,
unusedparams = true,
useany = true,
unusedwrite = true,
ST1003 = true,
undeclaredname = true,
fillreturns = true,
nonewvars = true,
fieldalignment = false,
shadow = true,
},
codelenses = {
generate = true, -- show the `go generate` lens.
gc_details = true, -- Show a code lens toggling the display of gc's choices.
test = true,
tidy = true,
vendor = true,
regenerate_cgo = true,
upgrade_dependency = true,
},
usePlaceholders = true,
completeUnimported = true,
staticcheck = true,
matcher = 'Fuzzy',
diagnosticsDelay = '500ms',
symbolMatcher = 'fuzzy',
['local'] = get_current_gomod(),
-- gofumpt = _GO_NVIM_CFG.lsp_gofumpt or false, -- true|false, -- turn on for new repos, gofmpt is good but also create code turmoils
buildFlags = { '-tags', 'integration' },
}
}
},
2023-02-07 18:55:59 +00:00
pylsp = {
settings = {
pylsp = {
plugins = {
2023-04-29 18:38:10 +00:00
black = { enabled = true},
2023-02-07 18:55:59 +00:00
autopep8 = { enabled = false },
-- pylint = { enabled = false }, -- disabled in null-ls
2023-02-07 18:55:59 +00:00
flake8 = { enabled = false },
mccabe = { enabled = false },
2023-02-07 18:55:59 +00:00
pycodestyle= { enabled = false},
pyflakes = { enabled = false },
}
}
}
},
2023-04-09 23:23:49 +00:00
lua_ls = {
2023-01-30 21:14:14 +00:00
before_init=require("neodev.lsp").before_init,
}
2023-01-28 03:01:20 +00:00
-- FIX: deperecated https://github.com/ray-x/navigator.lua/commit/1b2a0856f4adfffc5c4e785a6779c62759c8c926
2023-01-30 21:14:14 +00:00
-- ["neodev"] = {
-- library = {
-- enabled = true,
-- runtime = true,
-- -- plugins = true,
-- plugins = {"plenary.nvim"},
-- -- plugins = {"navigator.lua", "guihua.lua", "go.nvim", "plenary.nvim"},
-- types = true,
-- },
-- setup_jsonls = true,
-- },
2022-08-26 14:28:12 +00:00
}
}
2022-08-29 14:46:20 +00:00
M.setup = function()
navigator.setup(config)
end
-- make sure LSP is not started automatically
-- TODO: how to it per project basis
-- M.enable = function()
-- local lspconfig = require("lspconfig")
-- lspconfig.util.default_config = vim.tbl_extend(
-- "force",
-- lspconfig.util.default_config,
-- {
-- autostart = true
-- }
-- )
-- vim.cmd[[
-- LspStart
-- ]]
-- end
2022-08-29 14:46:20 +00:00
return M