|
17 | 17 | from lsprotocol.types import Location |
18 | 18 |
|
19 | 19 | from .abc import Capability, ClientProtocol |
| 20 | +from .exception import UnsupportedCapabilityError |
20 | 21 | from .locate import LocateCapability |
21 | 22 | from .symbol import SymbolCapability |
22 | 23 |
|
23 | 24 |
|
24 | 25 | @runtime_checkable |
25 | 26 | class DefinitionClient( |
26 | 27 | WithRequestDefinition, |
27 | | - WithRequestDeclaration, |
28 | | - WithRequestTypeDefinition, |
29 | 28 | WithRequestDocumentSymbol, |
30 | 29 | WithRequestHover, |
31 | 30 | ClientProtocol, |
@@ -59,10 +58,24 @@ async def __call__(self, req: DefinitionRequest) -> DefinitionResponse | None: |
59 | 58 | file_path, lsp_pos |
60 | 59 | ) |
61 | 60 | case "declaration": |
| 61 | + if not isinstance(self.client, WithRequestDeclaration): |
| 62 | + raise UnsupportedCapabilityError( |
| 63 | + "Client does not support 'textDocument/declaration'. " |
| 64 | + "To find declarations, you can: " |
| 65 | + "1) Use 'definition' mode (most language servers treat them similarly); " |
| 66 | + "2) For C/C++, check corresponding header files manually." |
| 67 | + ) |
62 | 68 | locations = await self.client.request_declaration_locations( |
63 | 69 | file_path, lsp_pos |
64 | 70 | ) |
65 | 71 | case "type_definition": |
| 72 | + if not isinstance(self.client, WithRequestTypeDefinition): |
| 73 | + raise UnsupportedCapabilityError( |
| 74 | + "Client does not support 'textDocument/typeDefinition'. " |
| 75 | + "To find type definitions, you can: " |
| 76 | + "1) Use 'definition' on the type name itself if visible; " |
| 77 | + "2) Use 'hover' to see the type name and then search for it." |
| 78 | + ) |
66 | 79 | locations = await self.client.request_type_definition_locations( |
67 | 80 | file_path, lsp_pos |
68 | 81 | ) |
|
0 commit comments