lint all codes

neovim_0.6^2
ray-x 2 years ago
parent 32ddd66dd2
commit 3f49769abc

@ -118,7 +118,6 @@ vim.cmd("command! -nargs=0 LspToggleFmt lua require'navigator.lspclient.mapping'
vim.cmd("command! -nargs=0 LspKeymaps lua require'navigator.lspclient.mapping'.get_keymaps_help()<CR>") vim.cmd("command! -nargs=0 LspKeymaps lua require'navigator.lspclient.mapping'.get_keymaps_help()<CR>")
M.deprecated = function(cfg) M.deprecated = function(cfg)
local warn = require('navigator.util').warn
if cfg.code_action_prompt then if cfg.code_action_prompt then
warn('code_action_prompt moved to lsp.code_action') warn('code_action_prompt moved to lsp.code_action')
end end

@ -51,7 +51,7 @@ end
local call_hierarchy_handler_from = partial(call_hierarchy_handler, 'from') local call_hierarchy_handler_from = partial(call_hierarchy_handler, 'from')
local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to') local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to')
local function incoming_calls_handler(bang, err, result, ctx, cfg) local function incoming_calls_handler(_, err, result, ctx, cfg)
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags') assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags')
@ -61,7 +61,7 @@ local function incoming_calls_handler(bang, err, result, ctx, cfg)
gui.new_list_view({ items = results, ft = ft or 'cpp', api = '' }) gui.new_list_view({ items = results, ft = ft or 'cpp', api = '' })
end end
-- err, method, result, client_id, bufnr -- err, method, result, client_id, bufnr
local function outgoing_calls_handler(bang, err, result, ctx, cfg) local function outgoing_calls_handler(_, err, result, ctx, cfg)
local results = call_hierarchy_handler_to(err, result, ctx, cfg, 'Outgoing calls not found') local results = call_hierarchy_handler_to(err, result, ctx, cfg, 'Outgoing calls not found')
local ft = vim.api.nvim_buf_get_option(ctx.bufnr or 0, 'ft') local ft = vim.api.nvim_buf_get_option(ctx.bufnr or 0, 'ft')

@ -2,7 +2,7 @@ local util = require('navigator.util')
local log = util.log local log = util.log
local trace = util.trace local trace = util.trace
local code_action = {} local code_action = {}
local gui = require('navigator.gui') -- local gui = require('navigator.gui')
local config = require('navigator').config_values() local config = require('navigator').config_values()
local api = vim.api local api = vim.api

@ -8,7 +8,6 @@ local trace = require('navigator.util').trace
local lsphelper = require('navigator.lspwrapper') local lsphelper = require('navigator.lspwrapper')
local api = vim.api local api = vim.api
local gui = require('navigator.gui')
local M = {} local M = {}
local config = require('navigator').config_values() local config = require('navigator').config_values()

@ -85,6 +85,9 @@ local function def_preview(timeout_ms)
local ts = require('navigator.treesitter') local ts = require('navigator.treesitter')
local root = parsers.get_parser(bufnr) local root = parsers.get_parser(bufnr)
log(range) log(range)
if ts == nil then
return
end
local def_node = ts.get_node_at_pos({ range['start'].line, range['start'].character }, root) local def_node = ts.get_node_at_pos({ range['start'].line, range['start'].character }, root)
local sr, _, er, _ = ts.get_node_scope(def_node) local sr, _, er, _ = ts.get_node_scope(def_node)
@ -105,7 +108,7 @@ local function def_preview(timeout_ms)
end end
local width = 40 local width = 40
local maxwidth = math.floor(vim.fn.winwidth(0) * 4 / 5) local maxwidth = math.floor(vim.fn.winwidth(0) * 4 / 5)
for key, value in pairs(definition) do for _, value in pairs(definition) do
-- log(key, value, width) -- log(key, value, width)
width = math.max(width, #value + 4) width = math.max(width, #value + 4)
width = math.min(maxwidth, width) width = math.min(maxwidth, width)
@ -143,7 +146,7 @@ local def = function()
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local ref_params = vim.lsp.util.make_position_params() local ref_params = vim.lsp.util.make_position_params()
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) vim.lsp.for_each_buffer_client(bufnr, function(client, _, _bufnr)
-- if client.resolved_capabilities.goto_definition then -- if client.resolved_capabilities.goto_definition then
if client.server_capabilities.definitionProvider then if client.server_capabilities.definitionProvider then
client.request('textDocument/definition', ref_params, definition_hdlr, _bufnr) client.request('textDocument/definition', ref_params, definition_hdlr, _bufnr)

@ -306,10 +306,10 @@ local diag_hdlr = function(err, result, ctx, config)
end end
end end
local diag_hdlr_async = function() -- local diag_hdlr_async = function()
local debounce = require('navigator.debounce').debounce_trailing -- local debounce = require('navigator.debounce').debounce_trailing
return debounce(100, diag_hdlr) -- return debounce(100, diag_hdlr)
end -- end
local M = {} local M = {}
@ -368,6 +368,9 @@ M.show_buf_diagnostics = function()
api = _NgConfigValues.icons.diagnostic_file .. _NgConfigValues.icons.diagnostic_head .. ' Diagnostic ', api = _NgConfigValues.icons.diagnostic_file .. _NgConfigValues.icons.diagnostic_head .. ' Diagnostic ',
enable_preview_edit = true, enable_preview_edit = true,
}) })
if listview == nil then
return log("nil listview")
end
trace('new buffer', listview.bufnr) trace('new buffer', listview.bufnr)
if listview.bufnr then if listview.bufnr then
vim.api.nvim_buf_add_highlight(listview.bufnr, -1, 'Title', 0, 0, -1) vim.api.nvim_buf_add_highlight(listview.bufnr, -1, 'Title', 0, 0, -1)

@ -205,10 +205,10 @@ local function cmd_nohl()
end end
end end
_G.nav_doc_hl = function() local nav_doc_hl = function()
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local ref_params = vim.lsp.util.make_position_params() local ref_params = vim.lsp.util.make_position_params()
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, bufnr) vim.lsp.for_each_buffer_client(bufnr, function(client, _, _)
if client.server_capabilities.documentHighlightProvider == true then if client.server_capabilities.documentHighlightProvider == true then
client.request('textDocument/documentHighlight', ref_params, handle_document_highlight, bufnr) client.request('textDocument/documentHighlight', ref_params, handle_document_highlight, bufnr)
end end
@ -220,7 +220,7 @@ local function documentHighlight()
[[ [[
augroup lsp_document_highlight augroup lsp_document_highlight
autocmd! * <buffer> autocmd! * <buffer>
autocmd CursorHold,CursorHoldI <buffer> lua nav_doc_hl() autocmd CursorHold,CursorHoldI <buffer> lua require('navigator.dochighlight').nav_doc_hl()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END augroup END
]], ]],
@ -258,5 +258,6 @@ return {
handle_document_highlight = handle_document_highlight, handle_document_highlight = handle_document_highlight,
hi_symbol = hi_symbol, hi_symbol = hi_symbol,
nohl = nohl, nohl = nohl,
nav_doc_hl = nav_doc_hl,
cmd_nohl = cmd_nohl, cmd_nohl = cmd_nohl,
} }

@ -87,7 +87,7 @@ function M.debug_folds()
end end
end end
M.fold_handler = function(err, result, ctx, config) M.fold_handler = function(err, result, ctx, _)
-- params: err, method, result, client_id, bufnr -- params: err, method, result, client_id, bufnr
-- XXX: handle err? -- XXX: handle err?
if err or result == nil or #result == 0 then if err or result == nil or #result == 0 then

@ -17,14 +17,14 @@ function M.on_attach()
-- M.update_folds() -- M.update_folds()
end end
function _G.custom_fold_text() function Custom_fold_text()
local line = vim.fn.getline(vim.v.foldstart) local line = vim.fn.getline(vim.v.foldstart)
local line_count = vim.v.foldend - vim.v.foldstart + 1 local line_count = vim.v.foldend - vim.v.foldstart + 1
-- log("" .. line .. " // " .. line_count .. " lines") -- log("" .. line .. " // " .. line_count .. " lines")
return '' .. line .. ': ' .. line_count .. ' lines' return '' .. line .. ': ' .. line_count .. ' lines'
end end
vim.opt.foldtext = _G.custom_fold_text() vim.opt.foldtext = Custom_fold_text()
vim.opt.fillchars = { eob = '-', fold = ' ' } vim.opt.fillchars = { eob = '-', fold = ' ' }

