Skip to content

Commit 2cf7b96

Browse files
author
Keen Yee Liau
committed
fix: use LocationLink for onDefinition
Before this, lsp.Location[] is returned by onDefinition, and the results do not contain the originSelectionRange. If user hovers over templateUrl for example, they'd see ``` @component({ templateUrl: './app.component.html', }) class AppComponent {} ``` `app`, `component`, and `html` highlighted separately. Returning lsp.LocationLink[] solves this issue.
1 parent 0087dd7 commit 2cf7b96

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server/src/server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,21 @@ connection.onDefinition((params: lsp.TextDocumentPositionParams) => {
164164
if (!definition || !definition.definitions) {
165165
return;
166166
}
167-
const results: lsp.Location[] = [];
167+
const originSelectionRange = tsTextSpanToLspRange(scriptInfo, definition.textSpan);
168+
const results: lsp.LocationLink[] = [];
168169
for (const d of definition.definitions) {
169170
const scriptInfo = tsProjSvc.getScriptInfo(d.fileName);
170171
if (!scriptInfo) {
171172
continue;
172173
}
173-
const uri = filePathToUri(d.fileName);
174+
const targetUri = filePathToUri(d.fileName);
174175
const range = tsTextSpanToLspRange(scriptInfo, d.textSpan);
175-
results.push(lsp.Location.create(uri, range));
176+
results.push({
177+
originSelectionRange,
178+
targetUri,
179+
targetRange: range,
180+
targetSelectionRange: range,
181+
});
176182
}
177183
return results;
178184
});

0 commit comments

Comments
 (0)