Merge branch 'neovim_0.7'

serverCapcities
ray-x 2 years ago
commit a316e7f449

@ -116,7 +116,7 @@ I'd like to go beyond what the system is offering.
# Install # Install
Require nvim-0.5.0 (a.k.a nightly) Require nvim-0.6.1, nightly prefered
You can remove your lspconfig setup and use this plugin. You can remove your lspconfig setup and use this plugin.
The plugin depends on lspconfig and [guihua.lua](https://github.com/ray-x/guihua.lua), which provides GUI and fzy support(migrate from [romgrk's project](romgrk/fzy-lua-native)). The plugin depends on lspconfig and [guihua.lua](https://github.com/ray-x/guihua.lua), which provides GUI and fzy support(migrate from [romgrk's project](romgrk/fzy-lua-native)).
@ -271,6 +271,12 @@ require'navigator'.setup({
-- to disable all default config and use your own lsp setup set -- to disable all default config and use your own lsp setup set
-- disable_lsp = 'all' -- disable_lsp = 'all'
-- Default {} -- Default {}
diagnostic = {
underline = true,
virtual_text = true, -- show virtual for diagnostic message
update_in_insert = false, -- update diagnostic message in insert mode
},
diagnostic_scrollbar_sign = {'▃', '▆', '█'}, -- experimental: diagnostic status in scroll bar area; set to false to disable the diagnostic sign, diagnostic_scrollbar_sign = {'▃', '▆', '█'}, -- experimental: diagnostic status in scroll bar area; set to false to disable the diagnostic sign,
-- for other style, set to {'╍', 'ﮆ'} or {'-', '='} -- for other style, set to {'╍', 'ﮆ'} or {'-', '='}
diagnostic_virtual_text = true, -- show virtual for diagnostic message diagnostic_virtual_text = true, -- show virtual for diagnostic message
@ -389,8 +395,8 @@ In `playground` folder, there is a `init.lua` and source code for you to play wi
| mode | key | function | | mode | key | function |
| ---- | --------------- | ---------------------------------------------------------- | | ---- | --------------- | ---------------------------------------------------------- |
| n | gr | show reference and context | | n | gr | async references, definitions and context |
| n | Gr | async references, definitions and context (experiential) | | n | \<Leader>gr | show reference and context |
| i | \<m-k\> | signature help | | i | \<m-k\> | signature help |
| n | \<c-k\> | signature help | | n | \<c-k\> | signature help |
| n | gW | workspace symbol | | n | gW | workspace symbol |
@ -759,7 +765,7 @@ end
# Errors and Bug Reporting # Errors and Bug Reporting
- Please double check your setup and check if minium setup works or not - Please double check your setup and check if minium setup works or not
- It should works for 0.5.1, neovim 0.6.x prefered. - It should works for 0.6.1, neovim 0.7.x prefered.
- Check console output - Check console output
- Check `LspInfo` and treesitter status with `checkhealth` - Check `LspInfo` and treesitter status with `checkhealth`
- Turn on log and attach the log to your issue if possible you can remove any personal/company info in the log - Turn on log and attach the log to your issue if possible you can remove any personal/company info in the log

@ -151,7 +151,7 @@ SIMILAR PROJECTS / SPECIAL MENTIONS: *navigator-similar_projects_/_special_menti
================================================================================ ================================================================================
INSTALL *navigator-install* INSTALL *navigator-install*
Require nvim-0.5.0 (a.k.a nightly) Require nvim-0.6.1 or nightly
You can remove your lspconfig setup and use this plugin. You can remove your lspconfig setup and use this plugin.
The plugin depends on lspconfig and guihua.lua (https://github.com/ray-x/guihua.lua), which provides GUI and fzy support(migrate from romgrk's project (romgrk/fzy-lua-native)). The plugin depends on lspconfig and guihua.lua (https://github.com/ray-x/guihua.lua), which provides GUI and fzy support(migrate from romgrk's project (romgrk/fzy-lua-native)).
@ -279,8 +279,6 @@ Nondefault configuration example:
-- Default {} -- Default {}
diagnostic_scrollbar_sign = {'▃', '▆', '█'}, -- experimental: diagnostic status in scroll bar area; set to false to disable the diagnostic sign, diagnostic_scrollbar_sign = {'▃', '▆', '█'}, -- experimental: diagnostic status in scroll bar area; set to false to disable the diagnostic sign,
-- for other style, set to {'╍', 'ﮆ'} or {'-', '='} -- for other style, set to {'╍', 'ﮆ'} or {'-', '='}
diagnostic_virtual_text = true, -- show virtual for diagnostic message
diagnostic_update_in_insert = false, -- update diagnostic message in insert mode
disply_diagnostic_qf = true, -- always show quickfix if there are diagnostic errors, set to false if you want to disply_diagnostic_qf = true, -- always show quickfix if there are diagnostic errors, set to false if you want to
ignore it ignore it
tsserver = { tsserver = {
@ -687,8 +685,7 @@ TODO *navigator-tod
ERRORS AND BUG REPORTING *navigator-errors_and_bug_reporting* ERRORS AND BUG REPORTING *navigator-errors_and_bug_reporting*
* Please double check your setup and check if minium setup works or not * Please double check your setup and check if minium setup works or not
* It should works for 0.5.1, neovim 0.6.x prefered. * It should works for 0.6.1, neovim 0.7.x prefered.
* Check console output * Check console output
* Check `LspInfo` and treesitter status with `checkhealth` * Check `LspInfo` and treesitter status with `checkhealth`
* Turn on log and attach the log to your issue if possible you can remove any personal/company info in the log * Turn on log and attach the log to your issue if possible you can remove any personal/company info in the log

@ -33,7 +33,7 @@ _NgConfigValues = {
transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil to disable it transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil to disable it
lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator
-- setup here. if it is nil, navigator will not init signature help -- setup here. if it is nil, navigator will not init signature help
signature_help_cfg = { debug = false }, -- if you would like to init ray-x/lsp_signature plugin in navigator, pass in signature help signature_help_cfg = {debug=false}, -- if you would like to init ray-x/lsp_signature plugin in navigator, pass in signature help
lsp = { lsp = {
code_action = { code_action = {
enable = true, enable = true,
@ -49,6 +49,12 @@ _NgConfigValues = {
virtual_text = true, virtual_text = true,
virtual_text_icon = true, virtual_text_icon = true,
}, },
diagnostic = {
underline = true,
virtual_text = { spacing = 3 }, -- show virtual for diagnostic message
update_in_insert = false, -- update diagnostic message in insert mode
severity_sort = { reverse = true },
},
format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc)
disable_format_cap = {}, -- a list of lsp disable file format (e.g. if you using efm or vim-codeformat etc), empty by default disable_format_cap = {}, -- a list of lsp disable file format (e.g. if you using efm or vim-codeformat etc), empty by default
disable_lsp = {}, -- a list of lsp server disabled for your project, e.g. denols and tsserver you may disable_lsp = {}, -- a list of lsp server disabled for your project, e.g. denols and tsserver you may
@ -218,28 +224,34 @@ M.setup = function(cfg)
extend_config(cfg) extend_config(cfg)
vim.cmd([[autocmd FileType,BufEnter * lua require'navigator.lspclient.clients'.on_filetype()]]) -- BufWinEnter BufNewFile,BufRead ? vim.cmd([[autocmd FileType,BufEnter * lua require'navigator.lspclient.clients'.on_filetype()]]) -- BufWinEnter BufNewFile,BufRead ?
-- local log = require"navigator.util".log
-- log(debug.traceback())
-- log(cfg, _NgConfigValues)
-- print("loading navigator")
require('navigator.lazyloader').init() require('navigator.lazyloader').init()
require('navigator.lspclient.clients').setup(_NgConfigValues) require('navigator.lspclient.clients').setup(_NgConfigValues)
-- keymaps should be added to on_attach. in case on_attach is not called
-- require('navigator.lspclient.mapping').setup(_NgConfigValues)
require('navigator.reference') require('navigator.reference')
require('navigator.definition') require('navigator.definition')
require('navigator.hierarchy') require('navigator.hierarchy')
require('navigator.implementation') require('navigator.implementation')
-- log("navigator loader") require('navigator.diagnostics').config(cfg.diagnostic)
-- vim.cmd("autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4")
if not _NgConfigValues.loaded then if not _NgConfigValues.loaded then
_NgConfigValues.loaded = true _NgConfigValues.loaded = true
end end
if _NgConfigValues.ts_fold == true then if _NgConfigValues.ts_fold == true then
require('navigator.foldts').on_attach() local ok, _ = pcall(require, 'nvim-treesitter')
if ok then
require('navigator.foldts').on_attach()
end
end
local _start_client = vim.lsp.start_client
vim.lsp.start_client = function(lsp_config)
-- add highlight for Lspxxx
require('navigator.dochighlight').documentHighlight()
require('navigator.lspclient.highlight').add_highlight()
require('navigator.lspclient.highlight').diagnositc_config_sign()
-- require('navigator.lspclient.mapping').setup()
require('navigator.lspclient.lspkind').init()
return _start_client(lsp_config)
end end
end end

@ -138,9 +138,16 @@ local code_action_req = function(_call_back_fn, diagnostics)
vim.lsp.buf_request(0, 'textDocument/codeAction', params, callback) vim.lsp.buf_request(0, 'textDocument/codeAction', params, callback)
end end
local function sort_select(action_tuples, opts, on_user_choice)
table.sort(action_tuples, function(a, b)
return a[1] > b[1]
end)
require('guihua.gui').select(action_tuples, opts, on_user_choice)
end
code_action.code_action = function() code_action.code_action = function()
local original_select = vim.ui.select local original_select = vim.ui.select
vim.ui.select = require('guihua.gui').select vim.ui.select = sort_select
log('codeaction') log('codeaction')

@ -5,7 +5,7 @@ local codelens = require('vim.lsp.codelens')
local log = require('navigator.util').log local log = require('navigator.util').log
local mk_handler = require('navigator.util').mk_handler local mk_handler = require('navigator.util').mk_handler
local nvim_0_6 = require('navigator.util').nvim_0_6 local nvim_0_6_1 = require('navigator.util').nvim_0_6_1
local trace = require('navigator.util').trace local trace = require('navigator.util').trace
local lsphelper = require('navigator.lspwrapper') local lsphelper = require('navigator.lspwrapper')
@ -50,7 +50,7 @@ local function _update_sign(line)
end end
local codelens_hdlr = mk_handler(function(err, result, ctx, cfg) local codelens_hdlr = mk_handler(function(err, result, ctx, cfg)
log(ctx, result) trace(ctx, result)
M.codelens_ctx = ctx M.codelens_ctx = ctx
if err or result == nil then if err or result == nil then
if err then if err then
@ -79,7 +79,7 @@ function M.setup()
-- trace(err, result, ctx.client_id, ctx.bufnr, cfg or {}) -- trace(err, result, ctx.client_id, ctx.bufnr, cfg or {})
cfg = cfg or {} cfg = cfg or {}
ctx = ctx or { bufnr = vim.api.nvim_get_current_buf() } ctx = ctx or { bufnr = vim.api.nvim_get_current_buf() }
if nvim_0_6() then if nvim_0_6_1() then
on_codelens(err, result, ctx, cfg) on_codelens(err, result, ctx, cfg)
codelens_hdlr(err, result, ctx, cfg) codelens_hdlr(err, result, ctx, cfg)
else else
@ -110,20 +110,16 @@ function M.disable()
is_enabled = false is_enabled = false
end end
function M.run_action() function M.run_action()
local original_select = vim.ui.select local original_select = vim.ui.select
vim.ui.select = require("guihua.gui").select vim.ui.select = require('guihua.gui').select
log('codeaction') log('codeaction')
codelens.run() codelens.run()
vim.defer_fn( vim.defer_fn(function()
function () vim.ui.select = original_select
vim.ui.select = original_select end, 1000)
end, 1000
)
end end
M.inline = function() M.inline = function()

@ -8,7 +8,7 @@ local TextView = require('guihua.textview')
local definition_hdlr = util.mk_handler(function(err, locations, ctx, _) local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
-- log(locations) -- log(locations)
if err ~= nil then if err ~= nil then
vim.notify('Defination: ', tostring(err) .. vim.inspect(ctx), vim.lsp.log_levels.WARN) vim.notify('Defination: ' .. tostring(err) .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
return return
end end
if type(locations) == 'number' then if type(locations) == 'number' then

@ -33,6 +33,29 @@ if vim.diagnostic then
} }
end end
local diagnostic_cfg = {
-- Enable underline, use default values
underline = _NgConfigValues.lsp.diagnostic.underline,
-- Enable virtual text, override spacing to 3 (prevent overlap)
virtual_text = {
spacing = _NgConfigValues.lsp.diagnostic.virtual_text.spacing,
prefix = _NgConfigValues.icons.diagnostic_virtual_text,
},
-- Use a function to dynamically turn signs off
-- and on, using buffer local variables
signs = true,
update_in_insert = _NgConfigValues.lsp.diagnostic.update_in_insert or false,
severity_sort = _NgConfigValues.lsp.diagnostic.severity_sort,
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
}
local function get_count(bufnr, level) local function get_count(bufnr, level)
if vim.diagnostic ~= nil then if vim.diagnostic ~= nil then
return #diagnostic.get(bufnr, { severity = diag_map[level] }) return #diagnostic.get(bufnr, { severity = diag_map[level] })
@ -182,6 +205,7 @@ end
local diag_hdlr = mk_handler(function(err, result, ctx, config) local diag_hdlr = mk_handler(function(err, result, ctx, config)
require('navigator.lspclient.highlight').diagnositc_config_sign() require('navigator.lspclient.highlight').diagnositc_config_sign()
config = config or diagnostic_cfg
if err ~= nil then if err ~= nil then
log(err, config, result) log(err, config, result)
return return
@ -203,11 +227,11 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
trace('diagnostic', result.diagnostics, ctx, config) trace('diagnostic', result.diagnostics, ctx, config)
end end
if util.nvim_0_6() then if util.nvim_0_6_1() then
trace(err, result, ctx, config) trace(err, result, ctx, config)
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config) vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
else else
log('old version of lsp nvim 050') log('old version of lsp nvim <=0.5.0')
vim.lsp.diagnostic.on_publish_diagnostics(err, _, result, ctx.client_id, _, config) vim.lsp.diagnostic.on_publish_diagnostics(err, _, result, ctx.client_id, _, config)
end end
local uri = result.uri local uri = result.uri
@ -215,7 +239,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]]) local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]])
if empty(result.diagnostics) and diag_cnt > 0 then if empty(result.diagnostics) and diag_cnt > 0 then
log('no result? ', diag_cnt) trace('no result? ', diag_cnt)
return return
end end
-- trace("diag: ", mode, result, ctx, config) -- trace("diag: ", mode, result, ctx, config)
@ -303,27 +327,15 @@ local diag_hdlr_async = function()
end end
local M = {} local M = {}
local diagnostic_cfg = { if _NgConfigValues.lsp.diagnostic.virtual_text == false then
-- Enable underline, use default values
underline = true,
-- Enable virtual text, override spacing to 3 (prevent overlap)
virtual_text = {
spacing = 3,
prefix = _NgConfigValues.icons.icons and _NgConfigValues.icons.diagnostic_virtual_text or "" },
-- Use a function to dynamically turn signs off
-- and on, using buffer local variables
signs = true,
update_in_insert = _NgConfigValues.lsp.diagnostic_update_in_insert or false,
severity_sort = { reverse = true },
}
if _NgConfigValues.lsp.diagnostic_virtual_text == false then
diagnostic_cfg.virtual_text = false diagnostic_cfg.virtual_text = false
end end
-- vim.lsp.handlers["textDocument/publishDiagnostics"] -- vim.lsp.handlers["textDocument/publishDiagnostics"]
M.diagnostic_handler = vim.lsp.with(diag_hdlr, diagnostic_cfg) M.diagnostic_handler = vim.lsp.with(diag_hdlr, diagnostic_cfg)
vim.diagnostic.config(diagnostic_cfg)
M.hide_diagnostic = function() M.hide_diagnostic = function()
if _NG_VT_DIAG_NS then if _NG_VT_DIAG_NS then
vim.api.nvim_buf_clear_namespace(0, _NG_VT_DIAG_NS, 0, -1) vim.api.nvim_buf_clear_namespace(0, _NG_VT_DIAG_NS, 0, -1)
@ -361,7 +373,9 @@ M.show_buf_diagnostics = function()
enable_preview_edit = true, enable_preview_edit = true,
}) })
trace('new buffer', listview.bufnr) trace('new buffer', listview.bufnr)
vim.api.nvim_buf_add_highlight(listview.bufnr, -1, 'Title', 0, 0, -1) if listview.bufnr then
vim.api.nvim_buf_add_highlight(listview.bufnr, -1, 'Title', 0, 0, -1)
end
end end
end end
end end
@ -431,11 +445,6 @@ function M.update_err_marker()
marker(result, { bufnr = bufnr, method = 'textDocument/publishDiagnostics' }) marker(result, { bufnr = bufnr, method = 'textDocument/publishDiagnostics' })
end end
-- TODO: update the marker
if _NgConfigValues.diagnostic_scrollbar_sign then
vim.notify('config deprecated, set lsp.diagnostic_scrollbar_sign instead', vim.lsp.log_levels.WARN)
end
if _NgConfigValues.lsp.diagnostic_scrollbar_sign then if _NgConfigValues.lsp.diagnostic_scrollbar_sign then
vim.cmd([[autocmd WinScrolled * lua require'navigator.diagnostics'.update_err_marker()]]) vim.cmd([[autocmd WinScrolled * lua require'navigator.diagnostics'.update_err_marker()]])
end end
@ -462,4 +471,18 @@ function M.show_diagnostics(pos)
end end
end end
function M.config(cfg)
cfg = cfg
or {
underline = true,
virtual_text = true,
signs = { _NgConfigValues.icons.diagnostic_err },
update_in_insert = false,
}
vim.diagnostic.config(cfg)
end
if not util.nvim_0_6_1() then
util.warn('Navigator 0.4+ only support nvim-0.6+, please use 0.3.x')
end
return M return M

@ -219,14 +219,9 @@ end
local function documentHighlight() local function documentHighlight()
api.nvim_exec( api.nvim_exec(
[[ [[
autocmd ColorScheme * |
hi default LspReferenceRead cterm=bold gui=Bold ctermbg=yellow guifg=yellow guibg=purple4 |
hi default LspReferenceText cterm=bold gui=Bold ctermbg=red guifg=SlateBlue guibg=MidnightBlue |
hi default LspReferenceWrite cterm=bold gui=Bold,Italic ctermbg=red guifg=DarkSlateBlue guibg=MistyRose
augroup lsp_document_highlight augroup lsp_document_highlight
autocmd! * <buffer> autocmd! * <buffer>
autocmd CursorHold <buffer> lua nav_doc_hl() autocmd CursorHold,CursorHoldI <buffer> lua 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
]], ]],

@ -1,6 +1,7 @@
-- NOTE: this file is a modified version of fold.lua from nvim-treesitter -- NOTE: this file is a modified version of fold.lua from nvim-treesitter
local log = require('navigator.util').log local log = require('navigator.util').log
local trace = require('navigator.util').trace
local api = vim.api local api = vim.api
local tsutils = require('nvim-treesitter.ts_utils') local tsutils = require('nvim-treesitter.ts_utils')
local query = require('nvim-treesitter.query') local query = require('nvim-treesitter.query')
@ -23,7 +24,7 @@ function _G.custom_fold_text()
return '' .. line .. ': ' .. line_count .. ' lines' return '' .. line .. ': ' .. line_count .. ' lines'
end end
vim.opt.foldtext = custom_fold_text() vim.opt.foldtext = _G.custom_fold_text()
vim.opt.fillchars = { eob = '-', fold = ' ' } vim.opt.fillchars = { eob = '-', fold = ' ' }
@ -61,7 +62,7 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
local parser = parsers.get_parser(bufnr) local parser = parsers.get_parser(bufnr)
if not parser then if not parser then
warn('treesitter parser not loaded') log('treesitter parser not loaded')
return {} return {}
end end
@ -148,12 +149,12 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
levels[lnum + 1] = tostring(trimmed_level) levels[lnum + 1] = tostring(trimmed_level)
else else
-- if levels[lnum + 1] == nil then -- if levels[lnum + 1] == nil then
levels[lnum + 1] = tostring(trimmed_level + 1) levels[lnum + 1] = tostring(trimmed_level + 1)
-- end -- end
end end
end end
end end
log(levels) trace(levels)
return levels return levels
end) end)

@ -12,7 +12,7 @@ function M.new_list_view(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
log(active_list_view) trace(active_list_view)
local winnr = active_list_view.win local winnr = active_list_view.win
local bufnr = active_list_view.buf local bufnr = active_list_view.buf
@ -48,7 +48,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
log(opts) trace(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

@ -5,11 +5,6 @@ local util = require('navigator.util')
local log = util.log local log = util.log
local trace = util.trace local trace = util.trace
local diagnostic_map = function(bufnr)
local opts = { noremap = true, silent = true }
api.nvim_buf_set_keymap(bufnr, 'n', ']O', ':lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
end
local M = {} local M = {}
M.on_attach = function(client, bufnr) M.on_attach = function(client, bufnr)
@ -29,7 +24,6 @@ M.on_attach = function(client, bufnr)
trace(client) trace(client)
diagnostic_map(bufnr)
-- add highlight for Lspxxx -- add highlight for Lspxxx
require('navigator.lspclient.highlight').add_highlight() require('navigator.lspclient.highlight').add_highlight()
require('navigator.lspclient.highlight').diagnositc_config_sign() require('navigator.lspclient.highlight').diagnositc_config_sign()
@ -38,7 +32,6 @@ M.on_attach = function(client, bufnr)
require('navigator.lspclient.mapping').setup({ require('navigator.lspclient.mapping').setup({
client = client, client = client,
bufnr = bufnr, bufnr = bufnr,
cap = client.resolved_capabilities,
}) })
if client.resolved_capabilities.document_highlight then if client.resolved_capabilities.document_highlight then

@ -1,3 +1,4 @@
-- todo allow config passed in
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
@ -7,6 +8,7 @@ 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
@ -429,6 +431,8 @@ end
local function update_capabilities() local function update_capabilities()
trace(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
@ -436,7 +440,7 @@ local function update_capabilities()
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
capabilities.textDocument.completion.completionItem.deprecatedSupport = true capabilities.textDocument.completion.completionItem.deprecatedSupport = true
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
-- capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
capabilities.textDocument.completion.completionItem.resolveSupport = { capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = { 'documentation', 'detail', 'additionalTextEdits' }, properties = { 'documentation', 'detail', 'additionalTextEdits' },
} }
@ -510,6 +514,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
default_config = vim.tbl_deep_extend('force', default_config, ng_default_cfg) default_config = vim.tbl_deep_extend('force', default_config, ng_default_cfg)
local cfg = setups[lspclient] or {} local cfg = setups[lspclient] or {}
cfg = vim.tbl_deep_extend('keep', cfg, default_config) cfg = vim.tbl_deep_extend('keep', cfg, default_config)
-- filetype disabled -- filetype disabled
if not vim.tbl_contains(cfg.filetypes or {}, ft) then if not vim.tbl_contains(cfg.filetypes or {}, ft) then

@ -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          ﮻         ﯭ        ﳀ  
@ -10,80 +10,56 @@ function M.diagnositc_config_sign()
end end
local icons = _NgConfigValues.icons local icons = _NgConfigValues.icons
local sign_name = "NavigatorLightBulb" local sign_name = 'NavigatorLightBulb'
if vim.fn.sign_getdefined(sign_name).text == nil then if vim.fn.sign_getdefined(sign_name).text == nil then
vim.fn.sign_define(sign_name, { text = icons.code_action_icon, texthl = 'LspDiagnosticsSignHint' })
vim.fn sign_name = 'NavigatorCodeLensLightBulb'
.sign_define(sign_name, {text = icons.code_action_icon, texthl = "LspDiagnosticsSignHint"}) vim.fn.sign_define(sign_name, { text = icons.code_lens_action_icon, texthl = 'LspDiagnosticsSignHint' })
sign_name = "NavigatorCodeLensLightBulb"
vim.fn.sign_define(sign_name,
{text = icons.code_lens_action_icon, texthl = "LspDiagnosticsSignHint"})
end end
local e, w, i, h = icons.diagnostic_err, icons.diagnostic_warn, icons.diagnostic_info, local e, w, i, h = icons.diagnostic_err, icons.diagnostic_warn, icons.diagnostic_info, icons.diagnostic_hint
icons.diagnostic_hint local t = vim.fn.sign_getdefined('DiagnosticSignWarn')
if vim.diagnostic ~= nil then if vim.tbl_isempty(t) or t[1].text == 'W ' and icons.icons == true then
local t = vim.fn.sign_getdefined('DiagnosticSignWarn') vim.fn.sign_define('DiagnosticSignError', { text = e, texthl = 'DiagnosticError', linehl = '', numhl = '' })
if (vim.tbl_isempty(t) or t[1].text == "W ") and icons.icons == true then vim.fn.sign_define('DiagnosticSignWarn', { text = w, texthl = 'DiagnosticWarn', linehl = '', numhl = '' })
vim.fn.sign_define('DiagnosticSignInfo', { text = i, texthl = 'DiagnosticInfo', linehl = '', numhl = '' })
vim.fn.sign_define('DiagnosticSignError', vim.fn.sign_define('DiagnosticSignHint', { text = h, texthl = 'DiagnosticHint', linehl = '', numhl = '' })
{text = e, texthl = 'DiagnosticError', linehl = '', numhl = ''})
vim.fn.sign_define('DiagnosticSignWarn',
{text = w, texthl = 'DiagnosticWarn', linehl = '', numhl = ''})
vim.fn.sign_define('DiagnosticSignInfo',
{text = i, texthl = 'DiagnosticInfo', linehl = '', numhl = ''})
vim.fn.sign_define('DiagnosticSignHint',
{text = h, texthl = 'DiagnosticHint', linehl = '', numhl = ''})
t = vim.fn.sign_getdefined('DiagnosticSignWarn') t = vim.fn.sign_getdefined('DiagnosticSignWarn')
end
else
local t = vim.fn.sign_getdefined('LspDiagnosticSignWarn')
if (vim.tbl_isempty(t) or t[1].text == "W ") and icons.icons == true then
vim.fn.sign_define('LspDiagnosticsSignError',
{text = e, texthl = 'LspDiagnosticsSignError', linehl = '', numhl = ''})
vim.fn.sign_define('LspDiagnosticsSignWarning',
{text = w, texthl = 'LspDiagnosticsSignWarning', linehl = '', numhl = ''})
vim.fn.sign_define('LspDiagnosticsSignInformation', {
text = i,
texthl = 'LspDiagnosticsSignInformation',
linehl = '',
numhl = ''
})
vim.fn.sign_define('LspDiagnosticsSignHint',
{text = h, texthl = 'LspDiagnosticsSignHint', linehl = '', numhl = ''})
end
end end
M.configed = true M.configed = true
end end
function M.add_highlight() function M.add_highlight()
-- lsp system default -- lsp system default
api.nvim_command("hi! link LspDiagnosticsUnderlineError SpellBad") api.nvim_command('hi! link DiagnosticUnderlineError SpellBad')
api.nvim_command("hi! link LspDiagnosticsUnderlineWarning SpellRare") api.nvim_command('hi! link DiagnosticUnderlineWarning SpellRare')
api.nvim_command("hi! link LspDiagnosticsUnderlineInformation SpellRare") api.nvim_command('hi! link DiagnosticUnderlineInformation SpellRare')
api.nvim_command("hi! link LspDiagnosticsUnderlineHint SpellRare") api.nvim_command('hi! link DiagnosticUnderlineHint SpellRare')
api.nvim_command('hi def link NGPreviewTitle Title')
api.nvim_command("hi! link DiagnosticUnderlineError SpellBad")
api.nvim_command("hi! link DiagnosticUnderlineWarning SpellRare")
api.nvim_command("hi! link DiagnosticUnderlineInformation SpellRare")
api.nvim_command("hi! link DiagnosticUnderlineHint SpellRare")
api.nvim_command("hi def link NGPreviewTitle Title")
local colors = { local colors = {
{'#aefe00', '#aede00', '#aebe00', '#4e7efe'}, {'#ff00e0', '#df00e0', '#af00e0', '#fedefe'}, { '#aefe00', '#aede00', '#aebe00', '#4e7efe' },
{'#1000ef', '#2000df', '#2000cf', '#f0f040'}, {'#d8a8a3', '#c8a8a3', '#b8a8a3', '#4e2c33'}, { '#ff00e0', '#df00e0', '#af00e0', '#fedefe' },
{'#ffa724', '#efa024', '#dfa724', '#0040ff'}, {'#afdc2b', '#09dc4b', '#08d04b', '#ef4f8f'} { '#1000ef', '#2000df', '#2000cf', '#f0f040' },
{ '#d8a8a3', '#c8a8a3', '#b8a8a3', '#4e2c33' },
{ '#ffa724', '#efa024', '#dfa724', '#0040ff' },
{ '#afdc2b', '#09dc4b', '#08d04b', '#ef4f8f' },
} }
for i = 1, #colors do for i = 1, #colors do
for j = 1, 3 do for j = 1, 3 do
local cmd = string.format("hi! default NGHiReference_%i_%i guibg=%s guifg=%s ", i, j, local cmd = string.format('hi! default NGHiReference_%i_%i guibg=%s guifg=%s ', i, j, colors[i][j], colors[i][4])
colors[i][j], colors[i][4])
vim.cmd(cmd) vim.cmd(cmd)
end end
end end
vim.cmd([[
autocmd ColorScheme * |
hi default LspReferenceRead cterm=bold gui=Bold ctermbg=yellow guifg=yellow guibg=purple4 |
hi default LspReferenceText cterm=bold gui=Bold ctermbg=red guifg=SlateBlue guibg=MidnightBlue |
hi default LspReferenceWrite cterm=bold gui=Bold,Italic ctermbg=red guifg=DarkSlateBlue guibg=MistyRose
]])
end end
return M return M

@ -1,5 +1,6 @@
local log = require('navigator.util').log local util = require('navigator.util')
local trace = require('navigator.util').trace local log = util.log
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()]] },
@ -13,8 +14,8 @@ local single = { '╭', '─', '╮', '│', '╯', '─', '╰', '│' }
-- TODO https://github.com/neovim/neovim/pull/16591 use vimkeymap.set/del -- TODO https://github.com/neovim/neovim/pull/16591 use vimkeymap.set/del
-- LuaFormatter off -- LuaFormatter off
local key_maps = { local key_maps = {
{ key = 'gr', func = "require('navigator.reference').reference()" }, { key = 'gr', func = "require('navigator.reference').async_ref()" },
{ key = 'Gr', func = "require('navigator.reference').async_ref()" }, { key = '<Leader>gr', func = "require('navigator.reference').reference()" }, -- reference deprecated
{ mode = 'i', key = '<M-k>', func = 'signature_help()' }, { mode = 'i', key = '<M-k>', func = 'signature_help()' },
{ key = '<c-k>', func = 'signature_help()' }, { key = '<c-k>', func = 'signature_help()' },
{ key = 'g0', func = "require('navigator.symbols').document_symbols()" }, { key = 'g0', func = "require('navigator.symbols').document_symbols()" },
@ -39,6 +40,7 @@ local key_maps = {
{ key = '<Leader>dt', func = "require('navigator.diagnostics').toggle_diagnostics()" }, { key = '<Leader>dt', func = "require('navigator.diagnostics').toggle_diagnostics()" },
{ key = ']d', func = "diagnostic.goto_next({ border = 'rounded', max_width = 80})" }, { key = ']d', func = "diagnostic.goto_next({ border = 'rounded', max_width = 80})" },
{ key = '[d', func = "diagnostic.goto_prev({ border = 'rounded', max_width = 80})" }, { key = '[d', func = "diagnostic.goto_prev({ border = 'rounded', max_width = 80})" },
{ key = ']O', func = 'diagnostic.set_loclist()' },
{ key = ']r', func = "require('navigator.treesitter').goto_next_usage()" }, { key = ']r', func = "require('navigator.treesitter').goto_next_usage()" },
{ key = '[r', func = "require('navigator.treesitter').goto_previous_usage()" }, { key = '[r', func = "require('navigator.treesitter').goto_previous_usage()" },
{ key = '<C-LeftMouse>', func = 'definition()' }, { key = '<C-LeftMouse>', func = 'definition()' },
@ -138,8 +140,10 @@ local function set_mapping(user_opts)
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.'
if vim.lsp.diagnostic ~= nil then if vim.diagnostic ~= nil then
diagnostic = '<Cmd>lua vim.lsp.' diagnostic = '<Cmd>lua vim.'
else
util.error('Please update nvim to 0.6.1+')
end end
f = diagnostic .. value.func .. '<CR>' f = diagnostic .. value.func .. '<CR>'
elseif string.find(value.func, 'vim.') then elseif string.find(value.func, 'vim.') then
@ -152,7 +156,7 @@ local function set_mapping(user_opts)
elseif string.find(value.func, 'formatting') then elseif string.find(value.func, 'formatting') then
fmtkey = value.key fmtkey = value.key
end end
log('binding', k, f) trace('binding', k, f)
set_keymap(m, k, f, opts) set_keymap(m, k, f, opts)
end end
@ -172,6 +176,7 @@ local function set_mapping(user_opts)
elseif fmtkey then elseif fmtkey then
del_keymap('n', fmtkey) del_keymap('n', fmtkey)
end end
if user_opts.cap and user_opts.cap.document_range_formatting then if user_opts.cap and user_opts.cap.document_range_formatting then
log('formatting enabled', user_opts.cap) log('formatting enabled', user_opts.cap)
end end
@ -247,7 +252,9 @@ function M.setup(user_opts)
autocmd(user_opts) autocmd(user_opts)
set_event_handler(user_opts) set_event_handler(user_opts)
local cap = user_opts.cap or vim.lsp.protocol.make_client_capabilities() local client = user_opts.client or {}
local cap = client.resolved_capabilities or vim.lsp.protocol.make_client_capabilities()
log('lsp cap:', cap) log('lsp cap:', cap)
if cap.call_hierarchy or cap.callHierarchy then if cap.call_hierarchy or cap.callHierarchy then

@ -1,7 +1,7 @@
local M = {} local M = {}
local util = require('navigator.util') local util = require('navigator.util')
local nvim_0_6 = util.nvim_0_6() local nvim_0_6_1 = util.nvim_0_6_1()
local gutil = require('guihua.util') local gutil = require('guihua.util')
local lsp = require('vim.lsp') local lsp = require('vim.lsp')
@ -145,7 +145,7 @@ function M.call_sync(method, params, opts, handler)
opts = opts or {} opts = opts or {}
local results_lsp, err = lsp.buf_request_sync(0, method, params, opts.timeout or vim.g.navtator_timeout or 1000) local results_lsp, err = lsp.buf_request_sync(0, method, params, opts.timeout or vim.g.navtator_timeout or 1000)
if nvim_0_6() then if nvim_0_6_1() then
handler(err, extract_result(results_lsp), { method = method }, nil) handler(err, extract_result(results_lsp), { method = method }, nil)
else else
handler(err, method, extract_result(results_lsp), nil, nil) handler(err, method, extract_result(results_lsp), nil, nil)
@ -263,6 +263,10 @@ end
local function order_locations(locations) local function order_locations(locations)
table.sort(locations, function(i, j) table.sort(locations, function(i, j)
if i == nil or j == nil or i.uri == nil or j.uri == nil then
-- log(i, j)
return false
end
if i.uri == j.uri then if i.uri == j.uri then
if i.range and i.range.start then if i.range and i.range.start then
return i.range.start.line < j.range.start.line return i.range.start.line < j.range.start.line
@ -337,9 +341,9 @@ function M.locations_to_items(locations, ctx)
for i, loc in ipairs(locations) do for i, loc in ipairs(locations) do
local funcs = nil local funcs = nil
local item = lsp.util.locations_to_items({ loc }, enc)[1] local item = lsp.util.locations_to_items({ loc }, enc)[1]
-- log(item)
item.range = locations[i].range or locations[i].targetRange item.range = locations[i].range or locations[i].targetRange
item.uri = locations[i].uri or locations[i].targetUri item.uri = locations[i].uri or locations[i].targetUri
item.definition = locations[i].definition
if is_win then if is_win then
log(item.uri) -- file:///C:/path/to/file log(item.uri) -- file:///C:/path/to/file
@ -416,6 +420,7 @@ function M.locations_to_items(locations, ctx)
vim.cmd([[set eventignore-=FileType]]) vim.cmd([[set eventignore-=FileType]])
log(items)
return items, width + 24, second_part -- TODO handle long line? return items, width + 24, second_part -- TODO handle long line?
end end
@ -431,6 +436,9 @@ function M.symbol_to_items(locations)
if i.definition then if i.definition then
return true return true
end end
if j.definition then
return false
end
if i.uri == j.uri then if i.uri == j.uri then
if i.range and i.range.start then if i.range and i.range.start then
return i.range.start.line < j.range.start.line return i.range.start.line < j.range.start.line

@ -22,29 +22,41 @@ local ref_view = function(err, locations, ctx, cfg)
if ctx.results == nil then if ctx.results == nil then
return return
end end
if #ctx.results.definitions.result == nil or ctx.results.references.result == nil then if (ctx.results.definitions == nil) or (ctx.results.references == nil) then
log('not all requests returned') log('not all requests returned')
return return
end end
local definitions = ctx.results.definitions local definitions = ctx.results.definitions
local references = ctx.results.references local references = ctx.results.references
log(ctx)
if definitions.error and references.error then if definitions.error and references.error then
vim.notify('lsp ref callback error' .. vim.inspect(ctx.result), vim.lsp.log_levels.WARN) vim.notify('lsp ref callback error' .. vim.inspect(ctx.result), vim.lsp.log_levels.WARN)
end end
locations = {} locations = {}
if definitions.result then if definitions and definitions.result then
for i, _ in ipairs(definitions.result) do for i, _ in ipairs(definitions.result) do
definitions.result[i].definition = true definitions.result[i].definition = true
end end
vim.list_extend(locations, definitions.result) vim.list_extend(locations, definitions.result)
end end
if references.result then if references and references.result and #references.result > 0 then
vim.list_extend(locations, references.result) local refs = references.result
for _, value in pairs(locations) do
vrange = value.range or { start = { line = 0 }, ['end'] = { line = 0 } }
for i = 1, #refs, 1 do
local rg = refs[i].range or {}
log(value, refs[i])
log(rg, vrange)
if rg.start.line == vrange.start.line and rg['end'].line == vrange['end'].line then
table.remove(refs, i)
break
end
end
end
vim.list_extend(locations, refs)
end end
ctx = references.ctx or definitions.ctx
err = nil err = nil
cfg = references.config or definitions.config log(locations)
trace(ctx, locations)
end end
-- log("num", num) -- log("num", num)
-- log("bfnr", bufnr) -- log("bfnr", bufnr)
@ -63,7 +75,7 @@ local ref_view = function(err, locations, ctx, cfg)
return return
end end
if locations == nil or vim.tbl_isempty(locations) then if locations == nil or vim.tbl_isempty(locations) then
vim.notify('References not found', vim.lsp.log_levels.WARN) vim.notify('References not found', vim.lsp.log_levels.INFO)
return return
end end
@ -137,11 +149,17 @@ end)
local async_ref = function() local async_ref = function()
local ref_params = vim.lsp.util.make_position_params() local ref_params = vim.lsp.util.make_position_params()
local results = { definitions = {}, references = {} } local results = {}
ref_params.context = { includeDeclaration = false } ref_params.context = { includeDeclaration = false }
lsp.call_async('textDocument/definition', ref_params, function(err, result, ctx, config) lsp.call_async('textDocument/definition', ref_params, function(err, result, ctx, config)
trace(err, result, ctx, config) trace(err, result, ctx, config)
for i = 1, #result do
if result[i].range == nil and result[i].targetRange then
result[i].range = result[i].targetRange
end
end
results.definitions = { error = err, result = result, ctx = ctx, config = config } results.definitions = { error = err, result = result, ctx = ctx, config = config }
log(result)
ctx = ctx or {} ctx = ctx or {}
ctx.results = results ctx.results = results
ctx.combine = true ctx.combine = true

@ -1,16 +1,16 @@
local log = require"guihua.log".info local log = require('guihua.log').info
local trace = require"guihua.log".trace local trace = require('guihua.log').trace
local M = {} local M = {}
local clone = require'guihua.util'.clone local clone = require('guihua.util').clone
local function filename(url) local function filename(url)
if url == nil then if url == nil then
return '' return ''
end end
return url:match("^.+/(.+)$") or url return url:match('^.+/(.+)$') or url
end end
local function extension(url) local function extension(url)
local ext = url:match("^.+(%..+)$") or "txt" local ext = url:match('^.+(%..+)$') or 'txt'
return string.sub(ext, 2) return string.sub(ext, 2)
end end
@ -38,7 +38,6 @@ local function get_pads(win_width, text, postfix)
i = i + rem * 10 i = i + rem * 10
-- log(i) -- log(i)
end end
end end
if i > 3 then if i > 3 then
@ -52,18 +51,18 @@ end
function M.prepare_for_render(items, opts) function M.prepare_for_render(items, opts)
opts = opts or {} opts = opts or {}
if items == nil or #items < 1 then if items == nil or #items < 1 then
vim.notify("no item found or empty fields", vim.lsp.log_levels.INFO) vim.notify('no item found or empty fields', vim.lsp.log_levels.INFO)
return return
end end
local item = clone(items[1]) local item = clone(items[1])
local display_items = {item} local display_items = { item }
local last_summary_idx = 1 local last_summary_idx = 1
local total_ref_in_file = 1 local total_ref_in_file = 1
local total = opts.total local total = opts.total
local icon = "" local icon = ''
local lspapi = opts.api or "" local lspapi = opts.api or ''
local ok, devicons = pcall(require, "nvim-web-devicons") local ok, devicons = pcall(require, 'nvim-web-devicons')
if ok then if ok then
local fn = filename(items[1].filename) local fn = filename(items[1].filename)
local ext = extension(fn) local ext = extension(fn)
@ -85,7 +84,7 @@ function M.prepare_for_render(items, opts)
local space local space
local trim local trim
local lspapi_display = lspapi local lspapi_display = lspapi
items[i].symbol_name = items[i].symbol_name or "" -- some LSP API does not have range for this items[i].symbol_name = items[i].symbol_name or '' -- some LSP API does not have range for this
local fn = display_items[last_summary_idx].filename local fn = display_items[last_summary_idx].filename
local dfn = items[i].display_filename local dfn = items[i].display_filename
@ -103,13 +102,18 @@ function M.prepare_for_render(items, opts)
if trim and opts.width > 50 and #dfn > opts.width - 20 then if trim and opts.width > 50 and #dfn > opts.width - 20 then
local fn1 = string.sub(dfn, 1, opts.width - 50) local fn1 = string.sub(dfn, 1, opts.width - 50)
local fn2 = string.sub(dfn, #dfn - 10, #dfn) local fn2 = string.sub(dfn, #dfn - 10, #dfn)
display_items[last_summary_idx].display_filename = fn1 .. "" .. fn2 display_items[last_summary_idx].display_filename = fn1 .. '' .. fn2
space = ' ' space = ' '
-- log("trim", fn1, fn2) -- log("trim", fn1, fn2)
end end
local api_disp = string.format("%s %s%s%s %i", icon, local api_disp = string.format(
display_items[last_summary_idx].display_filename, space, '%s %s%s%s %i',
lspapi_display, total_ref_in_file) icon,
display_items[last_summary_idx].display_filename,
space,
lspapi_display,
total_ref_in_file
)
if total then if total then
api_disp = api_disp .. ' of: ' .. tostring(total) api_disp = api_disp .. ' of: ' .. tostring(total)
@ -118,20 +122,17 @@ function M.prepare_for_render(items, opts)
display_items[last_summary_idx].text = api_disp display_items[last_summary_idx].text = api_disp
total_ref_in_file = total_ref_in_file + 1 total_ref_in_file = total_ref_in_file + 1
else else
lspapi_display = lspapi lspapi_display = lspapi
item = clone(items[i]) item = clone(items[i])
space, trim = get_pads(opts.width, icon .. ' ' .. item.display_filename, space, trim = get_pads(opts.width, icon .. ' ' .. item.display_filename, lspapi_display .. ' 12 of 33')
lspapi_display .. ' 12 of 33')
if trim and opts.width > 52 and #item.display_filename > opts.width - 20 then if trim and opts.width > 52 and #item.display_filename > opts.width - 20 then
item.display_filename = string.sub(item.display_filename, 1, opts.width - 52) .. "" item.display_filename = string.sub(item.display_filename, 1, opts.width - 52)
.. string.sub(item.display_filename, .. ''
#item.display_filename - 10, .. string.sub(item.display_filename, #item.display_filename - 10, #item.display_filename)
#item.display_filename)
space = ' ' space = ' '
end end
item.text = string.format("%s %s%s%s 1", icon, item.display_filename, space, lspapi_display) item.text = string.format('%s %s%s%s 1', icon, item.display_filename, space, lspapi_display)
trace(item.text) trace(item.text)
table.insert(display_items, item) table.insert(display_items, item)
@ -140,14 +141,16 @@ function M.prepare_for_render(items, opts)
end end
-- content of code lines -- content of code lines
item = clone(items[i]) item = clone(items[i])
item.text = require'navigator.util'.trim_and_pad(item.text) item.text = require('navigator.util').trim_and_pad(item.text)
item.text = string.format("%4i: %s", item.lnum, item.text) item.text = string.format('%4i: %s', item.lnum, item.text)
local ts_report = "" local ts_report = ''
if item.lhs then if item.lhs then
ts_report = _NgConfigValues.icons.value_changed ts_report = _NgConfigValues.icons.value_changed
end end
log(item)
if item.definition then if item.definition then
log('definition', item)
ts_report = ts_report .. _NgConfigValues.icons.value_definition .. ' ' ts_report = ts_report .. _NgConfigValues.icons.value_definition .. ' '
end end
local header_len = #ts_report + 4 -- magic number 2 local header_len = #ts_report + 4 -- magic number 2
@ -155,7 +158,7 @@ function M.prepare_for_render(items, opts)
item.text = item.text:gsub('%s*[%[%(%{]*%s*$', '') item.text = item.text:gsub('%s*[%[%(%{]*%s*$', '')
if item.call_by ~= nil and #item.call_by > 0 then if item.call_by ~= nil and #item.call_by > 0 then
trace("call_by:", #item.call_by) trace('call_by:', #item.call_by)
for _, value in pairs(item.call_by) do for _, value in pairs(item.call_by) do
if value.node_text then if value.node_text then
local txt = value.node_text:gsub('%s*[%[%(%{]*%s*$', '') local txt = value.node_text:gsub('%s*[%[%(%{]*%s*$', '')
@ -183,15 +186,15 @@ function M.prepare_for_render(items, opts)
if #ts_report > 1 then if #ts_report > 1 then
space, trim = get_pads(win_width, item.text, ts_report) space, trim = get_pads(win_width, item.text, ts_report)
if trim then if trim then
item.text = string.sub(item.text, 1, opts.width - 20) .. "" item.text = string.sub(item.text, 1, opts.width - 20) .. ''
end end
if #space + #item.text + #ts_report >= win_width then if #space + #item.text + #ts_report >= win_width then
if #item.text + #ts_report > win_width then if #item.text + #ts_report > win_width then
trace("exceeding", #item.text, #ts_report, win_width) trace('exceeding', #item.text, #ts_report, win_width)
space = ' ' space = ' '
else else
local remain = win_width - #item.text - #ts_report local remain = win_width - #item.text - #ts_report
trace("remain", remain) trace('remain', remain)
space = string.rep(' ', remain) space = string.rep(' ', remain)
end end
end end

@ -3,8 +3,8 @@
-- Some of function copied from https://github.com/RishabhRD/nvim-lsputils -- Some of function copied from https://github.com/RishabhRD/nvim-lsputils
local M = { log_path = vim.lsp.get_log_path() } local M = { log_path = vim.lsp.get_log_path() }
-- local is_windows = uv.os_uname().version:match("Windows") -- local is_windows = uv.os_uname().version:match("Windows")
local guihua = require('guihua.util')
local nvim_0_6 local nvim_0_6_1
M.path_sep = function() M.path_sep = function()
local is_win = vim.loop.os_uname().sysname:find('Windows') local is_win = vim.loop.os_uname().sysname:find('Windows')
@ -281,19 +281,7 @@ M.open_file = function(filename)
vim.api.nvim_command(string.format('e! %s', filename)) vim.api.nvim_command(string.format('e! %s', filename))
end end
M.open_file_at = function(filename, line, col, split) M.open_file_at = guihua.open_file_at
if split == nil then
-- code
vim.api.nvim_command(string.format('e! +%s %s', line, filename))
elseif split == 'v' then
vim.api.nvim_command(string.format('vsp! +%s %s', line, filename))
elseif split == 's' then
vim.api.nvim_command(string.format('sp! +%s %s', line, filename))
end
-- vim.api.nvim_command(string.format("e! %s", filename))
col = col or 1
vim.fn.cursor(line, col)
end
function M.exists(var) function M.exists(var)
for k, _ in pairs(_G) do for k, _ in pairs(_G) do
@ -355,32 +343,21 @@ function M.get_current_winid()
return api.nvim_get_current_win() return api.nvim_get_current_win()
end end
function M.nvim_0_6() function M.nvim_0_6_1()
if nvim_0_6 ~= nil then if nvim_0_6_1 ~= nil then
return nvim_0_6 return nvim_0_6_1
end end
if debug.getinfo(vim.lsp.handlers.signature_help).nparams == 4 then nvim_0_6_1 = vim.fn.has('nvim-0.6.1') == 1
nvim_0_6 = true if nvim_0_6_1 == false then
else M.warn('Please use navigator 0.3 version for neovim version < 0.6.1')
nvim_0_6 = false
end end
return nvim_0_6 return nvim_0_6_1
end end
function M.mk_handler(fn) function M.mk_handler(fn)
return function(...) return function(...)
local config_or_client_id = select(4, ...) if M.nvim_0_6_1() then
local is_new = M.nvim_0_6()
if is_new then
return fn(...) return fn(...)
else
local err = select(1, ...)
local method = select(2, ...)
local result = select(3, ...)
local client_id = select(4, ...)
local bufnr = select(5, ...)
local config = select(6, ...)
return fn(err, result, { method = method, client_id = client_id, bufnr = bufnr }, config)
end end
end end
end end
@ -422,15 +399,15 @@ end
-- alternatively: use vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR) -- alternatively: use vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR)
function M.warn(msg) function M.warn(msg)
vim.api.nvim_echo({ { 'WRN: ' .. msg, 'WarningMsg' } }, true, {}) vim.notify('WRN: ' .. msg, vim.lsp.log_levels.WARN)
end end
function M.error(msg) function M.error(msg)
vim.api.nvim_echo({ { 'ERR: ' .. msg, 'ErrorMsg' } }, true, {}) vim.notify('ERR: ' .. msg, vim.lsp.log_levels.EROR)
end end
function M.info(msg) function M.info(msg)
vim.api.nvim_echo({ { 'Info: ' .. msg } }, true, {}) vim.notify('INF: ' .. msg, vim.lsp.log_levels.INFO)
end end
return M return M

@ -12,13 +12,14 @@ most used plugins for programmer.
- luasnip - luasnip
- aurora (colorscheme used in the screenshot) - aurora (colorscheme used in the screenshot)
There also three folder `js`, `go`, `py`. Those folder have some basic source code you can play with. There are three folders `js`, `go`, `py`. Those folders have some basic source code you can play with.
The init will install the plugins in ``/tmp/nvim`` folder. It will not affect your current setup.
## Install LSP ## Install LSP
The playground has js, py, go folder, so you can install either one your self in your PATH. The playground has js, py, go folder, so you can install either one your self in your PATH.
If you want to try lua, Please check sumneko setup in init.lua make sure it pointed to correct path. By default it If you want to try lua, Please check sumneko setup in init.lua make sure it pointed to correct path. By default it
potint to ~/github/sumneko potint to ~/github/sumneko if not existed in your PATH.
## run init.lua ## run init.lua

@ -10,7 +10,7 @@ local sumneko_root_path = vim.fn.expand('$HOME') .. '/github/sumneko/lua-languag
local sumneko_binary = vim.fn.expand('$HOME') .. '/github/sumneko/lua-language-server/bin/macOS/lua-language-server' local sumneko_binary = vim.fn.expand('$HOME') .. '/github/sumneko/lua-language-server/bin/macOS/lua-language-server'
local lua_cfg = { local lua_cfg = {
cmd = { sumneko_binary, '-E', sumneko_root_path .. '/main.lua' }, -- cmd = { sumneko_binary, '-E', sumneko_root_path .. '/main.lua' },
settings = { settings = {
Lua = { Lua = {
runtime = { version = 'LuaJIT', path = vim.split(package.path, ';') }, runtime = { version = 'LuaJIT', path = vim.split(package.path, ';') },
@ -19,6 +19,10 @@ local lua_cfg = {
}, },
} }
if vim.fn.executable('lua-language-server') == 0 then
lua_cfg.cmd = { sumneko_binary, '-E', sumneko_root_path .. '/main.lua' }
end
local function load_plugins() local function load_plugins()
require('packer').startup({ require('packer').startup({
function(use) function(use)

@ -0,0 +1,14 @@
from random import shuffle
a = list(range(5))
def go(beg, c, b):
if beg >= len(a):
print(a )
for i in range(beg, len(a)):
a[beg], a[i] = a[i], a[beg]
go(beg + 1)
a[beg], a[i] = a[i], a[beg]
print(a, b)
go(0, 1, 4)
shuffle([1, 2,3 ])
Loading…
Cancel
Save