@ -1,7 +1,7 @@
-- https://github.com/wention/dotfiles/blob/master/.config/nvim/lua/config/lsp.lua -- https://github.com/wention/dotfiles/blob/master/.config/nvim/lua/config/lsp.lua
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/handlers.lua -- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/handlers.lua
return { return {
format_hdl = function(err, result, ctx, cfg) -- FIXME: bufnr is nil format_hdl = function(err, result, ctx, _) -- FIXME: bufnr is nil
if err ~= nil or result == nil then if err ~= nil or result == nil then
return return
end end

@ -8,7 +8,7 @@ local api = vim.api
local active_list_view -- only one listview at a time local active_list_view -- only one listview at a time
function M.new_list_view(opts) function M.new_list_view(opts)
log(opts) -- log(opts)
local config = require('navigator').config_values() local config = require('navigator').config_values()
if active_list_view ~= nil then if active_list_view ~= nil then
@ -36,6 +36,9 @@ function M.new_list_view(opts)
opts.data = require('navigator.render').prepare_for_render(items, opts) opts.data = require('navigator.render').prepare_for_render(items, opts)
end end
opts.border = _NgConfigValues.border or 'shadow' opts.border = _NgConfigValues.border or 'shadow'
if vim.fn.hlID('TelescopePromptBorder') > 0 then
opts.border_hl = 'TelescopePromptBorder'
end
if not items or vim.tbl_isempty(items) then if not items or vim.tbl_isempty(items) then
log('empty data return') log('empty data return')
return return
@ -48,7 +51,7 @@ function M.new_list_view(opts)
opts.external = _NgConfigValues.external opts.external = _NgConfigValues.external
opts.preview_lines_before = 3 opts.preview_lines_before = 3
trace(opts) log(opts)
active_list_view = require('guihua.gui').new_list_view(opts) active_list_view = require('guihua.gui').new_list_view(opts)
return active_list_view return active_list_view
end end

@ -9,7 +9,7 @@ local path_sep = require('navigator.util').path_sep()
local path_cur = require('navigator.util').path_cur() local path_cur = require('navigator.util').path_cur()
local cwd = vim.loop.cwd() local cwd = vim.loop.cwd()
local M = {} local M = {}
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message) local function call_hierarchy_handler(direction, err, result, ctx, _, error_message)
if not result then if not result then
vim.notify('No call hierarchy items found', vim.lsp.log_levels.WARN) vim.notify('No call hierarchy items found', vim.lsp.log_levels.WARN)
return return
@ -33,11 +33,11 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
kind = require('navigator.lspclient.lspkind').symbol_kind(call_hierarchy_item.kind) .. ' ' kind = require('navigator.lspclient.lspkind').symbol_kind(call_hierarchy_item.kind) .. ' '
end end
-- for _, range in pairs(call_hierarchy_call.fromRanges) do -- for _, range in pairs(call_hierarchy_call.fromRanges) do
range = call_hierarchy_item.range or call_hierarchy_item.selectionRange local range = call_hierarchy_item.range or call_hierarchy_item.selectionRange
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri)) local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1) local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
call_hierarchy_item.detail = call_hierarchy_item.detail or '' call_hierarchy_item.detail = call_hierarchy_item.detail or ''
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub('\n', '') call_hierarchy_item.detail = string.gsub(call_hierarchy_item.detail, '\n', '')
trace(range, call_hierarchy_item) trace(range, call_hierarchy_item)
local disp_item = { local disp_item = {
@ -59,7 +59,8 @@ end
local call_hierarchy_handler_from = partial(call_hierarchy_handler, 'from') local call_hierarchy_handler_from = partial(call_hierarchy_handler, 'from')
local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to') local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to')
local function incoming_calls_handler(bang, err, result, ctx, cfg) -- local function incoming_calls_handler(bang, err, result, ctx, cfg)
local function incoming_calls_handler(_, err, result, ctx, cfg)
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp hierarchy') assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp hierarchy')
local results = call_hierarchy_handler_from(err, result, ctx, cfg, 'Incoming calls not found') local results = call_hierarchy_handler_from(err, result, ctx, cfg, 'Incoming calls not found')
@ -68,7 +69,7 @@ local function incoming_calls_handler(bang, err, result, ctx, cfg)
gui.new_list_view({ items = results, ft = ft, api = '' }) gui.new_list_view({ items = results, ft = ft, api = '' })
end end
local function outgoing_calls_handler(bang, err, result, ctx, cfg) local function outgoing_calls_handler(_, err, result, ctx, cfg)
local results = call_hierarchy_handler_to(err, result, ctx, cfg, 'Outgoing calls not found') local results = call_hierarchy_handler_to(err, result, ctx, cfg, 'Outgoing calls not found')
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft') local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')

