Closed Davincible closed 2 years ago
First if you disabled lsp
diagnostic wont enabled.
The code is this:
if _NgConfigValues.lsp.enable then
require('navigator.diagnostics').config(cfg.lsp.diagnostic)
end
You might need to set it up manually in your config.
Here is an example to use mason (if you want this plugin to setup your lsp) and bypass sumneko_lua setup in navigator. you can try it fo pylsp and other lsp setup
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local Plugin_folder
local plugin_folder = function()
if Plugin_folder then
return Plugin_folder
end
local host = os.getenv("HOST_NAME")
if host and (host:find("Ray") or host:find("ray")) then
Plugin_folder = [[~/github/ray-x/]] -- vim.fn.expand("$HOME") .. '/github/'
else
Plugin_folder = [[ray-x/]]
end
return Plugin_folder
end
local path = plugin_folder()
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
vim.g.coq_settings = {
["auto_start"] = "shut-up",
}
local function load_plugins()
print("load plugins")
-- general setup
require("packer").startup({
function(use)
use("wbthomason/packer.nvim")
use("nvim-lua/plenary.nvim")
use(Plugin_folder .. "aurora")
use({
Plugin_folder .. "navigator.lua",
requires = {
{ "ray-x/guihua.lua", run = "cd lua/fzy && make" },
{ Plugin_folder .. "nvim-lspconfig" },
{ "nvim-treesitter/nvim-treesitter" },
},
config = function()
require("navigator").setup({
debug = true,
lsp_signature_help = true,
lsp = {
disable_lsp = { "sumneko_lua" },
document_highlight = true,
tsserver = {
single_file_support = true,
},
},
})
require("lspconfig").sumneko_lua.setup({
on_attach = function(client, bufnr)
require("navigator.lspclient.mapping").setup({ client = client, bufnr = bufnr })
print(bufnr)
require("navigator.dochighlight").documentHighlight(bufnr)
end,
})
end,
})
end,
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
},
})
end
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system({
"git",
"clone",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
load_plugins()
require("packer").sync()
else
load_plugins()
end
vim.cmd("set termguicolors")
vim.g.aurora_italic = 1
vim.g.aurora_transparent = 1
vim.g.aurora_bold = 1
vim.cmd("set mouse=a")
vim.cmd("colorscheme aurora")
vim.cmd("set updatetime=1")
First if you disabled lsp diagnostic wont enabled.
But why is it overwriting those settings in the first place? If I set lsp.enable = false
I don't expect it to change anything about my current LSP config :)
Thanks for the example.
So I think I managed to get the desired behavior by setting
require("navigator").setup({
mason = true,
default_mapping = false,
lsp = {
enable = true,
disable_lsp = "all",
},
})
I had expected what it is here enable = true
to be default, and disable_lsp = "all" > enable = false
lsp=false was a feature for anyone only use treesitter. In your case you just want navigator bypass the lsp setup.
I found a way to do the following:
Here are the relevant pieces:
Setup navigator with lsp disabled and mason enabled:
require("navigator").setup({
mason = true, -- use mason
default_mapping = false, -- use our own mappings / tell navigator not to define its own mappings
lsp = {
-- Disable all lsp setup including code actions, lens, diagnostics, etc...
-- Set these up via copy/paste functions from ray-x/navigator.lua
-- into my lsp config below
-- some config settings will still be loaded and respected during require("navigator.*").some_fn calls
enable = false, -- Disable LSP setup
disable_lsp = "all", -- Disable LSP configuration
-- configs below here will still be respected/used by navigator
code_action = {
delay = 5000, -- ms
},
diagnostic_scrollbar_sign = false, -- disable scrollbar symbols
tsserver = {
single_file_support = true,
},
format_on_save = {
disable = {
"javascript",
"typescript",
},
},
},
})
Enable/Load diagnostics config:
-- load diagnostics (disabled by lsp.enabled = false)
require('navigator.diagnostics').config({})
Note^: This only needs to be loaded once. You can place this directly after loading navigator.
LSP Attach for configuring various client/bufnr specific configs:
local lsp_attach = function(client, bufnr)
local opts = { buffer = bufnr }
-- enable identifier highlight on hover
require("navigator.dochighlight").documentHighlight(bufnr)
-- configure doc highlight
require("navigator.lspclient.highlight").add_highlight()
-- configure diagnostic highlight
require("navigator.lspclient.highlight").diagnositc_config_sign() -- [sic]
-- init LSP kind info
require('navigator.lspclient.lspkind').init()
-- attach omnifunc
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Setup navigator for lsp client
require("navigator.lspclient.mapping").setup({
client = client,
bufnr = bufnr,
})
-- call to show code actions as floating text and gutter icon
local prompt_code_action = function()
require('navigator.codeAction').code_action_prompt(bufnr)
end
-- ray-x/navigator
-- ref: https://github.com/ray-x/navigator.lua/tree/master#default-keymaps
-- ref: https://github.com/ray-x/navigator.lua/blob/master/lua/navigator/lspclient/mapping.lua
-- must override all default mappings for any of them to work
local keymaps = {
{ mode = 'n', key = 'gr', func = require('navigator.reference').async_ref }, -- show references and context (async)
{ mode = 'n', key = '<c-]>', func = require('navigator.definition').definition }, -- goto definition
{ mode = 'n', key = 'gd', func = require('navigator.definition').definition }, -- goto definition
{ mode = 'n', key = 'gD', func = vim.lsp.buf.declaration }, -- goto declaration
{ mode = 'n', key = '<leader>/', func = require('navigator.workspace').workspace_symbol_live }, -- workspace fzf
{ mode = 'n', key = '<C-S-F>', func = require('navigator.workspace').workspace_symbol_live }, -- workspace fzf
{ mode = 'n', key = 'g0', func = require('navigator.symbols').document_symbols }, -- document's symbols
{ mode = 'n', key = '<leader>d', func = vim.lsp.buf.hover }, -- hover window
{ mode = 'n', key = 'K', func = vim.lsp.buf.hover }, -- hover window
{ mode = 'n', key = 'gi', func = vim.lsp.buf.implementation }, -- goto implementation (doesn't always work?)
{ mode = 'n', key = '<Leader>gi', func = vim.lsp.buf.incoming_calls }, -- incoming calls
{ mode = 'n', key = '<Leader>go', func = vim.lsp.buf.outgoing_calls }, -- outgoing calls
{ mode = 'n', key = 'gt', func = vim.lsp.buf.type_definition }, -- goto type definition
{ mode = 'n', key = 'gp', func = require('navigator.definition').definition_preview }, -- hover definition preview
{ mode = 'n', key = 'gP', func = require('navigator.definition').type_definition_preview }, -- hover type definition preview
-- messes up ctrl-hjkl for moving windows
-- { mode = 'n', key = '<c-k>', func = vim.lsp.buf.signature_help }, -- sig help
{ mode = 'n', key = '<C-S-K>', func = toggle_lsp_signature }, -- sig help
{ mode = 'i', key = '<C-S-K>', func = toggle_lsp_signature }, -- sig help
{ mode = 'n', key = '<leader>ca', func = vim.lsp.buf.code_action }, -- code action
{ mode = 'n', key = '<leader>cl', func = require('navigator.codelens').run_action }, -- codelens action
{ mode = 'n', key = '<leader>la', func = require('navigator.codelens').run_action }, -- codelens action
{ mode = 'n', key = '<leader>rn', func = require('navigator.rename').rename }, -- rename
{ mode = 'n', key = '<leader>gt', func = require('navigator.treesitter').buf_ts }, -- fzf treesitter symbols
{ mode = 'n', key = '<leader>ts', func = require('navigator.treesitter').buf_ts }, -- fzf treesitter symbols
{ mode = 'n', key = '<leader>ct', func = require('navigator.ctags').ctags }, -- fzf ctags
{ mode = 'n', key = '<leader>ca', func = require('navigator.codeAction').code_action }, -- code action
{ mode = 'v', key = '<leader>ca', func = require('navigator.codeAction').range_code_action }, -- code action
{ mode = 'n', key = '<C-S-C>', func = prompt_code_action }, -- prompt for possible code actions
{ mode = 'v', key = '<C-S-C>', func = prompt_code_action }, -- prompt for possible code actions
{ mode = 'n', key = 'gG', func = require('navigator.diagnostics').show_buf_diagnostics }, -- diagnostics
{ mode = 'n', key = '<leader>G', func = require('navigator.diagnostics').show_buf_diagnostics }, -- diagnostics
{ mode = 'n', key = 'gL', func = require('navigator.diagnostics').show_diagnostics }, -- diagnostics
{ mode = 'n', key = '<leader>L', func = require('navigator.diagnostics').show_diagnostics }, -- diagnostics
{ mode = 'n', key = '<leader>cf', func = vim.lsp.buf.format }, -- format code
{ mode = 'v', key = '<leader>cf', func = vim.lsp.buf.range_formatting }, -- format code (visual range)
{ mode = 'n', key = '<leader>fc', func = vim.lsp.buf.format }, -- format code
{ mode = 'v', key = '<leader>fc', func = vim.lsp.buf.range_formatting }, -- format code (visual range)
}
for _, km in pairs(keymaps) do
vim.keymap.set(km.mode, km.key, km.func, opts)
end
end
I hope this helps!
I've just tried installing this plugin, but it doesn't play nice with LSP setup through other plugins, even if I disable everything;
E.g. normally, I get diagnostics like this, but when I have navigator enabled, without any lsp setups, they don't appear:
Also, if I try to do
gd
on something without definition I get this:Instead of just nothing
Config: