mirror of
https://github.com/ray-x/navigator.lua
synced 2024-10-30 21:20:12 +00:00
replace print to notify, add workspace gui
This commit is contained in:
parent
85d907ffaf
commit
c528b58bb9
12
index.html
Normal file
12
index.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link href="css/style.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -16,7 +16,7 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
|
|||||||
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
|
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
log("hierarchy error", ctx, "dir", direction, "result", result, "err", err)
|
log("hierarchy error", ctx, "dir", direction, "result", result, "err", err)
|
||||||
print("ERROR: " .. error_message)
|
vim.notify("ERROR: " .. error_message, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- local funcs = vim.lsp.util.locations_to_items(result)
|
-- local funcs = vim.lsp.util.locations_to_items(result)
|
||||||
|
@ -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
|
||||||
print(err, ctx)
|
vim.notify(err, ctx, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if type(locations) == "number" then
|
if type(locations) == "number" then
|
||||||
@ -16,7 +16,7 @@ local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
|
|||||||
log("unable to handle request")
|
log("unable to handle request")
|
||||||
end
|
end
|
||||||
if locations == nil or vim.tbl_isempty(locations) then
|
if locations == nil or vim.tbl_isempty(locations) then
|
||||||
print "Definition not found"
|
vim.notify "Definition not found"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if vim.tbl_islist(locations) then
|
if vim.tbl_islist(locations) then
|
||||||
@ -43,7 +43,7 @@ local function def_preview(timeout_ms)
|
|||||||
local result = vim.lsp.buf_request_sync(0, method, params, timeout_ms or 1000)
|
local result = vim.lsp.buf_request_sync(0, method, params, timeout_ms or 1000)
|
||||||
|
|
||||||
if result == nil or vim.tbl_isempty(result) then
|
if result == nil or vim.tbl_isempty(result) then
|
||||||
print("No result found: " .. method)
|
vim.notify("No result found: " .. method, vim.lsp.log_levels.WARN)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ local function def_preview(timeout_ms)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(data) then
|
if vim.tbl_isempty(data) then
|
||||||
print("No result found: " .. method)
|
vim.notify("No result found: " .. method, vim.lsp.log_levels.WARN)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ end
|
|||||||
|
|
||||||
-- TODO: update the marker
|
-- TODO: update the marker
|
||||||
if _NgConfigValues.diagnostic_scrollbar_sign then
|
if _NgConfigValues.diagnostic_scrollbar_sign then
|
||||||
print("config deprecated, set lsp.diagnostic_scrollbar_sign instead")
|
vim.notify("config deprecated, set lsp.diagnostic_scrollbar_sign instead", vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
|
|
||||||
if _NgConfigValues.lsp.diagnostic_scrollbar_sign then
|
if _NgConfigValues.lsp.diagnostic_scrollbar_sign then
|
||||||
|
@ -233,7 +233,7 @@ local function documentHighlight()
|
|||||||
vim.lsp.handlers['textDocument/documentHighlight'] = mk_handler(function(err, result, ctx)
|
vim.lsp.handlers['textDocument/documentHighlight'] = mk_handler(function(err, result, ctx)
|
||||||
local bufnr = ctx.bufnr or api.nvim_get_current_buf()
|
local bufnr = ctx.bufnr or api.nvim_get_current_buf()
|
||||||
if err then
|
if err then
|
||||||
print(err)
|
vim.notify(err, vim.lsp.log_levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not result or not result[1] or not result[1]['range'] then
|
if not result or not result[1] or not result[1]['range'] then
|
||||||
|
@ -93,7 +93,7 @@ M.fold_handler = mk_handler(function(err, result, ctx, config)
|
|||||||
-- 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
|
||||||
print(err, ctx.method, ctx.client_id)
|
vim.notify(err, ctx.method, ctx.client_id, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
M.debug_folds()
|
M.debug_folds()
|
||||||
|
@ -32,7 +32,7 @@ vim.opt.viewoptions:remove("options")
|
|||||||
|
|
||||||
function M.setup_fold()
|
function M.setup_fold()
|
||||||
if not parsers.has_parser() then
|
if not parsers.has_parser() then
|
||||||
print("treesitter folding not enabled for current file")
|
vim.notify("treesitter folding not enabled for current file", vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
log("setup treesitter folding")
|
log("setup treesitter folding")
|
||||||
|
@ -11,14 +11,14 @@ 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, cfg, error_message)
|
||||||
if not result then
|
if not result then
|
||||||
print("No call hierarchy items found")
|
vim.notify ("No call hierarchy items found", vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
trace('call_hierarchy', result)
|
trace('call_hierarchy', result)
|
||||||
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
|
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
log("dir", direction, "result", result, "err", err, ctx)
|
log("dir", direction, "result", result, "err", err, ctx)
|
||||||
print("ERROR: " .. error_message)
|
vim.notify("ERROR: " .. error_message, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ 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, cfg, msg)
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
print("ERROR: " .. tostring(err) .. " " .. msg)
|
vim.notify("ERROR: " .. tostring(err) .. " " .. msg, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return locations_to_items(locations)
|
return locations_to_items(locations)
|
||||||
|
@ -18,7 +18,7 @@ local has_lsp, lspconfig = pcall(require, 'lspconfig')
|
|||||||
if not has_lsp then
|
if not has_lsp then
|
||||||
return {
|
return {
|
||||||
setup = function()
|
setup = function()
|
||||||
print('loading lsp config failed LSP may not working correctly')
|
vim.notify('loading lsp config failed LSP may not working correctly', vim.lsp.log_levels.WARN)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -457,14 +457,14 @@ local function lsp_startup(ft, retry, user_lsp_opts)
|
|||||||
local default_config = {}
|
local default_config = {}
|
||||||
log(lspclient)
|
log(lspclient)
|
||||||
if lspconfig[lspclient] == nil then
|
if lspconfig[lspclient] == nil then
|
||||||
print('lspclient', lspclient, 'no longer support by lspconfig, please submit an issue')
|
vim.notify('lspclient', lspclient, 'no longer support by lspconfig, please submit an issue', vim.lsp.log_levels.WARN)
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
if lspconfig[lspclient].document_config and lspconfig[lspclient].document_config.default_config then
|
if lspconfig[lspclient].document_config and lspconfig[lspclient].document_config.default_config then
|
||||||
default_config = lspconfig[lspclient].document_config.default_config
|
default_config = lspconfig[lspclient].document_config.default_config
|
||||||
else
|
else
|
||||||
print('missing document config for client: ', lspclient)
|
vim.notify('missing document config for client: ', lspclient, vim.lsp.log_levels.WARN)
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -525,7 +525,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
|
|||||||
end
|
end
|
||||||
cfg.on_init = function(client)
|
cfg.on_init = function(client)
|
||||||
if client and client.config and client.config.settings then
|
if client and client.config and client.config.settings then
|
||||||
client.notify('workspace/didChangeConfiguration', { settings = client.config.settings })
|
client.notify('workspace/didChangeConfiguration', { settings = client.config.settings }, vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ local key_maps = {
|
|||||||
{ key = '<Space>wr', func = 'remove_workspace_folder()' },
|
{ key = '<Space>wr', func = 'remove_workspace_folder()' },
|
||||||
{ key = '<Space>ff', func = 'formatting()', mode = 'n' },
|
{ key = '<Space>ff', func = 'formatting()', mode = 'n' },
|
||||||
{ key = '<Space>ff', func = 'range_formatting()', mode = 'v' },
|
{ key = '<Space>ff', func = 'range_formatting()', mode = 'v' },
|
||||||
{ key = '<Space>wl', func = 'print(vim.inspect(vim.lsp.buf.list_workspace_folders()))' },
|
{ key = '<Space>wl', func = 'vim.notify(vim.inspect(vim.lsp.buf.list_workspace_folders()))' },
|
||||||
{ key = '<Space>la', mode = 'n', func = "require('navigator.codelens').run_action()" },
|
{ key = '<Space>la', mode = 'n', func = "require('navigator.codelens').run_action()" },
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,12 +221,12 @@ M.toggle_lspformat = function(on)
|
|||||||
end
|
end
|
||||||
if _NgConfigValues.lsp.format_on_save then
|
if _NgConfigValues.lsp.format_on_save then
|
||||||
if on == nil then
|
if on == nil then
|
||||||
print('format on save true')
|
vim.notify('format on save true', vim.lsp.log_levels.INFO)
|
||||||
end
|
end
|
||||||
vim.cmd([[set eventignore-=BufWritePre]])
|
vim.cmd([[set eventignore-=BufWritePre]])
|
||||||
else
|
else
|
||||||
if on == nil then
|
if on == nil then
|
||||||
print('format on save false')
|
vim.notify('format on save false', vim.lsp.log_levels.INFO)
|
||||||
end
|
end
|
||||||
vim.cmd([[set eventignore+=BufWritePre]])
|
vim.cmd([[set eventignore+=BufWritePre]])
|
||||||
end
|
end
|
||||||
|
@ -314,7 +314,7 @@ end
|
|||||||
function M.locations_to_items(locations, max_items)
|
function M.locations_to_items(locations, max_items)
|
||||||
max_items = max_items or 100000 --
|
max_items = max_items or 100000 --
|
||||||
if not locations or vim.tbl_isempty(locations) then
|
if not locations or vim.tbl_isempty(locations) then
|
||||||
print('list not avalible')
|
vim.notify('list not avalible', vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local width = 4
|
local width = 4
|
||||||
@ -420,7 +420,7 @@ end
|
|||||||
|
|
||||||
function M.symbol_to_items(locations)
|
function M.symbol_to_items(locations)
|
||||||
if not locations or vim.tbl_isempty(locations) then
|
if not locations or vim.tbl_isempty(locations) then
|
||||||
print('list not avalible')
|
vim.notify('list not avalible', vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,18 +20,18 @@ local ref_view = function(err, locations, ctx, cfg)
|
|||||||
-- log("num", num)
|
-- log("num", num)
|
||||||
-- log("bfnr", bufnr)
|
-- log("bfnr", bufnr)
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
print('lsp ref callback error', err, ctx, vim.inspect(locations))
|
vim.notify('lsp ref callback error', err, ctx, vim.inspect(locations), vim.lsp.log_levels.WARN)
|
||||||
log('ref callback error, lsp may not ready', err, ctx, vim.inspect(locations))
|
log('ref callback error, lsp may not ready', err, ctx, vim.inspect(locations))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if type(locations) ~= 'table' then
|
if type(locations) ~= 'table' then
|
||||||
log(locations)
|
log(locations)
|
||||||
log('ctx', ctx)
|
log('ctx', ctx)
|
||||||
print('incorrect setup', locations)
|
vim.notify('incorrect setup', locations, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if locations == nil or vim.tbl_isempty(locations) then
|
if locations == nil or vim.tbl_isempty(locations) then
|
||||||
print('References not found')
|
vim.notify('References not found', vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ local ref_view = function(err, locations, ctx, cfg)
|
|||||||
local listview = gui.new_list_view(opts)
|
local listview = gui.new_list_view(opts)
|
||||||
|
|
||||||
if listview == nil then
|
if listview == nil then
|
||||||
print('failed to create preview windows')
|
vim.notify('failed to create preview windows', vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- trace("update items", listview.ctrl.class)
|
-- trace("update items", listview.ctrl.class)
|
||||||
|
@ -52,7 +52,7 @@ 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
|
||||||
print("no item found or empty fields")
|
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])
|
||||||
|
@ -52,7 +52,7 @@ local signature_handler = mk_handler(function(err, result, ctx, config)
|
|||||||
log("config nil")
|
log("config nil")
|
||||||
end
|
end
|
||||||
if err then
|
if err then
|
||||||
print("signature help error: ", err, vim.inspect(result), ctx, config)
|
vim.notify("signature help error: ", err, vim.inspect(result), ctx, config, vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
config = config or {}
|
config = config or {}
|
||||||
if config.border == nil then
|
if config.border == nil then
|
||||||
|
@ -30,7 +30,7 @@ local symbols_to_items = lsphelper.symbols_to_items
|
|||||||
-- if #lines > 0 then
|
-- if #lines > 0 then
|
||||||
-- gui.new_list_view({data = lines})
|
-- gui.new_list_view({data = lines})
|
||||||
-- else
|
-- else
|
||||||
-- print("symbols not found")
|
-- vim.notify("symbols not found")
|
||||||
-- end
|
-- end
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
@ -77,12 +77,12 @@ end
|
|||||||
|
|
||||||
M.document_symbol_handler = mk_handler(function(err, result, ctx)
|
M.document_symbol_handler = mk_handler(function(err, result, ctx)
|
||||||
if err then
|
if err then
|
||||||
print('failed to get document symbol', ctx)
|
vim.notify('failed to get document symbol', ctx, vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
local bufnr = ctx.bufnr or 0
|
local bufnr = ctx.bufnr or 0
|
||||||
|
|
||||||
if not result or vim.tbl_isempty(result) then
|
if not result or vim.tbl_isempty(result) then
|
||||||
print('symbol not found for buf', ctx)
|
vim.notify('symbol not found for buf', ctx, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- log(result)
|
-- log(result)
|
||||||
@ -134,10 +134,10 @@ end)
|
|||||||
|
|
||||||
M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
|
M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
|
||||||
if err then
|
if err then
|
||||||
print('failed to get workspace symbol', ctx)
|
vim.notify('failed to get workspace symbol', ctx, vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
if not result or vim.tbl_isempty(result) then
|
if not result or vim.tbl_isempty(result) then
|
||||||
print('symbol not found for buf', ctx)
|
vim.notify('symbol not found for buf', ctx, vim.lsp.log_levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
log(result[1])
|
log(result[1])
|
||||||
@ -161,7 +161,7 @@ M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
|
|||||||
-- gui.new_list_view({items = items, prompt = true, ft = ft, rowdata = true, api = " "})
|
-- gui.new_list_view({items = items, prompt = true, ft = ft, rowdata = true, api = " "})
|
||||||
|
|
||||||
-- if locations == nil or vim.tbl_isempty(locations) then
|
-- if locations == nil or vim.tbl_isempty(locations) then
|
||||||
-- print "References not found"
|
-- vim.notify "References not found"
|
||||||
-- return
|
-- return
|
||||||
-- end
|
-- end
|
||||||
-- local items = locations_to_items(locations)
|
-- local items = locations_to_items(locations)
|
||||||
|
@ -292,11 +292,11 @@ local function get_all_nodes(bufnr, filter, summary)
|
|||||||
|
|
||||||
trace(bufnr, filter, summary)
|
trace(bufnr, filter, summary)
|
||||||
if not bufnr then
|
if not bufnr then
|
||||||
print("get_all_node invalide bufnr")
|
vim.notify("get_all_node invalide bufnr", vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
summary = summary or false
|
summary = summary or false
|
||||||
if not parsers.has_parser() then
|
if not parsers.has_parser() then
|
||||||
print("ts not loaded")
|
vim.notify("ts not loaded", vim.lsp.log_levels.WARN)
|
||||||
end
|
end
|
||||||
|
|
||||||
local path_sep = require"navigator.util".path_sep()
|
local path_sep = require"navigator.util".path_sep()
|
||||||
|
@ -211,7 +211,7 @@ function M.getArgs(inputstr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.p(t)
|
function M.p(t)
|
||||||
print(vim.inspect(t))
|
vim.notify(vim.inspect(t), vim.log.levels.INFO)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.printError(msg)
|
function M.printError(msg)
|
||||||
|
49
lua/navigator/workspace.lua
Normal file
49
lua/navigator/workspace.lua
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/rename.lua
|
||||||
|
local M = {}
|
||||||
|
local util = require('navigator.util')
|
||||||
|
-- local rename_prompt = 'Rename -> '
|
||||||
|
|
||||||
|
M.add_workspace_folder = function()
|
||||||
|
util.log(vim.ui.input)
|
||||||
|
local input = require('guihua.floating').input
|
||||||
|
input({ prompt = 'Workspace To Add: ', default = vim.fn.expand('%:p:h') }, function(inputs)
|
||||||
|
util.log(inputs)
|
||||||
|
vim.lsp.buf.add_workspace_folder(inputs)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.remove_workspace_folder = function()
|
||||||
|
local select = require('guihua.gui').select
|
||||||
|
local folders = vim.lsp.buf.list_workspace_folders()
|
||||||
|
|
||||||
|
if #folders > 1 then
|
||||||
|
select(folders, { prompt = 'select workspace to delete' }, function(workspace)
|
||||||
|
util.log(workspace)
|
||||||
|
vim.lsp.buf.remove_workspace_folder(workspace)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.workspace_symbol = function()
|
||||||
|
local input = vim.ui.input
|
||||||
|
|
||||||
|
vim.ui.input = require('guihua.floating').input
|
||||||
|
vim.lsp.buf.workspace_symbol()
|
||||||
|
vim.defer_fn(function()
|
||||||
|
vim.ui.input = input
|
||||||
|
end, 1000)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.list_workspace_folders = function()
|
||||||
|
local folders = vim.lsp.buf.list_workspace_folders()
|
||||||
|
if #folders > 0 then
|
||||||
|
return require('navigator.gui').new_list_view({
|
||||||
|
items = folders,
|
||||||
|
border = 'single',
|
||||||
|
rawdata = true,
|
||||||
|
on_move = function(...) end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Reference in New Issue
Block a user