Skip to content

Commit 2969cae

Browse files
committed
Align Ctrl+Click navigation flow with F12 for smoother and consistent definition jumps (#24)
1 parent 9df8993 commit 2969cae

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as vscode from "vscode";
2+
3+
import { lookupCcsDefinition } from "../features/definitionLookup/lookup";
4+
5+
export async function followDefinitionLink(documentUri: string, line: number, character: number): Promise<void> {
6+
if (!documentUri || typeof line !== "number" || typeof character !== "number") {
7+
return;
8+
}
9+
10+
const uri = vscode.Uri.parse(documentUri);
11+
const document =
12+
vscode.workspace.textDocuments.find((doc) => doc.uri.toString() === documentUri) ??
13+
(await vscode.workspace.openTextDocument(uri));
14+
15+
const position = new vscode.Position(line, character);
16+
const tokenSource = new vscode.CancellationTokenSource();
17+
18+
try {
19+
const location = await lookupCcsDefinition(document, position, tokenSource.token);
20+
if (location) {
21+
await vscode.window.showTextDocument(location.uri, { selection: location.range });
22+
return;
23+
}
24+
25+
await vscode.window.showTextDocument(document, {
26+
selection: new vscode.Range(position, position),
27+
});
28+
await vscode.commands.executeCommand("editor.action.revealDefinition");
29+
} finally {
30+
tokenSource.dispose();
31+
}
32+
}

src/ccs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
type QueryKind,
1515
} from "./features/definitionLookup/extractQuery";
1616
export { goToDefinitionLocalFirst } from "./commands/goToDefinitionLocalFirst";
17+
export { followDefinitionLink } from "./commands/followDefinitionLink";
1718
export { PrioritizedDefinitionProvider } from "./providers/PrioritizedDefinitionProvider";
1819
export {
1920
DefinitionDocumentLinkProvider,

src/extension.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ import {
167167
PrioritizedDefinitionProvider,
168168
DefinitionDocumentLinkProvider,
169169
followDefinitionLinkCommand,
170+
followDefinitionLink,
170171
goToDefinitionLocalFirst,
171172
resolveContextExpression,
172173
showGlobalDocumentation,
@@ -1298,22 +1299,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12981299
followDefinitionLinkCommand,
12991300
async (documentUri: string, line: number, character: number) => {
13001301
sendCommandTelemetryEvent("ccs.followDefinitionLink");
1301-
if (!documentUri || typeof line !== "number" || typeof character !== "number") {
1302-
return;
1303-
}
1304-
1305-
const uri = vscode.Uri.parse(documentUri);
1306-
const document =
1307-
vscode.workspace.textDocuments.find((doc) => doc.uri.toString() === documentUri) ??
1308-
(await vscode.workspace.openTextDocument(uri));
1309-
1310-
const position = new vscode.Position(line, character);
1311-
const selectionRange = new vscode.Range(position, position);
1312-
const editor = await vscode.window.showTextDocument(document, { selection: selectionRange });
1313-
editor.selection = new vscode.Selection(position, position);
1314-
editor.revealRange(selectionRange);
1315-
1316-
await goToDefinitionLocalFirst();
1302+
await followDefinitionLink(documentUri, line, character);
13171303
}
13181304
),
13191305
vscode.commands.registerCommand("vscode-objectscript.debug", (program: string, askArgs: boolean) => {

0 commit comments

Comments
 (0)