empty func

neovim_0.6
ray-x 2 years ago
parent ecc1f2d28a
commit aa9b80e848

@ -1,16 +1,17 @@
local gui = require "navigator.gui"
local gui = require('navigator.gui')
local diagnostic_list = {}
local diagnostic = vim.diagnostic or vim.lsp.diagnostic
-- local hide = diagnostic.hide or diagnostic.clear
_NG_VT_DIAG_NS = vim.api.nvim_create_namespace("navigator_lua_diag")
local util = require "navigator.util"
_NG_VT_DIAG_NS = vim.api.nvim_create_namespace('navigator_lua_diag')
local util = require('navigator.util')
local log = util.log
local trace = require"guihua.log".trace
local trace = require('guihua.log').trace
-- trace = log
local error = util.error
local path_sep = require"navigator.util".path_sep()
local mk_handler = require"navigator.util".mk_handler
local path_cur = require"navigator.util".path_cur()
local path_sep = require('navigator.util').path_sep()
local mk_handler = require('navigator.util').mk_handler
local path_cur = require('navigator.util').path_cur()
local empty = util.empty
diagnostic_list[vim.bo.filetype] = {}
local function clear_diag_VT(bufnr) -- important for clearing out when no more errors
log(bufnr, _NG_VT_DIAG_NS)
@ -28,21 +29,24 @@ if vim.diagnostic then
Error = vim.diagnostic.severity.ERROR,
Warning = vim.diagnostic.severity.WARN,
Info = vim.diagnostic.severity.Info,
Hint = vim.diagnostic.severity.Hint
Hint = vim.diagnostic.severity.Hint,
}
end
local function get_count(bufnr, level)
if vim.diagnostic ~= nil then
return #diagnostic.get(bufnr, {severity = diag_map[level]})
return #diagnostic.get(bufnr, { severity = diag_map[level] })
else
return diagnostic.get_count(bufnr, level)
end
end
local function error_marker(result, ctx, config)
if _NgConfigValues.lsp.diagnostic_scrollbar_sign == nil or _NgConfigValues.lsp.diagnostic_scrollbar_sign == {}
or _NgConfigValues.lsp.diagnostic_scrollbar_sign == false then -- not enabled or already shown
if
_NgConfigValues.lsp.diagnostic_scrollbar_sign == nil
or empty(_NgConfigValues.lsp.diagnostic_scrollbar_sign)
or _NgConfigValues.lsp.diagnostic_scrollbar_sign == false
then -- not enabled or already shown
return
end
@ -60,14 +64,13 @@ local function error_marker(result, ctx, config)
local fname = vim.api.nvim_buf_get_name(bufnr)
local uri = vim.uri_from_fname(fname)
if uri ~= result.uri then
log("not same buf", ctx, result.uri, bufnr, vim.fn.bufnr())
log('not same buf', ctx, result.uri, bufnr, vim.fn.bufnr())
return
end
if not vim.api.nvim_buf_is_loaded(bufnr) then
log("buf not loaded", bufnr)
log('buf not loaded', bufnr)
return
end
trace('schedule callback', result, ctx, config)
@ -76,7 +79,7 @@ local function error_marker(result, ctx, config)
if result == nil or result.diagnostics == nil or #result.diagnostics == 0 then
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]])
if diag_cnt == 0 and _NG_VT_DIAG_NS ~= nil then
log("great no errors")
log('great no errors')
vim.api.nvim_buf_clear_namespace(bufnr, _NG_VT_DIAG_NS, 0, -1)
end
return
@ -92,13 +95,13 @@ local function error_marker(result, ctx, config)
local stats = vim.api.nvim_list_uis()[1]
-- local wwidth = stats.width;
local wheight = stats.height;
local wheight = stats.height
if total_num <= wheight then
return
end
if _NG_VT_DIAG_NS == nil then
_NG_VT_DIAG_NS = vim.api.nvim_create_namespace("navigator_lua_diag")
_NG_VT_DIAG_NS = vim.api.nvim_create_namespace('navigator_lua_diag')
end
local pos = {}
@ -106,7 +109,7 @@ local function error_marker(result, ctx, config)
for i, _ in ipairs(diags) do
if not diags[i].range then
diags[i].range = {start = {line = diags[i].lnum}}
diags[i].range = { start = { line = diags[i].lnum } }
end
end
@ -117,7 +120,7 @@ local function error_marker(result, ctx, config)
for _, diag in pairs(result.diagnostics) do
local p
if not diag.range then
diag.range = {start = {line = diag.lnum}}
diag.range = { start = { line = diag.lnum } }
end
if diag.range and diag.range.start and diag.range.start.line then
p = diag.range.start.line
@ -127,17 +130,16 @@ local function error_marker(result, ctx, config)
if pos[#pos] == bar then
bar = _NgConfigValues.lsp.diagnostic_scrollbar_sign[3]
end
pos[#pos] = {line = p, sign = bar, severity = math.min(diag.severity, pos[#pos].severity)}
pos[#pos] = { line = p, sign = bar, severity = math.min(diag.severity, pos[#pos].severity) }
else
table.insert(pos,
{
table.insert(pos, {
line = p,
sign = _NgConfigValues.lsp.diagnostic_scrollbar_sign[1],
severity = diag.severity
severity = diag.severity,
})
end
end
trace("pos, line:", p, diag.severity, diag.range)
trace('pos, line:', p, diag.severity, diag.range)
end
if not vim.tbl_isempty(pos) then
@ -145,38 +147,41 @@ local function error_marker(result, ctx, config)
end
for i, s in pairs(pos) do
local hl = 'ErrorMsg'
if type(s.severity) == "number" then
if type(s.severity) == 'number' then
if s.severity == 2 then
hl = 'WarningMsg'
elseif s.severity >= 3 then
hl = 'DiagnosticInfo'
end
elseif type(s.severity) == "string" then
if s.severity:lower() == "warn" then
hl = "WarningMsg"
elseif type(s.severity) == 'string' then
if s.severity:lower() == 'warn' then
hl = 'WarningMsg'
end
end
local l = s.line + first_line
if l > total_num then
l = total_num
end
trace("add pos", s, bufnr)
vim.api.nvim_buf_set_extmark(bufnr, _NG_VT_DIAG_NS, l, -1,
{virt_text = {{s.sign, hl}}, virt_text_pos = 'right_align'})
trace('add pos', s, bufnr)
vim.api.nvim_buf_set_extmark(
bufnr,
_NG_VT_DIAG_NS,
l,
-1,
{ virt_text = { { s.sign, hl } }, virt_text_pos = 'right_align' }
)
end
end, 10) -- defer in 10ms
end
local update_err_marker_async = function()
local debounce = require'navigator.debounce'.debounce_trailing
local debounce = require('navigator.debounce').debounce_trailing
return debounce(400, error_marker)
end
local diag_hdlr = mk_handler(function(err, result, ctx, config)
require"navigator.lspclient.highlight".diagnositc_config_sign()
require('navigator.lspclient.highlight').diagnositc_config_sign()
if err ~= nil then
log(err, config, result)
return
@ -184,7 +189,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
local mode = vim.api.nvim_get_mode().mode
if mode ~= 'n' and config.update_in_insert == false then
log("skip sign update in insert mode")
log('skip sign update in insert mode')
end
local cwd = vim.loop.cwd()
local ft = vim.bo.filetype
@ -202,15 +207,15 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
trace(err, result, ctx, config)
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
else
log("old version of lsp nvim 050")
log('old version of lsp nvim 050')
vim.lsp.diagnostic.on_publish_diagnostics(err, _, result, ctx.client_id, _, config)
end
local uri = result.uri
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]])
if result.diagnostics == {} and diag_cnt > 0 then
log("no result? ", diag_cnt)
if empty(result.diagnostics) and diag_cnt > 0 then
log('no result? ', diag_cnt)
return
end
-- trace("diag: ", mode, result, ctx, config)
@ -253,11 +258,11 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
end
local pos = v.range.start
local row = pos.line
local line = (vim.api.nvim_buf_get_lines(bufnr1, row, row + 1, false) or {""})[1]
local line = (vim.api.nvim_buf_get_lines(bufnr1, row, row + 1, false) or { '' })[1]
if line ~= nil then
item.text = head .. line .. _NgConfigValues.icons.diagnostic_head_description .. v.message
else
error("diagnostic result empty line", v, row, bufnr1)
error('diagnostic result empty line', v, row, bufnr1)
end
else
item.text = head .. _NgConfigValues.icons.diagnostic_head_description .. v.message
@ -268,7 +273,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
end
if v.releated_lnum then
item.text = item.text .. ":" .. tostring(item.releated_lnum)
item.text = item.text .. ':' .. tostring(item.releated_lnum)
end
table.insert(item_list, item)
@ -286,15 +291,14 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
local marker = update_err_marker_async()
marker(result, ctx, config)
else
trace("great, no diag errors")
trace('great, no diag errors')
vim.api.nvim_buf_clear_namespace(0, _NG_VT_DIAG_NS, 0, -1)
_NG_VT_DIAG_NS = nil
end
end)
local diag_hdlr_async = function()
local debounce = require'navigator.debounce'.debounce_trailing
local debounce = require('navigator.debounce').debounce_trailing
return debounce(100, diag_hdlr)
end
@ -303,12 +307,12 @@ local diagnostic_cfg = {
-- Enable underline, use default values
underline = true,
-- Enable virtual text, override spacing to 3 (prevent overlap)
virtual_text = {spacing = 3, prefix = _NgConfigValues.icons.diagnostic_virtual_text},
virtual_text = { spacing = 3, 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 = {reverse = true}
severity_sort = { reverse = true },
}
if _NgConfigValues.lsp.diagnostic_virtual_text == false then
@ -351,10 +355,10 @@ M.show_buf_diagnostics = function()
if #display_items > 0 then
local listview = gui.new_list_view({
items = display_items,
api = _NgConfigValues.icons.diagnostic_file .. _NgConfigValues.icons.diagnostic_head .. " Diagnostic ",
enable_preview_edit = true
api = _NgConfigValues.icons.diagnostic_file .. _NgConfigValues.icons.diagnostic_head .. ' Diagnostic ',
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)
end
end
@ -362,15 +366,14 @@ end
-- set loc list win
M.set_diag_loclist = function()
local bufnr = vim.api.nvim_get_current_buf()
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]])
if diag_cnt == 0 then
log("great, no errors!")
log('great, no errors!')
return
end
local clients = vim.lsp.buf_get_clients(0)
local cfg = {open = diag_cnt > 0}
local cfg = { open = diag_cnt > 0 }
for _, client in pairs(clients) do
cfg.client_id = client['id']
break
@ -386,68 +389,69 @@ M.set_diag_loclist = function()
diagnostic.setloclist(cfg)
end
else
vim.cmd("lclose")
vim.cmd('lclose')
end
end
end
-- TODO: callback when scroll
function M.update_err_marker()
trace("update err marker", _NG_VT_DIAG_NS)
trace('update err marker', _NG_VT_DIAG_NS)
if _NG_VT_DIAG_NS == nil then
-- nothing to update
return
end
local bufnr = vim.api.nvim_get_current_buf()
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]]) + get_count(bufnr, [[Info]])
+ get_count(bufnr, [[Hint]])
local diag_cnt = get_count(bufnr, [[Error]])
+ get_count(bufnr, [[Warning]])
+ get_count(bufnr, [[Info]])
+ get_count(bufnr, [[Hint]])
-- redraw
if diag_cnt == 0 and _NG_VT_DIAG_NS ~= nil then
vim.api.nvim_buf_clear_namespace(bufnr, _NG_VT_DIAG_NS, 0, -1)
trace("no errors")
trace('no errors')
return
end
vim.api.nvim_buf_clear_namespace(bufnr, _NG_VT_DIAG_NS, 0, -1)
local errors = diagnostic.get(bufnr)
if #errors == 0 then
trace("no errors", errors)
trace('no errors', errors)
return
end
local uri = vim.uri_from_bufnr(bufnr)
local result = {diagnostics = errors, uri = errors[1].uri or uri}
local result = { diagnostics = errors, uri = errors[1].uri or uri }
trace(result)
local marker = update_err_marker_async()
marker(result, {bufnr = bufnr, method = 'textDocument/publishDiagnostics'})
marker(result, { bufnr = bufnr, method = 'textDocument/publishDiagnostics' })
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)
vim.notify('config deprecated, set lsp.diagnostic_scrollbar_sign instead', vim.lsp.log_levels.WARN)
end
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
function M.get_line_diagnostic()
local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
return diagnostic.get(vim.api.nvim_get_current_buf(), {lnum = lnum})
return diagnostic.get(vim.api.nvim_get_current_buf(), { lnum = lnum })
end
function M.show_diagnostics(pos)
local bufnr = vim.api.nvim_get_current_buf()
local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
local opt = {border = 'single'}
if diagnostic.open_float and type(diagnostic.open_float) == "function" then
local opt = { border = 'single' }
if diagnostic.open_float and type(diagnostic.open_float) == 'function' then
if pos == true then
opt.scope = "cursor"
opt.scope = 'cursor'
else
opt.scope = "line"
opt.scope = 'line'
end
diagnostic.open_float(bufnr, opt)
else

