mirror of
https://github.com/neovim/neovim.git
synced 2026-04-04 22:59:36 +00:00
fix(lsp): don't treat MarkedString[] with language id as empty #35518
Problem: Hover response of MarkedString[] where the first element contains a language identifier treated as empty. Solution: Fix empty check to handle case of MarkedString[] where the first element is a pair of a language and value.
This commit is contained in:
@@ -69,11 +69,26 @@ function M.hover(config)
|
||||
lsp.log.error(err.code, err.message)
|
||||
elseif result and result.contents then
|
||||
-- Make sure the response is not empty
|
||||
-- Five response shapes:
|
||||
-- - MarkupContent: { kind="markdown", value="doc" }
|
||||
-- - MarkedString-string: "doc"
|
||||
-- - MarkedString-pair: { language="c", value="doc" }
|
||||
-- - MarkedString[]-string: { "doc1", ... }
|
||||
-- - MarkedString[]-pair: { { language="c", value="doc1" }, ... }
|
||||
if
|
||||
(
|
||||
type(result.contents) == 'table'
|
||||
and #(vim.tbl_get(result.contents, 'value') or result.contents[1] or '') > 0
|
||||
) or (type(result.contents) == 'string' and #result.contents > 0)
|
||||
and #(
|
||||
vim.tbl_get(result.contents, 'value') -- MarkupContent or MarkedString-pair
|
||||
or vim.tbl_get(result.contents, 1, 'value') -- MarkedString[]-pair
|
||||
or result.contents[1] -- MarkedString[]-string
|
||||
or ''
|
||||
)
|
||||
> 0
|
||||
)
|
||||
or (
|
||||
type(result.contents) == 'string' and #result.contents > 0 -- MarkedString-string
|
||||
)
|
||||
then
|
||||
results1[client_id] = result
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user