Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/ccs/commands/followDefinitionLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as vscode from "vscode";

import { lookupCcsDefinition } from "../features/definitionLookup/lookup";

export async function followDefinitionLink(documentUri: string, line: number, character: number): Promise<void> {
if (!documentUri || typeof line !== "number" || typeof character !== "number") {
return;
}

const uri = vscode.Uri.parse(documentUri);
const document =
vscode.workspace.textDocuments.find((doc) => doc.uri.toString() === documentUri) ??
(await vscode.workspace.openTextDocument(uri));

const position = new vscode.Position(line, character);
const tokenSource = new vscode.CancellationTokenSource();

try {
const location = await lookupCcsDefinition(document, position, tokenSource.token);
if (location) {
await vscode.window.showTextDocument(location.uri, { selection: location.range });
return;
}

await vscode.window.showTextDocument(document, {
selection: new vscode.Range(position, position),
});
await vscode.commands.executeCommand("editor.action.revealDefinition");
} finally {
tokenSource.dispose();
}
}
1 change: 1 addition & 0 deletions src/ccs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
type QueryKind,
} from "./features/definitionLookup/extractQuery";
export { goToDefinitionLocalFirst } from "./commands/goToDefinitionLocalFirst";
export { followDefinitionLink } from "./commands/followDefinitionLink";
export { PrioritizedDefinitionProvider } from "./providers/PrioritizedDefinitionProvider";
export {
DefinitionDocumentLinkProvider,
Expand Down
18 changes: 2 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ import {
PrioritizedDefinitionProvider,
DefinitionDocumentLinkProvider,
followDefinitionLinkCommand,
followDefinitionLink,
goToDefinitionLocalFirst,
resolveContextExpression,
showGlobalDocumentation,
Expand Down Expand Up @@ -1298,22 +1299,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
followDefinitionLinkCommand,
async (documentUri: string, line: number, character: number) => {
sendCommandTelemetryEvent("ccs.followDefinitionLink");
if (!documentUri || typeof line !== "number" || typeof character !== "number") {
return;
}

const uri = vscode.Uri.parse(documentUri);
const document =
vscode.workspace.textDocuments.find((doc) => doc.uri.toString() === documentUri) ??
(await vscode.workspace.openTextDocument(uri));

const position = new vscode.Position(line, character);
const selectionRange = new vscode.Range(position, position);
const editor = await vscode.window.showTextDocument(document, { selection: selectionRange });
editor.selection = new vscode.Selection(position, position);
editor.revealRange(selectionRange);

await goToDefinitionLocalFirst();
await followDefinitionLink(documentUri, line, character);
}
),
vscode.commands.registerCommand("vscode-objectscript.debug", (program: string, askArgs: boolean) => {
Expand Down