Skip to content

Commit 1d26c7b

Browse files
committed
feat: support manual construction of Location from LocationLink in navigation requests
1 parent 192ceec commit 1d26c7b

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

src/lsp_client/capability/request/declaration.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ async def request_declaration_locations(
8181
return [loc]
8282
case locations if is_locations(locations):
8383
return list(locations)
84+
case links if is_location_links(links):
85+
return [
86+
lsp_type.Location(
87+
uri=link.target_uri, range=link.target_selection_range
88+
)
89+
for link in links
90+
]
91+
case None:
92+
return None
8493
case other:
8594
logger.warning("Declaration returned with unexpected result: {}", other)
8695
return None
@@ -91,6 +100,8 @@ async def request_declaration_links(
91100
match await self.request_declaration(file_path, position):
92101
case links if is_location_links(links):
93102
return list(links)
103+
case None:
104+
return None
94105
case other:
95106
logger.warning("Declaration returned with unexpected result: {}", other)
96107
return None

src/lsp_client/capability/request/definition.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,21 @@ async def request_definition_locations(
8383
file_path: AnyPath,
8484
position: Position,
8585
) -> Sequence[lsp_type.Location] | None:
86-
match await self.request_definition(
87-
file_path,
88-
position,
89-
):
86+
match await self.request_definition(file_path, position):
9087
case lsp_type.Location() as loc:
9188
return [loc]
9289
case locations if is_locations(locations):
9390
return list(locations)
91+
case links if is_location_links(links):
92+
return [
93+
lsp_type.Location(
94+
uri=link.target_uri,
95+
range=link.target_selection_range,
96+
)
97+
for link in links
98+
]
99+
case None:
100+
return None
94101
case other:
95102
logger.warning("Definition returned with unexpected result: {}", other)
96103
return None
@@ -100,12 +107,11 @@ async def request_definition_links(
100107
file_path: AnyPath,
101108
position: Position,
102109
) -> Sequence[lsp_type.LocationLink] | None:
103-
match await self.request_definition(
104-
file_path,
105-
position,
106-
):
110+
match await self.request_definition(file_path, position):
107111
case links if is_location_links(links):
108112
return list(links)
113+
case None:
114+
return None
109115
case other:
110116
logger.warning("Definition returned with unexpected result: {}", other)
111117
return None

src/lsp_client/capability/request/implementation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ async def request_implementation_locations(
8181
return [loc]
8282
case locations if is_locations(locations):
8383
return list(locations)
84+
case links if is_location_links(links):
85+
return [
86+
lsp_type.Location(
87+
uri=link.target_uri, range=link.target_selection_range
88+
)
89+
for link in links
90+
]
91+
case None:
92+
return None
8493
case other:
8594
logger.warning(
8695
"Implementation returned with unexpected result: {}", other
@@ -93,6 +102,8 @@ async def request_implementation_links(
93102
match await self.request_implementation(file_path, position):
94103
case links if is_location_links(links):
95104
return list(links)
105+
case None:
106+
return None
96107
case other:
97108
logger.warning(
98109
"Implementation returned with unexpected result: {}", other

src/lsp_client/capability/request/type_definition.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ async def request_type_definition_locations(
8383
return [loc]
8484
case locations if is_locations(locations):
8585
return list(locations)
86+
case links if is_location_links(links):
87+
return [
88+
lsp_type.Location(
89+
uri=link.target_uri, range=link.target_selection_range
90+
)
91+
for link in links
92+
]
93+
case None:
94+
return None
8695
case other:
8796
logger.warning(
8897
"TypeDefinition returned with unexpected result: {}", other
@@ -95,6 +104,8 @@ async def request_type_definition_links(
95104
match await self.request_type_definition(file_path, position):
96105
case links if is_location_links(links):
97106
return list(links)
107+
case None:
108+
return None
98109
case other:
99110
logger.warning(
100111
"TypeDefinition returned with unexpected result: {}", other

0 commit comments

Comments
 (0)