@ -2,12 +2,12 @@ local util = require('navigator.util')
local lsphelper = require('navigator.lspwrapper') local lsphelper = require('navigator.lspwrapper')
local gui = require('navigator.gui') local gui = require('navigator.gui')
local M = {} local M = {}
local location = require('guihua.location') -- local location = require('guihua.location')
local partial = util.partial local partial = util.partial
local locations_to_items = lsphelper.locations_to_items local locations_to_items = lsphelper.locations_to_items
local log = util.log local log = util.log
-- dataformat should be same as reference -- dataformat should be same as reference
local function location_handler(err, locations, ctx, cfg, msg) local function location_handler(err, locations, ctx, _, msg)
if err ~= nil then if err ~= nil then
vim.notify('ERROR: ' .. tostring(err) .. ' ' .. msg, vim.lsp.log_levels.WARN) vim.notify('ERROR: ' .. tostring(err) .. ' ' .. msg, vim.lsp.log_levels.WARN)
return return
@ -15,7 +15,7 @@ local function location_handler(err, locations, ctx, cfg, msg)
return locations_to_items(locations, ctx) return locations_to_items(locations, ctx)
end end
local function implementation_handler(bang, err, result, ctx, cfg) local function implementation_handler(_, err, result, ctx, cfg)
local results = location_handler(err, result, ctx, cfg, 'Implementation not found') local results = location_handler(err, result, ctx, cfg, 'Implementation not found')
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft') local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
gui.new_list_view({ items = results, ft = ft, api = 'Implementation' }) gui.new_list_view({ items = results, ft = ft, api = 'Implementation' })

@ -51,7 +51,7 @@ return {
local lazy_plugins = {} local lazy_plugins = {}
lazy_plugins[plugin_name] = path lazy_plugins[plugin_name] = path
loader = require('packer').loader loader = require('packer').loader
for plugin, url in pairs(lazy_plugins) do for plugin, _ in pairs(lazy_plugins) do
if packer_plugins[plugin] and packer_plugins[plugin].loaded == false then if packer_plugins[plugin] and packer_plugins[plugin].loaded == false then
-- log("loading ", plugin) -- log("loading ", plugin)
pcall(loader, plugin) pcall(loader, plugin)

@ -1,14 +1,12 @@
-- todo allow config passed in -- todo allow config passed in
local util = require('navigator.util') local ng_util = require('navigator.util')
local log = util.log local log = ng_util.log
local trace = util.trace local trace = ng_util.trace
local uv = vim.loop local empty = ng_util.empty
local empty = util.empty local warn = ng_util.warn
local warn = util.warn
_NG_Loaded = {} _NG_Loaded = {}
_LoadedFiletypes = {} _LoadedFiletypes = {}
local loader = nil
packer_plugins = packer_plugins or nil -- suppress warnings packer_plugins = packer_plugins or nil -- suppress warnings
-- packer only -- packer only
@ -203,7 +201,7 @@ local setups = {
}, },
sqls = { sqls = {
filetypes = { 'sql' }, filetypes = { 'sql' },
on_attach = function(client, bufnr) on_attach = function(client, _)
client.server_capabilities.executeCommandProvider = client.server_capabilities.documentFormattingProvider or true client.server_capabilities.executeCommandProvider = client.server_capabilities.documentFormattingProvider or true
highlight.diagnositc_config_sign() highlight.diagnositc_config_sign()
require('sqls').setup({ picker = 'telescope' }) -- or default require('sqls').setup({ picker = 'telescope' }) -- or default
@ -369,7 +367,6 @@ local ng_default_cfg = {
flags = { allow_incremental_sync = true, debounce_text_changes = 1000 }, flags = { allow_incremental_sync = true, debounce_text_changes = 1000 },
} }
local configs = {}
-- check and load based on file type -- check and load based on file type
local function load_cfg(ft, client, cfg, loaded) local function load_cfg(ft, client, cfg, loaded)
@ -444,7 +441,6 @@ end
local function update_capabilities() local function update_capabilities()
trace(vim.o.ft, 'lsp startup') trace(vim.o.ft, 'lsp startup')
local loaded = {}
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.preselectSupport = true capabilities.textDocument.completion.completionItem.preselectSupport = true
@ -481,7 +477,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
if lspclient.name then if lspclient.name then
lspclient = lspclient.name lspclient = lspclient.name
else else
warn('incorrect set for lspclient', vim.inspect(lspclient)) warn('incorrect set for lspclient'.. vim.inspect(lspclient))
goto continue goto continue
end end
end end
@ -546,9 +542,9 @@ local function lsp_startup(ft, retry, user_lsp_opts)
if user_lsp_opts[lspclient] ~= nil then if user_lsp_opts[lspclient] ~= nil then
-- log(lsp_opts[lspclient], cfg) -- log(lsp_opts[lspclient], cfg)
cfg = vim.tbl_deep_extend('force', cfg, user_lsp_opts[lspclient]) cfg = vim.tbl_deep_extend('force', cfg, user_lsp_opts[lspclient])
if config.combined_attach == nil then -- if config.combined_attach == nil then
setup_fmt(client, enable_fmt) -- setup_fmt(client, enable_fmt)
end -- end
if config.combined_attach == 'mine' then if config.combined_attach == 'mine' then
if config.on_attach == nil then if config.on_attach == nil then
error('on attach not provided') error('on attach not provided')
@ -652,7 +648,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
end, 1000) end, 1000)
log('null-ls loading') log('null-ls loading')
_NG_Loaded['null-ls'] = true _NG_Loaded['null-ls'] = true
configs['null-ls'] = cfg setups['null-ls'] = cfg
end end
end end
@ -671,7 +667,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
lspconfig.efm.setup(cfg) lspconfig.efm.setup(cfg)
log('efm loading') log('efm loading')
_NG_Loaded['efm'] = true _NG_Loaded['efm'] = true
configs['efm'] = cfg setups['efm'] = cfg
end end
end end

