#195 update doc for rust-tool, make client/bufnr require fields for mapping.setup(opts) when calling from rust/clangd on_attach

neovim_0.6^2
ray-x 2 years ago
parent edba3efd1e
commit 22e858f261

@ -618,8 +618,8 @@ require'navigator'.setup({
require('rust-tools').setup({ require('rust-tools').setup({
server = { server = {
on_attach = function(_, _) on_attach = function(client, bufnr)
require('navigator.lspclient.mapping').setup() -- setup navigator keymaps here, require('navigator.lspclient.mapping').setup({client=client, bufnr=bufnr}) -- setup navigator keymaps here,
-- otherwise, you can define your own commands to call navigator functions -- otherwise, you can define your own commands to call navigator functions
end, end,
} }
@ -627,8 +627,8 @@ require('rust-tools').setup({
require("clangd_extensions").setup { require("clangd_extensions").setup {
server = { server = {
on_attach = function(_, _) on_attach = function(client, bufnr)
require('navigator.lspclient.mapping').setup() -- setup navigator keymaps here, require('navigator.lspclient.mapping').setup({client=client, bufnr=bufnr}) -- setup navigator keymaps here,
-- otherwise, you can define your own commands to call navigator functions -- otherwise, you can define your own commands to call navigator functions
end, end,
} }

@ -1,7 +1,6 @@
local util = require('navigator.util') local util = require('navigator.util')
local log = util.log local log = util.log
local trace = util.trace local trace = util.trace
local event_hdlrs = { local event_hdlrs = {
{ ev = 'BufWritePre', func = [[require "navigator.diagnostics".set_diag_loclist()]] }, { ev = 'BufWritePre', func = [[require "navigator.diagnostics".set_diag_loclist()]] },
{ ev = 'CursorHold', func = 'document_highlight()' }, { ev = 'CursorHold', func = 'document_highlight()' },
@ -122,12 +121,17 @@ local function set_cmds(_)
end end
end end
local function set_mapping(lsp_info) -- should works for both 1)attach from known lsp client or from a disabled lsp client
local function set_mapping(lsp_attach_info)
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
lsp_info = lsp_info or {} vim.validate({
log('setup mapping', lsp_info.client.name, lsp_info.client.cmd) lsp_attach_info = { lsp_attach_info, 'table' },
})
if _NgConfigValues.debug then
log('setup mapping for client', lsp_attach_info.client.name, lsp_attach_info.client.cmd)
end
local user_key = _NgConfigValues.keymaps or {} local user_key = _NgConfigValues.keymaps or {}
local bufnr = lsp_info.bufnr or 0 local bufnr = lsp_attach_info.bufnr or 0
local function del_keymap(...) local function del_keymap(...)
vim.api.nvim_buf_del_keymap(bufnr, ...) vim.api.nvim_buf_del_keymap(bufnr, ...)
@ -139,7 +143,7 @@ local function set_mapping(lsp_info)
-- local function buf_set_option(...) -- local function buf_set_option(...)
-- vim.api.nvim_buf_set_option(bufnr, ...) -- vim.api.nvim_buf_set_option(bufnr, ...)
-- end -- end
local doc_fmt, range_fmt, ccls = check_cap(lsp_info) local doc_fmt, range_fmt, ccls = check_cap(lsp_attach_info)
if ccls then if ccls then
vim.list_extend(key_maps, ccls_mappings) vim.list_extend(key_maps, ccls_mappings)
@ -203,8 +207,8 @@ local function set_mapping(lsp_info)
del_keymap('n', fmtkey) del_keymap('n', fmtkey)
end end
if lsp_info.cap and lsp_info.cap.document_range_formatting then if lsp_attach_info.cap and lsp_attach_info.cap.document_range_formatting then
log('formatting enabled', lsp_info.cap) log('formatting enabled', lsp_attach_info.cap)
end end
if not range_fmt and rfmtkey then if not range_fmt and rfmtkey then
@ -271,15 +275,21 @@ M.toggle_lspformat = function(on)
end end
end end
function M.setup(user_opts) function M.setup(attach_opts)
user_opts = user_opts or _NgConfigValues if not attach_opts or not attach_opts.client then
set_mapping(user_opts) vim.notify(
set_cmds(user_opts) 'please call require"navigator.mapping".setup({bufnr=bufnr, client=client}) inside on_attach(client,bufnr)',
vim.lsp.log_levels.WARN
)
end
attach_opts = attach_opts or { bufnr = 0, client = {}, cap = {} }
set_mapping(attach_opts)
set_cmds(attach_opts)
autocmd() autocmd()
set_event_handler(user_opts) set_event_handler(attach_opts)
local client = user_opts.client or {} local client = attach_opts.client or {}
local cap = client.server_capabilities or vim.lsp.protocol.make_client_capabilities() local cap = client.server_capabilities or vim.lsp.protocol.make_client_capabilities()
log('lsp cap:', cap.codeActionProvider) log('lsp cap:', cap.codeActionProvider)

@ -42,7 +42,7 @@ local function load_plugins()
use({ 'ray-x/aurora' }) use({ 'ray-x/aurora' })
use({ use({
'ray-x/navigator.lua', 'ray-x/navigator.lua',
-- '~/github/navigator.lua', -- '~/github/ray-x/navigator.lua',
requires = { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' }, requires = { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' },
config = function() config = function()
require('navigator').setup({ require('navigator').setup({

Loading…
Cancel
Save