mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(lsp): merge subtypes and supertypes into typehierarchy (#28467)
Both methods had pretty much the same documentation and shared the implementation.
This commit is contained in:
parent
052498ed42
commit
c81b7849a0
@ -1431,22 +1431,20 @@ signature_help() *vim.lsp.buf.signature_help()*
|
|||||||
Displays signature information about the symbol under the cursor in a
|
Displays signature information about the symbol under the cursor in a
|
||||||
floating window.
|
floating window.
|
||||||
|
|
||||||
subtypes() *vim.lsp.buf.subtypes()*
|
|
||||||
Lists all the subtypes of the symbol under the cursor in the |quickfix|
|
|
||||||
window. If the symbol can resolve to multiple items, the user can pick one
|
|
||||||
using |vim.ui.select()|.
|
|
||||||
|
|
||||||
supertypes() *vim.lsp.buf.supertypes()*
|
|
||||||
Lists all the supertypes of the symbol under the cursor in the |quickfix|
|
|
||||||
window. If the symbol can resolve to multiple items, the user can pick one
|
|
||||||
using |vim.ui.select()|.
|
|
||||||
|
|
||||||
type_definition({options}) *vim.lsp.buf.type_definition()*
|
type_definition({options}) *vim.lsp.buf.type_definition()*
|
||||||
Jumps to the definition of the type of the symbol under the cursor.
|
Jumps to the definition of the type of the symbol under the cursor.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {options} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
|
• {options} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
|
||||||
|
|
||||||
|
typehierarchy({kind}) *vim.lsp.buf.typehierarchy()*
|
||||||
|
Lists all the subtypes or supertypes of the symbol under the cursor in the
|
||||||
|
|quickfix| window. If the symbol can resolve to multiple items, the user
|
||||||
|
can pick one using |vim.ui.select()|.
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {kind} (`"subtypes"|"supertypes"`)
|
||||||
|
|
||||||
workspace_symbol({query}, {options}) *vim.lsp.buf.workspace_symbol()*
|
workspace_symbol({query}, {options}) *vim.lsp.buf.workspace_symbol()*
|
||||||
Lists all symbols in the current workspace in the quickfix window.
|
Lists all symbols in the current workspace in the quickfix window.
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ The following new APIs and features were added.
|
|||||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_inlayHint
|
https://microsoft.github.io/language-server-protocol/specification/#textDocument_inlayHint
|
||||||
• Implemented pull diagnostic textDocument/diagnostic: |vim.lsp.diagnostic.on_diagnostic()|
|
• Implemented pull diagnostic textDocument/diagnostic: |vim.lsp.diagnostic.on_diagnostic()|
|
||||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_diagnostic
|
https://microsoft.github.io/language-server-protocol/specification/#textDocument_diagnostic
|
||||||
• Implemented LSP type hierarchy: |vim.lsp.buf.supertypes()| and |vim.lsp.buf.subtypes()|
|
• Implemented LSP type hierarchy: |vim.lsp.buf.typehierarchy()|
|
||||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_prepareTypeHierarchy
|
https://microsoft.github.io/language-server-protocol/specification/#textDocument_prepareTypeHierarchy
|
||||||
• |vim.lsp.status()| consumes the last progress messages as a string.
|
• |vim.lsp.status()| consumes the last progress messages as a string.
|
||||||
• LSP client now always saves and restores named buffer marks when applying
|
• LSP client now always saves and restores named buffer marks when applying
|
||||||
|
@ -495,11 +495,17 @@ function M.outgoing_calls()
|
|||||||
call_hierarchy(ms.callHierarchy_outgoingCalls)
|
call_hierarchy(ms.callHierarchy_outgoingCalls)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param method string
|
--- Lists all the subtypes or supertypes of the symbol under the
|
||||||
local function type_hierarchy(method)
|
--- cursor in the |quickfix| window. If the symbol can resolve to
|
||||||
|
--- multiple items, the user can pick one using |vim.ui.select()|.
|
||||||
|
---@param kind "subtypes"|"supertypes"
|
||||||
|
function M.typehierarchy(kind)
|
||||||
|
local method = kind == 'subtypes' and ms.typeHierarchy_subtypes or ms.typeHierarchy_supertypes
|
||||||
|
|
||||||
--- Merge results from multiple clients into a single table. Client-ID is preserved.
|
--- Merge results from multiple clients into a single table. Client-ID is preserved.
|
||||||
---
|
---
|
||||||
--- @param results table<integer, {error: lsp.ResponseError, result: lsp.TypeHierarchyItem[]?}>
|
--- @param results table<integer, {error: lsp.ResponseError, result: lsp.TypeHierarchyItem[]?}>
|
||||||
|
--- @return [integer, lsp.TypeHierarchyItem][]
|
||||||
local function merge_results(results)
|
local function merge_results(results)
|
||||||
local merged_results = {}
|
local merged_results = {}
|
||||||
for client_id, client_result in pairs(results) do
|
for client_id, client_result in pairs(results) do
|
||||||
@ -525,11 +531,9 @@ local function type_hierarchy(method)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if #merged_results == 1 then
|
if #merged_results == 1 then
|
||||||
--- @type {integer, lsp.TypeHierarchyItem}
|
|
||||||
local item = merged_results[1]
|
local item = merged_results[1]
|
||||||
local client = vim.lsp.get_client_by_id(item[1])
|
local client = vim.lsp.get_client_by_id(item[1])
|
||||||
if client then
|
if client then
|
||||||
--- @type lsp.TypeHierarchyItem
|
|
||||||
client.request(method, { item = item[2] }, nil, bufnr)
|
client.request(method, { item = item[2] }, nil, bufnr)
|
||||||
else
|
else
|
||||||
vim.notify(
|
vim.notify(
|
||||||
@ -565,20 +569,6 @@ local function type_hierarchy(method)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Lists all the subtypes of the symbol under the
|
|
||||||
--- cursor in the |quickfix| window. If the symbol can resolve to
|
|
||||||
--- multiple items, the user can pick one using |vim.ui.select()|.
|
|
||||||
function M.subtypes()
|
|
||||||
type_hierarchy(ms.typeHierarchy_subtypes)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Lists all the supertypes of the symbol under the
|
|
||||||
--- cursor in the |quickfix| window. If the symbol can resolve to
|
|
||||||
--- multiple items, the user can pick one using |vim.ui.select()|.
|
|
||||||
function M.supertypes()
|
|
||||||
type_hierarchy(ms.typeHierarchy_supertypes)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- List workspace folders.
|
--- List workspace folders.
|
||||||
---
|
---
|
||||||
function M.list_workspace_folders()
|
function M.list_workspace_folders()
|
||||||
|
@ -3463,7 +3463,7 @@ describe('LSP', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('vim.lsp.buf.subtypes', function()
|
describe('vim.lsp.buf.typehierarchy subtypes', function()
|
||||||
it('does nothing for an empty response', function()
|
it('does nothing for an empty response', function()
|
||||||
local qflist_count = exec_lua([=[
|
local qflist_count = exec_lua([=[
|
||||||
require'vim.lsp.handlers'['typeHierarchy/subtypes'](nil, nil, {})
|
require'vim.lsp.handlers'['typeHierarchy/subtypes'](nil, nil, {})
|
||||||
@ -3681,7 +3681,7 @@ describe('LSP', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('vim.lsp.buf.supertypes', function()
|
describe('vim.lsp.buf.typehierarchy supertypes', function()
|
||||||
it('does nothing for an empty response', function()
|
it('does nothing for an empty response', function()
|
||||||
local qflist_count = exec_lua([=[
|
local qflist_count = exec_lua([=[
|
||||||
require'vim.lsp.handlers'['typeHierarchy/supertypes'](nil, nil, {})
|
require'vim.lsp.handlers'['typeHierarchy/supertypes'](nil, nil, {})
|
||||||
|
Loading…
Reference in New Issue
Block a user