@ -1,6 +1,6 @@
local lsp = require("vim.lsp") local lsp = require("vim.lsp")
M = {} local M = {}
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true

@ -1,6 +1,6 @@
local M = {} local M = {}
local log = require('navigator.util').log -- local log = require('navigator.util').log
local api = vim.api local api = vim.api
-- lsp sign          ﮻         ﯭ        ﳀ   -- lsp sign          ﮻         ﯭ        ﳀ  

@ -1,78 +1,135 @@
local kind_symbols = { local kind_symbols = {
Text = "", Text = '',
Method = "ƒ", Method = 'ƒ',
Function = "", Function = '',
Constructor = "", Constructor = '',
Field = "", Field = '',
Variable = "", Variable = '',
Class = "", Class = '',
Interface = "", Interface = '',
Module = "", Module = '',
Property = "", Property = '',
Unit = "", Unit = '',
Value = "", Value = '',
Enum = "", Enum = '',
Keyword = "", Keyword = '',
Snippet = "", Snippet = '',
Color = "", Color = '',
File = "", File = '',
Reference = "", Reference = '',
Folder = "", Folder = '',
EnumMember = "", EnumMember = '',
Constant = "", Constant = '',
Struct = "", Struct = '',
Event = "", Event = '',
Operator = "", Operator = '',
TypeParameter = "", TypeParameter = '',
Default = "" Default = '',
} }
local CompletionItemKind = { local CompletionItemKind = {
"", "𝔉 ", "", "", "", "", "", "", "", "", "", "", "𝕰 ", "", '',
"", "", "", "", "", "", "", "", "", "", "", "" '𝔉 ',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'𝕰 ',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
} }
-- A symbol kind. -- A symbol kind.
local SymbolKind = { -- local SymbolKind = {
File = 1, -- File = 1,
Module = 2, -- Module = 2,
Namespace = 3, -- Namespace = 3,
Package = 4, -- Package = 4,
Class = 5, -- Class = 5,
Method = 6, -- Method = 6,
Property = 7, -- Property = 7,
Field = 8, -- Field = 8,
Constructor = 9, -- Constructor = 9,
Enum = 10, -- Enum = 10,
Interface = 11, -- Interface = 11,
Function = 12, -- Function = 12,
Variable = 13, -- Variable = 13,
Constant = 14, -- Constant = 14,
String = 15, -- String = 15,
Number = 16, -- Number = 16,
Boolean = 17, -- Boolean = 17,
Array = 18, -- Array = 18,
Object = 19, -- Object = 19,
Key = 20, -- Key = 20,
Null = 21, -- Null = 21,
EnumMember = 22, -- EnumMember = 22,
Struct = 23, -- Struct = 23,
Event = 24, -- Event = 24,
Operator = 25, -- Operator = 25,
TypeParameter = 26 -- TypeParameter = 26
} -- }
local SymbolItemKind = { local SymbolItemKind = {
"", "", "", "", "", "ƒ ", "", "", "", "𝕰 ", "", "", "", "", "", '',
"", "", "", "", "", "", "", "", "", "", "", "" '',
'',
'',
'',
'ƒ ',
'',
'',
'',
'𝕰 ',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
} }
local lspkind = {} local lspkind = {}
function lspkind.comp_kind(kind) return CompletionItemKind[kind] or "" end function lspkind.comp_kind(kind)
return CompletionItemKind[kind] or ''
end
function lspkind.symbol_kind(kind) return SymbolItemKind[kind] or "" end function lspkind.symbol_kind(kind)
return SymbolItemKind[kind] or ''
end
function lspkind.cmp_kind(kind) return kind_symbols[kind] or "" end function lspkind.cmp_kind(kind)
return kind_symbols[kind] or ''
end
function lspkind.init() require('vim.lsp.protocol').CompletionItemKind = CompletionItemKind end function lspkind.init()
require('vim.lsp.protocol').CompletionItemKind = CompletionItemKind
end
return lspkind return lspkind

