Skip to content

Commit abe7f90

Browse files
authored
Ensure Ctrl+Click navigates to the definition in the same file (#33)
* Fix unified definition navigation and Ctrl+Click local resolution * Fix removed custom Go to Definition command from editor title actions to hide the top bar button * Revert "Fix unified definition navigation and Ctrl+Click local resolution" This reverts commit ce01489. * Ensure Ctrl+Click navigates to the definition in the same file
1 parent dd066d5 commit abe7f90

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/ccs/providers/DefinitionDocumentLinkProvider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export class DefinitionDocumentLinkProvider implements vscode.DocumentLinkProvid
4848
);
4949

5050
return queries.map((match) => {
51-
const args = [document.uri.toString(), match.range.start.line, match.range.start.character];
51+
const targetPosition = this.getDefinitionPosition(match.range);
52+
const args = [document.uri.toString(), targetPosition.line, targetPosition.character];
5253
const commandUri = vscode.Uri.parse(
5354
`command:${followDefinitionLinkCommand}?${encodeURIComponent(JSON.stringify(args))}`
5455
);
@@ -58,6 +59,15 @@ export class DefinitionDocumentLinkProvider implements vscode.DocumentLinkProvid
5859
});
5960
}
6061

62+
private getDefinitionPosition(range: vscode.Range): vscode.Position {
63+
const { start, end } = range;
64+
if (end.isAfter(start)) {
65+
const character = Math.max(start.character, end.character - 1);
66+
return new vscode.Position(start.line, character);
67+
}
68+
return start;
69+
}
70+
6171
public dispose(): void {
6272
for (const timeout of this.refreshTimeouts.values()) {
6373
clearTimeout(timeout);

0 commit comments

Comments
 (0)