-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathOpenFileInPackage.ts
More file actions
57 lines (44 loc) · 1.53 KB
/
OpenFileInPackage.ts
File metadata and controls
57 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (c) 2020 Certinia Inc. All rights reserved.
*/
import {
commands,
Position,
Selection,
ViewColumn,
workspace,
type TextDocumentShowOptions,
} from 'vscode';
import { Context } from '../Context.js';
import { getMethodLine, parseApex } from '../salesforce/ApexParser/ApexSymbolLocator.js';
import { parseSymbol } from '../salesforce/codesymbol/ApexSymbolParser.js';
export class OpenFileInPackage {
static async openFileForSymbol(context: Context, symbolName: string): Promise<void> {
if (!symbolName?.trim()) {
return;
}
await context.workspaceManager.initialiseWorkspaceProjectInfo();
const apexSymbol = parseSymbol(symbolName, context.workspaceManager.getAllProjects());
const uri = await context.findSymbol(apexSymbol);
if (!uri) {
return;
}
const document = await workspace.openTextDocument(uri);
const parsedRoot = parseApex(document.getText());
const symbolLocation = getMethodLine(parsedRoot, apexSymbol);
if (!symbolLocation.isExactMatch) {
context.display.showErrorMessage(
`Symbol '${symbolLocation.missingSymbol}' could not be found in file '${apexSymbol.fullSymbol}'`,
);
}
const zeroIndexedLineNumber = symbolLocation.line - 1;
const pos = new Position(zeroIndexedLineNumber, 0);
const options: TextDocumentShowOptions = {
preserveFocus: false,
preview: false,
viewColumn: ViewColumn.Active,
selection: new Selection(pos, pos),
};
commands.executeCommand('vscode.open', uri, options);
}
}