incoming_calls and outgoing_calls cause errors when results from LSP server have multiple lines #78

neovim_0.6
ray-x 3 years ago
parent 0f2868c5e6
commit 2afd51ae11

@ -1,6 +1,7 @@
local gui = require "navigator.gui"
local util = require "navigator.util"
local log = util.log
local trace = util.trace
local partial = util.partial
local lsphelper = require "navigator.lspwrapper"
@ -10,7 +11,7 @@ local cwd = vim.loop.cwd()
local M = {}
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
log('call_hierarchy')
trace('call_hierarchy', result)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if err ~= nil then
log("dir", direction, "result", result, "err", err, ctx)
@ -29,11 +30,13 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
for _, range in pairs(call_hierarchy_call.fromRanges) do
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub("\n", "")
table.insert(items, {
uri = call_hierarchy_item.uri,
filename = filename,
display_filename = call_hierarchy_item.detail or display_filename,
text = kind .. call_hierarchy_item.name,
display_filename = display_filename,
text = kind .. call_hierarchy_item.name .. '' .. call_hierarchy_item.detail,
range = range,
lnum = range.start.line,
col = range.start.character
@ -47,7 +50,7 @@ local call_hierarchy_handler_from = partial(call_hierarchy_handler, "from")
local call_hierarchy_handler_to = partial(call_hierarchy_handler, "to")
local function incoming_calls_handler(bang, err, result, ctx, cfg)
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 hierarchy")
local results = call_hierarchy_handler_from(err, result, ctx, cfg, "Incoming calls not found")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
@ -63,7 +66,7 @@ local function outgoing_calls_handler(bang, err, result, ctx, cfg)
end
function M.incoming_calls(bang, opts)
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 hierarchy")
if not lsphelper.check_capabilities("call_hierarchy") then
return
end

@ -485,7 +485,7 @@ local function setup(user_opts)
if user_opts ~= nil then
log("navigator user setup", user_opts)
end
log(debug.traceback())
trace(debug.traceback())
user_opts = user_opts or config -- incase setup was triggered from autocmd
if ft == nil then

@ -1136,7 +1136,7 @@ definition.lua:9: { {
cargoArgs = { "run", "--package", "hello", "--bin", "hello" },
cargoExtraArgs = {},
executableArgs = {},
workspaceRoot = "/Users/ray.xu/lsp_test/rust"
workspaceRoot = "/Users/glsp_test/rust"
},
kind = "cargo",
label = "run hello",
@ -1161,7 +1161,7 @@ definition.lua:9: { {
line = 45
}
},
targetUri = "file:///Users/ray.xu/lsp_test/rust/src/main.rs"
targetUri = "file:///Users/glsp_test/rust/src/main.rs"
}
} },
command = "rust-analyzer.runSingle",
@ -1184,7 +1184,7 @@ definition.lua:9: { {
cargoArgs = { "run", "--package", "hello", "--bin", "hello" },
cargoExtraArgs = {},
executableArgs = {},
workspaceRoot = "/Users/ray.xu/lsp_test/rust"
workspaceRoot = "/Users/glsp_test/rust"
},
kind = "cargo",
label = "run hello",
@ -1209,7 +1209,7 @@ definition.lua:9: { {
line = 45
}
},
targetUri = "file:///Users/ray.xu/lsp_test/rust/src/main.rs"
targetUri = "file:///Users/glsp_test/rust/src/main.rs"
}
} },
command = "rust-analyzer.debugSingle",
@ -1233,7 +1233,7 @@ definition.lua:9: { {
line = 2
},
textDocument = {
uri = "file:///Users/ray.xu/lsp_test/rust/src/main.rs"
uri = "file:///Users/glsp_test/rust/src/main.rs"
}
}
},
@ -1255,7 +1255,7 @@ definition.lua:9: { {
line = 28
},
textDocument = {
uri = "file:///Users/ray.xu/lsp_test/rust/src/main.rs"
uri = "file:///Users/glsp_test/rust/src/main.rs"
}
}
},
@ -1277,7 +1277,7 @@ definition.lua:9: { {
line = 31
},
textDocument = {
uri = "file:///Users/ray.xu/lsp_test/rust/src/main.rs"
uri = "file:///Users/glsp_test/rust/src/main.rs"
}
}
},
@ -1293,3 +1293,178 @@ definition.lua:9: { {
}
} }
} }
type_definition = true,
workspace_folder_properties = {
changeNotifications = false,
supported = false
},
workspace_symbol = true
}
...ack/packer/opt/navigator.lua/lua/navigator/hierarchy.lua:13: call_hierarchy { {
fromRanges = { {
end = {
character = 68,
line = 53
},
start = {
character = 54,
line = 53
}
} },
to = {
detail = "pub fn unwrap_or_else<F>(self, f: F) -> T\nwhere\n F: FnOnce<(), Output = T>,",
kind = 12,
name = "unwrap_or_else",
range = {
end = {
character = 5,
line = 764
},
start = {
character = 4,
line = 748
}
},
selectionRange = {
end = {
character = 25,
line = 759
},
start = {
character = 11,
line = 759
}
},
uri = "file:///Users/g.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs"
}
}, {
fromRanges = { {
end = {
character = 33,
line = 54
},
start = {
character = 27,
line = 54
}
}, {
end = {
character = 28,
line = 55
},
start = {
character = 22,
line = 55
}
} },
to = {
detail = "pub const fn unwrap(self) -> T",
kind = 12,
name = "unwrap",
range = {
end = {
character = 5,
line = 723
},
start = {
character = 4,
line = 688
}
},
selectionRange = {
end = {
character = 23,
line = 718
},
start = {
character = 17,
line = 718
}
},
uri = "file:///Users/g.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs"
}
} }
call_hierarchy { {
from = {
detail = "fn test2()",
kind = 12,
name = "test2",
range = {
end = {
character = 20,
line = 43
},
start = {
character = 0,
line = 43
}
},
selectionRange = {
end = {
character = 8,
line = 43
},
start = {
character = 3,
line = 43
}
},
uri = "file:///Users/glsp_test/rust/src/main.rs"
},
fromRanges = { {
end = {
character = 16,
line = 43
},
start = {
character = 12,
line = 43
}
} }
}, {
from = {
detail = "fn test3()",
kind = 12,
name = "test3",
range = {
end = {
character = 29,
line = 44
},
start = {
character = 0,
line = 44
}
},
selectionRange = {
end = {
character = 8,
line = 44
},
start = {
character = 3,
line = 44
}
},
uri = "file:///Users/glsp_test/rust/src/main.rs"
},
fromRanges = { {
end = {
character = 16,
line = 44
},
start = {
character = 12,
line = 44
}
} }
} }

Loading…
Cancel
Save