Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/litee/lib/jumps/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function M.jump_invoking(location, win, node, offset_encoding)
-- if the panel currently has a component "popped-out"
-- close it before jumping.
lib_panel.close_current_popout()
vim.lsp.util.jump_to_location(location, offset_encoding or "utf-8")
vim.lsp.util.show_document(location, offset_encoding or "utf-8")
M.set_jump_hl(true, node)

-- cleanup any [No Name] buffers if they exist
Expand Down
78 changes: 55 additions & 23 deletions lua/litee/lib/lsp/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@ local M = {}

local float_win = nil

-- 本地实现:去掉头尾的空行,替代 vim.lsp.util.trim_empty_lines()
local function trim_empty_lines(lines)
local start_idx = 1
local end_idx = #lines

-- 去掉开头空行
while start_idx <= end_idx and lines[start_idx]:match("^%s*$") do
start_idx = start_idx + 1
end

-- 去掉结尾空行
while end_idx >= start_idx and lines[end_idx]:match("^%s*$") do
end_idx = end_idx - 1
end

local new = {}
for i = start_idx, end_idx do
new[#new + 1] = lines[i]
end
return new
end

-- close_hover_popups closes the created popup window
-- if it exists.
function M.close_hover_popup()
if float_win ~= nil and
vim.api.nvim_win_is_valid(float_win) then
if float_win ~= nil and vim.api.nvim_win_is_valid(float_win) then
vim.api.nvim_win_close(float_win, true)
float_win = nil
end
Expand All @@ -19,18 +40,22 @@ end
-- function conforms to client LSP handler signature.
function M.hover_handler(_, result, ctx, config)
M.close_hover_popup()
-- get lines from result

config = config or {}
config.focus_id = ctx.method

if not (result and result.contents) then
-- return { 'No information available' }
return
-- return { 'No information available' }
return
end

-- 从 LSP 结果生成 markdown 行
local lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
lines = vim.lsp.util.trim_empty_lines(lines)
lines = trim_empty_lines(lines) -- 使用我们自己的实现

if vim.tbl_isempty(lines) then
-- return { 'No information available' }
return
-- return { 'No information available' }
return
end

-- create buffer for popup
Expand All @@ -39,12 +64,17 @@ function M.hover_handler(_, result, ctx, config)
vim.api.nvim_err_writeln("details_popup: could not create details buffer")
return
end
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'delete')
vim.api.nvim_buf_set_option(buf, 'syntax', 'markdown')
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')

lines = vim.lsp.util.stylize_markdown(buf, lines, {})
vim.api.nvim_buf_set_option(buf, "bufhidden", "delete")
vim.api.nvim_buf_set_option(buf, "syntax", "markdown")
vim.api.nvim_buf_set_option(buf, "filetype", "markdown")

-- 之前这里调用的是 vim.lsp.util.stylize_markdown(buf, lines, {})
-- 该 API 已弃用,我们改成简单方案:
-- 只用 markdown filetype + treesitter 高亮(如果有安装 markdown parser)
pcall(vim.treesitter.start, buf, "markdown")

-- 计算浮窗宽度
local width = 20
for _, line in ipairs(lines) do
local line_width = vim.fn.strdisplaywidth(line)
Expand All @@ -53,22 +83,24 @@ function M.hover_handler(_, result, ctx, config)
end
end

vim.api.nvim_buf_set_option(buf, 'modifiable', true)
vim.api.nvim_buf_set_option(buf, "modifiable", true)
vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines)
vim.api.nvim_buf_set_option(buf, 'modifiable', false)
vim.api.nvim_buf_set_option(buf, "modifiable", false)

local popup_conf = vim.lsp.util.make_floating_popup_options(
width,
#lines,
{
border= "rounded",
focusable= false,
zindex = 99,
}
width,
#lines,
{
border = "rounded",
focusable = false,
zindex = 99,
}
)

float_win = vim.api.nvim_open_win(buf, false, popup_conf)

return float_win
return float_win
end


return M

8 changes: 4 additions & 4 deletions lua/litee/lib/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ local M = {}
-- but takes a list of clients as the first argument.
function M.multi_client_request(clients, method, params, handler, bufnr)
for _, client in ipairs(clients) do
if client.supports_method(method) then
client.request(method, params, handler, bufnr or 0)
if client:supports_method(method) then
client:request(method, params, handler, bufnr or 0)
return client
end
end
Expand Down Expand Up @@ -102,12 +102,12 @@ function M.symbol_from_node(clients, node, bufnr)
query = node.name,
}
for _, client in ipairs(clients) do
if not client.supports_method("workspace/symbol") then
if not client:supports_method("workspace/symbol") then
goto continue
end
-- not all LSPs are optimized, specially ones in early development, set
-- this timeout high.
local out = client.request_sync("workspace/symbol", params, 5000, bufnr)
local out = client:request_sync("workspace/symbol", params, 5000, bufnr)
if out == nil then
goto continue
end
Expand Down