fix(dap.hover): more cleanup
This commit is contained in:
@@ -108,7 +108,7 @@ end
|
||||
|
||||
---@return string[]
|
||||
function Content:get_lines()
|
||||
return vim.split(self.text, "\n", { trimempty = true })
|
||||
return vim.split(vim.trim(self.text), "\n")
|
||||
end
|
||||
|
||||
---@param ns_id integer
|
||||
|
||||
+10
-15
@@ -1,5 +1,7 @@
|
||||
local Content = require("ow.dap.hover.content")
|
||||
local Item = require("ow.dap.item")
|
||||
local Node = require("ow.dap.hover.node")
|
||||
local log = require("ow.log")
|
||||
|
||||
---@class ow.dap.hover.Tree
|
||||
---@field session dap.Session
|
||||
@@ -12,9 +14,7 @@ Tree.__index = Tree
|
||||
function Tree.new(session)
|
||||
return setmetatable({
|
||||
session = session,
|
||||
root_node = nil,
|
||||
line_to_node = {},
|
||||
extmark_to_node = {},
|
||||
root = nil,
|
||||
}, Tree)
|
||||
end
|
||||
|
||||
@@ -40,25 +40,20 @@ function Tree:load_children(node)
|
||||
local err, resp = self.session:request("variables", {
|
||||
variablesReference = node.item.variablesReference,
|
||||
})
|
||||
|
||||
if err then
|
||||
log.warning("Failed to get variables for %s: %s", node.item.name, err)
|
||||
end
|
||||
if err or not resp or #resp.variables == 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
for i, var in ipairs(resp.variables) do
|
||||
local child_item = {
|
||||
name = var.name,
|
||||
type = var.type,
|
||||
value = var.value,
|
||||
variablesReference = var.variablesReference,
|
||||
depth = node.item.depth + 1,
|
||||
}
|
||||
|
||||
local child = Node.new(child_item, node)
|
||||
local item = Item.from_var(var)
|
||||
local child = Node.new(item, node)
|
||||
child.is_last_child = (i == #resp.variables)
|
||||
|
||||
if child_item.name:match("^%d+$") then
|
||||
child_item.name = "[" .. child_item.name .. "]"
|
||||
if item.name:match("^%d+$") then
|
||||
item.name = "[" .. item.name .. "]"
|
||||
end
|
||||
|
||||
table.insert(node.children, child)
|
||||
|
||||
@@ -42,9 +42,11 @@ function Window:close()
|
||||
vim.api.nvim_del_augroup_by_id(self.augroup)
|
||||
end
|
||||
|
||||
self.augroup = nil
|
||||
self.max_width = nil
|
||||
self.max_height = nil
|
||||
self.winid = nil
|
||||
self.bufnr = nil
|
||||
self.augroup = nil
|
||||
self.tree = nil
|
||||
end
|
||||
|
||||
@@ -69,12 +71,12 @@ function Window:compute_height()
|
||||
return math.min(self.max_height or text_height, text_height)
|
||||
end
|
||||
|
||||
---@param lines string[]
|
||||
---@param content ow.dap.hover.Content
|
||||
function Window:show(lines, content)
|
||||
function Window:show(content)
|
||||
local prev_buf = vim.api.nvim_get_current_buf()
|
||||
self.bufnr = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
local lines = content:get_lines()
|
||||
vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines)
|
||||
vim.bo[self.bufnr].modifiable = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user