Skip to content

Commit 55b8c95

Browse files
committed
feat: support workspace symbol resolve
1 parent 1c0ca6f commit 55b8c95

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

src/lsp_client/capability/request/workspace_symbol.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections.abc import Iterator, Sequence
44
from typing import Protocol, override, runtime_checkable
55

6+
import asyncer
67
from loguru import logger
78

89
from lsp_client.jsonrpc.id import jsonrpc_uuid
@@ -19,14 +20,18 @@ class WithRequestWorkspaceSymbol(
1920
Protocol,
2021
):
2122
"""
22-
`workspace/symbol` - https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_symbol
23+
- `workspace/symbol` - https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_symbol
24+
- `workspace/symbolResolve` - https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_symbolResolve
2325
"""
2426

2527
@override
2628
@classmethod
2729
def iter_methods(cls) -> Iterator[str]:
2830
yield from super().iter_methods()
29-
yield from (lsp_type.WORKSPACE_SYMBOL,)
31+
yield from (
32+
lsp_type.WORKSPACE_SYMBOL,
33+
lsp_type.WORKSPACE_SYMBOL_RESOLVE,
34+
)
3035

3136
@override
3237
@classmethod
@@ -71,6 +76,34 @@ async def request_workspace_symbol(
7176
lsp_type.WorkspaceSymbolParams(query=query)
7277
)
7378

79+
async def _request_workspace_symbol_resolve(
80+
self, params: lsp_type.WorkspaceSymbol
81+
) -> lsp_type.WorkspaceSymbol:
82+
return await self.request(
83+
lsp_type.WorkspaceSymbolResolveRequest(
84+
id=jsonrpc_uuid(),
85+
params=params,
86+
),
87+
schema=lsp_type.WorkspaceSymbolResolveResponse,
88+
)
89+
90+
async def request_workspace_symbol_resolve(
91+
self, symbol: lsp_type.WorkspaceSymbol
92+
) -> lsp_type.WorkspaceSymbol:
93+
return await self._request_workspace_symbol_resolve(symbol)
94+
95+
async def resolve_workspace_symbols(
96+
self,
97+
symbols: Sequence[lsp_type.WorkspaceSymbol],
98+
) -> Sequence[lsp_type.WorkspaceSymbol]:
99+
tasks: list[asyncer.SoonValue[lsp_type.WorkspaceSymbol]] = []
100+
async with asyncer.create_task_group() as tg:
101+
tasks = [
102+
tg.soonify(self.request_workspace_symbol_resolve)(symbol)
103+
for symbol in symbols
104+
]
105+
return [task.value for task in tasks]
106+
74107
@deprecated("Use 'request_workspace_symbol_list' instead.")
75108
async def request_workspace_symbol_information_list(
76109
self, query: str
@@ -85,11 +118,14 @@ async def request_workspace_symbol_information_list(
85118
return None
86119

87120
async def request_workspace_symbol_list(
88-
self, query: str
121+
self, query: str, *, resolve: bool = False
89122
) -> Sequence[lsp_type.WorkspaceSymbol] | None:
90123
match await self.request_workspace_symbol(query):
91124
case result if is_workspace_symbols(result):
92-
return list(result)
125+
res = list(result)
126+
if resolve:
127+
return await self.resolve_workspace_symbols(res)
128+
return res
93129
case other:
94130
logger.warning(
95131
"Workspace symbol returned with unexpected result: {}", other

0 commit comments

Comments
 (0)