@ -10,8 +10,7 @@ _NG_ref_hi_idx = 1
-- extract symbol from cursor
local function get_symbol()
local currentWord = vim.fn.expand('<cword>')
return currentWord
return vim.fn.expand('<cword>')
end
local function add_locs(bufnr, result)
@ -21,7 +20,7 @@ local function add_locs(bufnr, result)
end
symbol = string.format('%s_%i_%i_%i', symbol, bufnr, result[1].range.start.line, result[1].range.start.character)
if _NG_hi_list[symbol] == nil then
_NG_hi_list[symbol] = { range = {} }
_NG_hi_list[symbol] = {range = {}}
end
if _NG_hi_list[symbol] ~= nil then
trace('already added', symbol)
@ -107,8 +106,8 @@ local function hi_symbol()
end
local w = value.range['end'].character - value.range.start.character
local hi_name = string.format('NGHiReference_%i_%i', _NG_ref_hi_idx, k)
trace(hi_name, { l, cs, w })
local m = vim.fn.matchaddpos(hi_name, { { l, cs, w } }, 10)
trace(hi_name, {l, cs, w})
local m = vim.fn.matchaddpos(hi_name, {{l, cs, w}}, 10)
table.insert(_NG_hi_list[symbol].hi_ids, m)
end
end
@ -159,7 +158,7 @@ end)
-- modify from vim-illuminate
local function goto_adjent_reference(opt)
trace(opt)
opt = vim.tbl_extend('force', { forward = true, wrap = true }, opt or {})
opt = vim.tbl_extend('force', {forward = true, wrap = true}, opt or {})
local bufnr = vim.api.nvim_get_current_buf()
local refs = references[bufnr]
@ -170,7 +169,7 @@ local function goto_adjent_reference(opt)
local next = nil
local nexti = nil
local crow, ccol = unpack(vim.api.nvim_win_get_cursor(0))
local crange = { start = { line = crow - 1, character = ccol } }
local crange = {start = {line = crow - 1, character = ccol}}
for i, ref in ipairs(refs) do
local range = ref.range
@ -193,7 +192,7 @@ local function goto_adjent_reference(opt)
end
trace(next)
vim.api.nvim_win_set_cursor(0, { next.start.line + 1, next.start.character })
vim.api.nvim_win_set_cursor(0, {next.start.line + 1, next.start.character})
return next
end
@ -215,8 +214,7 @@ _G.nav_doc_hl = function()
end
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 |
@ -227,9 +225,7 @@ local function documentHighlight()
autocmd CursorHold <buffer> lua nav_doc_hl()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
false
)
]], false)
vim.lsp.handlers['textDocument/documentHighlight'] = mk_handler(function(err, result, ctx)
local bufnr = ctx.bufnr or api.nvim_get_current_buf()
if err then
@ -261,5 +257,5 @@ return {
handle_document_highlight = handle_document_highlight,
hi_symbol = hi_symbol,
nohl = nohl,
cmd_nohl = cmd_nohl,
cmd_nohl = cmd_nohl
}

@ -1,9 +1,10 @@
-- todo allow config passed in
local log = require('navigator.util').log
local trace = require('navigator.util').trace
local util = require('navigator.util')
local log = util.log
local trace = util.trace
local uv = vim.loop
local warn = require('navigator.util').warn
local empty = util.empty
local warn = util.warn
_NG_Loaded = {}
_LoadedFiletypes = {}
@ -457,7 +458,12 @@ local function lsp_startup(ft, retry, user_lsp_opts)
local default_config = {}
log(lspclient)
if lspconfig[lspclient] == nil then
vim.notify('lspclient', lspclient, 'no longer support by lspconfig, please submit an issue', vim.lsp.log_levels.WARN)
vim.notify(
'lspclient',
lspclient,
'no longer support by lspconfig, please submit an issue',
vim.lsp.log_levels.WARN
)
goto continue
end
@ -525,7 +531,11 @@ local function lsp_startup(ft, retry, user_lsp_opts)
end
cfg.on_init = function(client)
if client and client.config and client.config.settings then
client.notify('workspace/didChangeConfiguration', { settings = client.config.settings }, vim.lsp.log_levels.WARN)
client.notify(
'workspace/didChangeConfiguration',
{ settings = client.config.settings },
vim.lsp.log_levels.WARN
)
end
end
end
@ -711,7 +721,7 @@ function on_filetype()
log(uri)
local wids = vim.fn.win_findbuf(bufnr)
if wins == nil or wins == {} then
if empty(wins) then
log('buf not shown return')
end
setup()

@ -1,28 +1,28 @@
-- retreives data form file
-- and line to highlight
-- 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 nvim_0_6
M.path_sep = function()
local is_win = vim.loop.os_uname().sysname:find("Windows")
local is_win = vim.loop.os_uname().sysname:find('Windows')
if is_win then
return "\\"
return '\\'
else
return "/"
return '/'
end
end
local path_sep = M.path_sep()
M.path_cur = function()
local is_win = vim.loop.os_uname().sysname:find("Windows")
local is_win = vim.loop.os_uname().sysname:find('Windows')
if is_win then
return ".\\"
return '.\\'
else
return "./"
return './'
end
end
@ -39,7 +39,7 @@ function M.get_data_from_file(filename, startLine)
startLine = startLine - 2
displayLine = 2
end
local uri = "file:///" .. filename
local uri = 'file:///' .. filename
local bufnr = vim.uri_to_bufnr(uri)
if not vim.api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr)
@ -51,11 +51,11 @@ function M.get_data_from_file(filename, startLine)
local len = #data
startLine = startLine + 1
for i = 1, len, 1 do
data[i] = startLine .. " " .. data[i]
data[i] = startLine .. ' ' .. data[i]
startLine = startLine + 1
end
end
return {data = data, line = displayLine}
return { data = data, line = displayLine }
end
M.merge = function(t1, t2)
@ -66,12 +66,12 @@ M.merge = function(t1, t2)
end
M.map = function(modes, key, result, options)
options = M.merge({noremap = true, silent = false, expr = false, nowait = false}, options or {})
options = M.merge({ noremap = true, silent = false, expr = false, nowait = false }, options or {})
local buffer = options.buffer
options.buffer = nil
if type(modes) ~= "table" then
modes = {modes}
if type(modes) ~= 'table' then
modes = { modes }
end
for i = 1, #modes do
@ -132,7 +132,7 @@ function M.get_relative_path(base_path, my_path)
end
cur = i
end
local data = ""
local data = ''
for i = cur + 1, my_len do
data = data .. my_data[i] .. path_sep
end
@ -140,18 +140,18 @@ function M.get_relative_path(base_path, my_path)
return data
end
local level = "error"
local level = 'error'
if _NgConfigValues.debug == true then
level = "info"
elseif _NgConfigValues.debug == "trace" then
level = "trace"
level = 'info'
elseif _NgConfigValues.debug == 'trace' then
level = 'trace'
end
local default_config = {use_console = false, use_file = true, level = level}
local default_config = { use_console = false, use_file = true, level = level }
if _NgConfigValues.debug_console_output then
default_config.use_console = true
default_config.use_file = false
end
M._log = require("guihua.log").new(default_config, true)
M._log = require('guihua.log').new(default_config, true)
-- add log to you lsp.log
M.log = M._log.info
@ -165,10 +165,10 @@ end
function M.split(inputstr, sep)
if sep == nil then
sep = "%s"
sep = '%s'
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
for str in string.gmatch(inputstr, '([^' .. sep .. ']+)') do
table.insert(t, str)
end
return t
@ -178,29 +178,29 @@ function M.quickfix_extract(line)
-- check if it is a line of file pos been selected
local split = M.split
line = vim.trim(line)
local sep = split(line, " ")
local sep = split(line, ' ')
if #sep < 2 then
M.log(line)
return nil
end
sep = split(sep[1], ":")
sep = split(sep[1], ':')
if #sep < 3 then
M.log(line)
return nil
end
local location = {
uri = "file:///" .. sep[1],
range = {start = {line = sep[2] - 3 > 0 and sep[2] - 3 or 1}}
uri = 'file:///' .. sep[1],
range = { start = { line = sep[2] - 3 > 0 and sep[2] - 3 or 1 } },
}
location.range["end"] = {line = sep[2] + 15}
location.range['end'] = { line = sep[2] + 15 }
return location
end
function M.getArgs(inputstr)
local sep = "%s"
local sep = '%s'
local t = {}
local cmd
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
for str in string.gmatch(inputstr, '([^' .. sep .. ']+)') do
if not cmd then
cmd = str
else
@ -215,42 +215,42 @@ function M.p(t)
end
function M.printError(msg)
vim.cmd("echohl ErrorMsg")
vim.cmd('echohl ErrorMsg')
vim.cmd(string.format([[echomsg '%s']], msg))
vim.cmd("echohl None")
vim.cmd('echohl None')
end
function M.reload()
vim.lsp.stop_client(vim.lsp.get_active_clients())
vim.cmd [[edit]]
vim.cmd([[edit]])
end
function M.open_log()
local path = vim.lsp.get_log_path()
vim.cmd("edit " .. path)
vim.cmd('edit ' .. path)
end
function table.pack(...)
return {n = select("#", ...), ...}
return { n = select('#', ...), ... }
end
function M.show(...)
local string = ""
local string = ''
local args = table.pack(...)
for i = 1, args.n do
string = string .. tostring(args[i]) .. "\t"
string = string .. tostring(args[i]) .. '\t'
end
return string .. "\n"
return string .. '\n'
end
function M.split2(s, sep)
local fields = {}
sep = sep or " "
local pattern = string.format("([^%s]+)", sep)
sep = sep or ' '
local pattern = string.format('([^%s]+)', sep)
string.gsub(s, pattern, function(c)
fields[#fields + 1] = c
end)
@ -278,17 +278,17 @@ function M.trim_and_pad(txt)
end
M.open_file = function(filename)
vim.api.nvim_command(string.format("e! %s", filename))
vim.api.nvim_command(string.format('e! %s', filename))
end
M.open_file_at = function(filename, line, col, split)
if split == nil then
-- code
vim.api.nvim_command(string.format("e! +%s %s", line, filename))
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))
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))
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
@ -303,7 +303,7 @@ function M.exists(var)
end
end
local exclude_ft = {"scrollbar", "help", "NvimTree"}
local exclude_ft = { 'scrollbar', 'help', 'NvimTree' }
function M.exclude(fname)
for i = 1, #exclude_ft do
if string.find(fname, exclude_ft[i]) then
@ -322,13 +322,12 @@ local bufs
function M.set_virt_eol(bufnr, lnum, chunks, priority, id)
if nss == nil then
nss = api.nvim_create_namespace("navigator_search")
nss = api.nvim_create_namespace('navigator_search')
end
bufnr = bufnr == 0 and api.nvim_get_current_buf() or bufnr
bufs[bufnr] = true
-- id may be nil
return api.nvim_buf_set_extmark(bufnr, nss, lnum, -1,
{id = id, virt_text = chunks, priority = priority})
return api.nvim_buf_set_extmark(bufnr, nss, lnum, -1, { id = id, virt_text = chunks, priority = priority })
end
function M.clear_buf(bufnr)
@ -381,7 +380,7 @@ function M.mk_handler(fn)
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)
return fn(err, result, { method = method, client_id = client_id, bufnr = bufnr }, config)
end
end
end
@ -392,18 +391,25 @@ function M.partial(func, arg)
end))
end
function M.empty(t)
if t == nil then
return true
end
return next(t) == nil
end
-- alternatively: use vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR)
function M.warn(msg)
vim.api.nvim_echo({{"WRN: " .. msg, "WarningMsg"}}, true, {})
vim.api.nvim_echo({ { 'WRN: ' .. msg, 'WarningMsg' } }, true, {})
end
function M.error(msg)
vim.api.nvim_echo({{"ERR: " .. msg, "ErrorMsg"}}, true, {})
vim.api.nvim_echo({ { 'ERR: ' .. msg, 'ErrorMsg' } }, true, {})
end
function M.info(msg)
vim.api.nvim_echo({{"Info: " .. msg}}, true, {})
vim.api.nvim_echo({ { 'Info: ' .. msg } }, true, {})
end
return M

Loading…
Cancel
Save