@ -148,14 +148,14 @@ local function set_mapping(user_opts)
local fmtkey, rfmtkey local fmtkey, rfmtkey
for _, value in pairs(key_maps) do for _, value in pairs(key_maps) do
local f = '<Cmd>lua vim.lsp.buf.' .. value.func .. '<CR>' local f = '<Cmd>lua vim.lsp.buf.' .. value.func .. '<CR>'
if string.find(value.func, 'require') then if string.find(value.func, 'require') or string.find(value.func, 'vim.') then
f = '<Cmd>lua ' .. value.func .. '<CR>' f = '<Cmd>lua ' .. value.func .. '<CR>'
elseif string.find(value.func, 'diagnostic') then elseif string.find(value.func, 'diagnostic') then
local diagnostic = '<Cmd>lua vim.' local diagnostic = '<Cmd>lua vim.'
diagnostic = '<Cmd>lua vim.' diagnostic = '<Cmd>lua vim.'
f = diagnostic .. value.func .. '<CR>' f = diagnostic .. value.func .. '<CR>'
elseif string.find(value.func, 'vim.') then -- elseif string.find(value.func, 'vim.') then
f = '<Cmd>lua ' .. value.func .. '<CR>' -- f = '<Cmd>lua ' .. value.func .. '<string.find(value.func, 'vim.')CR>'
end end
local k = value.key local k = value.key
local m = value.mode or 'n' local m = value.mode or 'n'
@ -196,7 +196,7 @@ local function set_mapping(user_opts)
log('enable format ', doc_fmt, range_fmt, _NgConfigValues.lsp.format_on_save) log('enable format ', doc_fmt, range_fmt, _NgConfigValues.lsp.format_on_save)
end end
local function autocmd(user_opts) local function autocmd()
vim.api.nvim_exec( vim.api.nvim_exec(
[[ [[
aug NavigatorDocHlAu aug NavigatorDocHlAu
@ -257,7 +257,7 @@ function M.setup(user_opts)
user_opts = user_opts or _NgConfigValues user_opts = user_opts or _NgConfigValues
set_mapping(user_opts) set_mapping(user_opts)
autocmd(user_opts) autocmd()
set_event_handler(user_opts) set_event_handler(user_opts)
local client = user_opts.client or {} local client = user_opts.client or {}
@ -301,7 +301,11 @@ function M.setup(user_opts)
}) })
end end
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = single }) local border_style = single
if _NgConfigValues.border == 'double' then
border_style = double
end
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = border_style })
if cap.documentFormattingProvider then if cap.documentFormattingProvider then
log('formatting enabled setup hdl') log('formatting enabled setup hdl')
vim.lsp.handlers['textDocument/formatting'] = require('navigator.formatting').format_hdl vim.lsp.handlers['textDocument/formatting'] = require('navigator.formatting').format_hdl

@ -294,21 +294,21 @@ local function slice_locations(locations, max_items)
return first_part, second_part return first_part, second_part
end end
local function test_locations() -- local function test_locations()
local locations = { -- local locations = {
{ uri = '1', range = { start = { line = 1 } } }, -- { uri = '1', range = { start = { line = 1 } } },
{ uri = '2', range = { start = { line = 2 } } }, -- { uri = '2', range = { start = { line = 2 } } },
{ uri = '2', range = { start = { line = 3 } } }, -- { uri = '2', range = { start = { line = 3 } } },
{ uri = '1', range = { start = { line = 3 } } }, -- { uri = '1', range = { start = { line = 3 } } },
{ uri = '1', range = { start = { line = 4 } } }, -- { uri = '1', range = { start = { line = 4 } } },
{ uri = '3', range = { start = { line = 4 } } }, -- { uri = '3', range = { start = { line = 4 } } },
{ uri = '3', range = { start = { line = 4 } } }, -- { uri = '3', range = { start = { line = 4 } } },
} -- }
local second_part -- local second_part
order_locations(locations) -- order_locations(locations)
local locations, second_part = slice_locations(locations, 3) -- local locations, second_part = slice_locations(locations, 3)
log(locations, second_part) -- log(locations, second_part)
end -- end
function M.locations_to_items(locations, ctx) function M.locations_to_items(locations, ctx)
ctx = ctx or {} ctx = ctx or {}
@ -462,7 +462,7 @@ end
function M.request(method, hdlr) -- e.g textDocument/reference function M.request(method, hdlr) -- e.g textDocument/reference
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local ref_params = vim.lsp.util.make_position_params() local ref_params = vim.lsp.util.make_position_params()
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) vim.lsp.for_each_buffer_client(bufnr, function(client, _, _)
client.request(method, ref_params, hdlr, bufnr) client.request(method, ref_params, hdlr, bufnr)
end) end)
end end

