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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@
}
],
"editor/title": [
{
"command": "vscode-objectscript.ccs.goToDefinition",
"group": "navigation@0",
"when": "editorTextFocus && editorLangId =~ /^objectscript/"
},
{
"command": "-editor.action.revealDefinition",
"group": "navigation@0",
Expand Down
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();
}
}
26 changes: 26 additions & 0 deletions src/ccs/commands/goToDefinitionLocalFirst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as vscode from "vscode";

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

export async function goToDefinitionLocalFirst(): Promise<void> {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}

const { document, selection } = editor;
const position = selection.active;
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;
}
} finally {
tokenSource.dispose();
}

await vscode.commands.executeCommand("editor.action.revealDefinition");
}
23 changes: 0 additions & 23 deletions src/ccs/commands/navigation/followDefinitionLink.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/ccs/commands/navigation/goToDefinitionLocalFirst.ts

This file was deleted.

148 changes: 0 additions & 148 deletions src/ccs/commands/navigation/navigateDefinition.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/ccs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export {
type QueryMatch,
type QueryKind,
} from "./features/definitionLookup/extractQuery";
export { goToDefinitionLocalFirst } from "./commands/navigation/goToDefinitionLocalFirst";
export { followDefinitionLink } from "./commands/navigation/followDefinitionLink";
export { navigateToDefinition, type NavigateOpts } from "./commands/navigation/navigateDefinition";
export { goToDefinitionLocalFirst } from "./commands/goToDefinitionLocalFirst";
export { followDefinitionLink } from "./commands/followDefinitionLink";
export { PrioritizedDefinitionProvider } from "./providers/PrioritizedDefinitionProvider";
export {
DefinitionDocumentLinkProvider,
Expand Down