@ -4,7 +4,6 @@ local lsphelper = require('navigator.lspwrapper')
local gui = require('navigator.gui') local gui = require('navigator.gui')
local lsp = require('navigator.lspwrapper') local lsp = require('navigator.lspwrapper')
local trace = require('navigator.util').trace local trace = require('navigator.util').trace
ListViewCtrl = ListViewCtrl or require('guihua.listviewctrl').ListViewCtrl
-- local partial = util.partial -- local partial = util.partial
-- local cwd = vim.loop.cwd() -- local cwd = vim.loop.cwd()
-- local lsphelper = require "navigator.lspwrapper" -- local lsphelper = require "navigator.lspwrapper"
@ -41,7 +40,7 @@ local ref_view = function(err, locations, ctx, cfg)
if references and references.result and #references.result > 0 then if references and references.result and #references.result > 0 then
local refs = references.result local refs = references.result
for _, value in pairs(locations) do for _, value in pairs(locations) do
vrange = value.range or { start = { line = 0 }, ['end'] = { line = 0 } } local vrange = value.range or { start = { line = 0 }, ['end'] = { line = 0 } }
for i = 1, #refs, 1 do for i = 1, #refs, 1 do
local rg = refs[i].range or {} local rg = refs[i].range or {}
log(value, refs[i]) log(value, refs[i])
@ -204,7 +203,7 @@ local ref = function()
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local ref_params = vim.lsp.util.make_position_params() local ref_params = vim.lsp.util.make_position_params()
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, bufnr) vim.lsp.for_each_buffer_client(bufnr, function(client, _, _)
if client.server_capabilities.referencesProvider then if client.server_capabilities.referencesProvider then
client.request('textDocument/references', ref_params, ref_hdlr, bufnr) client.request('textDocument/references', ref_params, ref_hdlr, bufnr)
end end
@ -212,12 +211,9 @@ local ref = function()
end end
return { return {
reference_handler = ref_hdlr, reference_handler = ref_hdlr,
reference = ref_req, reference = ref_req,
ref_view = ref_view, ref_view = ref_view,
async_ref = async_ref, async_ref = async_ref,
all_ref = ref,
} }

@ -68,16 +68,16 @@ function M.prepare_for_render(items, opts)
local ext = extension(fn) local ext = extension(fn)
icon = devicons.get_icon(fn, ext) or icon icon = devicons.get_icon(fn, ext) or icon
end end
local call_by_presented = false -- local call_by_presented = false
local width = 100 local width = 100
opts.width = opts.width or width opts.width = opts.width or width
local win_width = opts.width -- buf local win_width = opts.width -- buf
for i = 1, #items do -- for i = 1, #items do
if items[i].call_by and #items[i].call_by > 0 then -- if items[i].call_by and #items[i].call_by > 0 then
call_by_presented = true -- call_by_presented = true
end -- end
end -- end
-- log(items[1]) -- log(items[1])
for i = 1, #items do for i = 1, #items do

@ -1,10 +1,5 @@
local gui = require "navigator.gui"
local util = require "navigator.util" local util = require "navigator.util"
local log = util.log local log = util.log
local partial = util.partial
local lsphelper = require "navigator.lspwrapper"
local cwd = vim.loop.cwd()
local M = {}
--- navigator signature --- navigator signature
local match_parameter = function(result) local match_parameter = function(result)

@ -3,8 +3,6 @@ local M = {}
local log = require('navigator.util').log local log = require('navigator.util').log
local trace = require('navigator.util').trace local trace = require('navigator.util').trace
local lsphelper = require('navigator.lspwrapper') local lsphelper = require('navigator.lspwrapper')
local locations_to_items = lsphelper.locations_to_items
local clone = require('guihua.util').clone
local symbol_kind = require('navigator.lspclient.lspkind').symbol_kind local symbol_kind = require('navigator.lspclient.lspkind').symbol_kind
local symbols_to_items = lsphelper.symbols_to_items local symbols_to_items = lsphelper.symbols_to_items
@ -12,7 +10,7 @@ function M.workspace_symbols(query)
query = query or pcall(vim.fn.input, 'Query: ') query = query or pcall(vim.fn.input, 'Query: ')
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local params = { query = query } local params = { query = query }
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) vim.lsp.for_each_buffer_client(bufnr, function(client, _, _bufnr)
-- if client.resolved_capabilities.workspace_symbol then -- if client.resolved_capabilities.workspace_symbol then
if client.server_capabilities.workspaceSymbolProvider then if client.server_capabilities.workspaceSymbolProvider then
client.request('workspace/symbol', params, M.workspace_symbol_handler, _bufnr) client.request('workspace/symbol', params, M.workspace_symbol_handler, _bufnr)
@ -34,7 +32,7 @@ function M.document_symbols(opts)
local params = vim.lsp.util.make_position_params() local params = vim.lsp.util.make_position_params()
params.context = { includeDeclaration = true } params.context = { includeDeclaration = true }
params.query = opts.prompt or '' params.query = opts.prompt or ''
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) vim.lsp.for_each_buffer_client(bufnr, function(client, _, _bufnr)
-- if client.resolved_capabilities.document_symbol then -- if client.resolved_capabilities.document_symbol then
if client.server_capabilities.documentSymbolProvider then if client.server_capabilities.documentSymbolProvider then
client.request('textDocument/documentSymbol', params, M.document_symbol_handler, _bufnr) client.request('textDocument/documentSymbol', params, M.document_symbol_handler, _bufnr)

@ -149,9 +149,7 @@ local function prepare_node(node, kind)
end end
local function get_scope(type, source) local function get_scope(type, source)
local sbl, sbc, sel, sec = source:range()
local current = source local current = source
local result = current
local next = ts_utils.get_next_node(source) local next = ts_utils.get_next_node(source)
local parent = current:parent() local parent = current:parent()
trace(source:type(), source:range(), parent) trace(source:type(), source:range(), parent)
@ -169,7 +167,7 @@ local function get_scope(type, source)
-- for C++ -- for C++
local n = source local n = source
for i = 1, 4, 1 do for _ = 1, 4, 1 do
if n == nil or n:parent() == nil then if n == nil or n:parent() == nil then
break break
end end
@ -195,7 +193,7 @@ local function get_scope(type, source)
-- M.fun1 = function() end -- M.fun1 = function() end
-- lets work up and see next node, lua -- lets work up and see next node, lua
local n = source local n = source
for i = 1, 4, 1 do for _ = 1, 4, 1 do
if n == nil or n:parent() == nil then if n == nil or n:parent() == nil then
break break
end end
@ -303,7 +301,7 @@ local function get_all_nodes(bufnr, filter, summary)
local all_nodes = {} local all_nodes = {}
-- Support completion-nvim customized label map -- Support completion-nvim customized label map
local customized_labels = vim.g.completion_customize_lsp_label or {} -- local customized_labels = vim.g.completion_customize_lsp_label or {}
-- Force some types to act like they are parents -- Force some types to act like they are parents
-- instead of neighbors of the next nodes. -- instead of neighbors of the next nodes.

@ -114,7 +114,13 @@ end
function M.get_relative_path(base_path, my_path) function M.get_relative_path(base_path, my_path)
local base_data = getDir(base_path) local base_data = getDir(base_path)
if base_data == nil then
return
end
local my_data = getDir(my_path) local my_data = getDir(my_path)
if my_data == nil then
return
end
local base_len = #base_data local base_len = #base_data
local my_len = #my_data local my_len = #my_data
@ -163,10 +169,18 @@ if _NgConfigValues.debug then
M.error = M._log.error M.error = M._log.error
else else
M._log = {} M._log = {}
M.log = function() end M.log = function(...)
M.info = function() end return { ... }
M.trace = function() end end
M.error = function() end M.info = function(...)
return { ... }
end
M.trace = function(...)
return { ... }
end
M.error = function(...)
return { ... }
end
end end
function M.fmt(...) function M.fmt(...)
@ -261,7 +275,7 @@ function M.split2(s, sep)
sep = sep or ' ' sep = sep or ' '
local pattern = string.format('([^%s]+)', sep) local pattern = string.format('([^%s]+)', sep)
string.gsub(s, pattern, function(c) _ = string.gsub(s, pattern, function(c)
fields[#fields + 1] = c fields[#fields + 1] = c
end) end)
@ -293,13 +307,13 @@ end
M.open_file_at = guihua.open_file_at M.open_file_at = guihua.open_file_at
function M.exists(var) -- function M.exists(var)
for k, _ in pairs(_G) do -- for k, _ in pairs(_G) do
if k == var then -- if k == var then
return true -- return true
end -- end
end -- end
end -- end
local exclude_ft = { 'scrollbar', 'help', 'NvimTree' } local exclude_ft = { 'scrollbar', 'help', 'NvimTree' }
function M.exclude(fname) function M.exclude(fname)

@ -38,7 +38,7 @@ M.list_workspace_folders = function()
items = folders, items = folders,
border = 'single', border = 'single',
rawdata = true, rawdata = true,
on_move = function(...) on_move = function()
end end
}) })
end end

Loading…
Cancel
Save