Skip to content

Commit f22b0c2

Browse files
authored
feat: Make openFile experience consistent with built-in trees (#426)
1 parent 379e101 commit f22b0c2

File tree

10 files changed

+48
-44
lines changed

10 files changed

+48
-44
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"explorer"
1313
],
1414
"engines": {
15-
"vscode": "^1.50.0"
15+
"vscode": "^1.52.0"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -570,7 +570,7 @@
570570
"@types/minimatch": "^3.0.3",
571571
"@types/mocha": "^8.0.4",
572572
"@types/node": "^8.10.66",
573-
"@types/vscode": "1.50.0",
573+
"@types/vscode": "1.52.0",
574574
"copy-webpack-plugin": "^6.3.2",
575575
"glob": "^7.1.6",
576576
"gulp": "^4.0.2",

src/commands.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export namespace Commands {
2020

2121
export const VIEW_PACKAGE_REFRESH = "java.view.package.refresh";
2222

23-
export const VIEW_PACKAGE_OPEN_FILE = "java.view.package.openFile";
24-
2523
export const VIEW_PACKAGE_OUTLINE = "java.view.package.outline";
2624

2725
export const VIEW_PACKAGE_REVEAL_FILE_OS = "java.view.package.revealFileInOS";

src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import { ExtensionContext, tasks } from "vscode";
5-
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation } from "vscode-extension-telemetry-wrapper";
5+
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
66
import { contextManager } from "../extension.bundle";
77
import { Build, Context } from "./constants";
88
import { LibraryController } from "./controllers/libraryController";
@@ -11,6 +11,7 @@ import { init as initExpService } from "./ExperimentationService";
1111
import { ExportJarTaskProvider } from "./exportJarSteps/ExportJarTaskProvider";
1212
import { Settings } from "./settings";
1313
import { syncHandler } from "./syncHandler";
14+
import { EventCounter } from "./utility";
1415
import { DependencyExplorer } from "./views/dependencyExplorer";
1516

1617
export async function activate(context: ExtensionContext): Promise<void> {
@@ -33,6 +34,7 @@ async function activateExtension(_operationId: string, context: ExtensionContext
3334
}
3435

3536
// this method is called when your extension is deactivated
36-
export async function deactivate() {
37+
export async function deactivate(): Promise<void> {
38+
sendInfo("", EventCounter.dict);
3739
await disposeTelemetryWrapper();
3840
}

src/utility.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export class Utility {
3838

3939
}
4040

41+
export class EventCounter {
42+
public static dict: {[key: string]: number} = {};
43+
44+
public static increase(event: string) {
45+
const count = this.dict[event] ?? 0;
46+
this.dict[event] = count + 1;
47+
}
48+
}
49+
4150
export class UserError extends Error {
4251
public context: ITroubleshootingMessage;
4352

src/views/PrimaryTypeNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export class PrimaryTypeNode extends DataNode {
8585
protected get command(): Command {
8686
return {
8787
title: "Open source file content",
88-
command: Commands.VIEW_PACKAGE_OPEN_FILE,
89-
arguments: [this.uri],
88+
command: Commands.VSCODE_OPEN,
89+
arguments: [Uri.parse(this.uri || ""), { preserveFocus: true }],
9090
};
9191
}
9292

src/views/dependencyDataProvider.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
4141
}));
4242
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_CLASS, (node: DataNode) => newJavaClass(node)));
4343
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_PACKAGE, (node: DataNode) => newPackage(node)));
44-
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, (uri) =>
45-
commands.executeCommand(Commands.VSCODE_OPEN, Uri.parse(uri), { preserveFocus: true })));
4644
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OUTLINE, (uri, range) =>
4745
window.showTextDocument(Uri.parse(uri), { selection: range })));
4846
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_BUILD_WORKSPACE, () =>

src/views/dependencyExplorer.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import * as fse from "fs-extra";
55
import * as _ from "lodash";
66
import * as path from "path";
7-
import { commands, Disposable, ExtensionContext, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
8-
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
7+
import { commands, Disposable, ExtensionContext, TextEditor, TreeView,
8+
TreeViewExpansionEvent, TreeViewSelectionChangeEvent, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
9+
import { instrumentOperationAsVsCodeCommand, sendInfo } from "vscode-extension-telemetry-wrapper";
910
import { Commands } from "../commands";
1011
import { Build } from "../constants";
1112
import { deleteFiles } from "../explorerCommands/delete";
1213
import { renameFile } from "../explorerCommands/rename";
1314
import { getCmdNode } from "../explorerCommands/utility";
1415
import { Jdtls } from "../java/jdtls";
1516
import { INodeData } from "../java/nodeData";
16-
import { Utility } from "../utility";
17+
import { EventCounter, Utility } from "../utility";
1718
import { Lock } from "../utils/Lock";
1819
import { DataNode } from "./dataNode";
1920
import { DependencyDataProvider } from "./dependencyDataProvider";
@@ -41,32 +42,27 @@ export class DependencyExplorer implements Disposable {
4142
this._dataProvider = new DependencyDataProvider(context);
4243
this._dependencyViewer = window.createTreeView("javaProjectExplorer", { treeDataProvider: this._dataProvider, showCollapseAll: true });
4344

45+
// register reveal events
4446
context.subscriptions.push(
4547
window.onDidChangeActiveTextEditor((textEditor: TextEditor | undefined) => {
4648
if (this._dependencyViewer.visible && textEditor?.document) {
4749
const uri: Uri = textEditor.document.uri;
4850
this.reveal(uri);
4951
}
5052
}),
51-
);
52-
53-
context.subscriptions.push(
5453
this._dependencyViewer.onDidChangeVisibility((e: TreeViewVisibilityChangeEvent) => {
55-
if (e.visible && window.activeTextEditor) {
56-
this.reveal(window.activeTextEditor.document.uri);
54+
if (e.visible) {
55+
sendInfo("", {projectManagerVisible: 1});
56+
if (window.activeTextEditor) {
57+
this.reveal(window.activeTextEditor.document.uri);
58+
}
5759
}
5860
}),
59-
);
60-
61-
context.subscriptions.push(
6261
this._dataProvider.onDidChangeTreeData(() => {
6362
if (window.activeTextEditor) {
6463
this.reveal(window.activeTextEditor.document.uri);
6564
}
6665
}),
67-
);
68-
69-
context.subscriptions.push(
7066
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_IN_PROJECT_EXPLORER, async (uri: Uri) => {
7167
await commands.executeCommand(Commands.JAVA_PROJECT_EXPLORER_FOCUS);
7268
let fsPath: string = uri.fsPath;
@@ -77,13 +73,26 @@ export class DependencyExplorer implements Disposable {
7773

7874
uri = Uri.file(fsPath);
7975
if ((await fse.stat(fsPath)).isFile()) {
80-
await commands.executeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, uri);
76+
await commands.executeCommand(Commands.VSCODE_OPEN, uri, { preserveFocus: true });
8177
}
8278

8379
this.reveal(uri);
8480
}),
8581
);
8682

83+
// register telemetry events
84+
context.subscriptions.push(
85+
this._dependencyViewer.onDidChangeSelection((_e: TreeViewSelectionChangeEvent<ExplorerNode>) => {
86+
EventCounter.increase("didChangeSelection");
87+
}),
88+
this._dependencyViewer.onDidCollapseElement((_e: TreeViewExpansionEvent<ExplorerNode>) => {
89+
EventCounter.increase("didCollapseElement");
90+
}),
91+
this._dependencyViewer.onDidExpandElement((_e: TreeViewExpansionEvent<ExplorerNode>) => {
92+
EventCounter.increase("didExpandElement");
93+
}),
94+
);
95+
8796
// register keybinding commands
8897
context.subscriptions.push(
8998
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: DataNode) => {
@@ -92,33 +101,21 @@ export class DependencyExplorer implements Disposable {
92101
commands.executeCommand("revealFileInOS", Uri.parse(cmdNode.uri));
93102
}
94103
}),
95-
);
96-
97-
context.subscriptions.push(
98104
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node?: DataNode) => {
99105
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
100106
if (cmdNode.uri) {
101107
commands.executeCommand("copyFilePath", Uri.parse(cmdNode.uri));
102108
}
103109
}),
104-
);
105-
106-
context.subscriptions.push(
107110
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node?: DataNode) => {
108111
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
109112
if (cmdNode.uri) {
110113
commands.executeCommand("copyRelativeFilePath", Uri.parse(cmdNode.uri));
111114
}
112115
}),
113-
);
114-
115-
context.subscriptions.push(
116116
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_RENAME_FILE, (node?: DataNode) => {
117117
renameFile(getCmdNode(this._dependencyViewer.selection[0], node));
118118
}),
119-
);
120-
121-
context.subscriptions.push(
122119
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_MOVE_FILE_TO_TRASH, (node?: DataNode) => {
123120
deleteFiles(getCmdNode(this._dependencyViewer.selection[0], node));
124121
}),

src/views/fileNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { Command, ThemeIcon } from "vscode";
4+
import { Command, ThemeIcon, Uri } from "vscode";
55
import { Commands } from "../commands";
66
import { Explorer } from "../constants";
77
import { INodeData } from "../java/nodeData";
@@ -32,8 +32,8 @@ export class FileNode extends DataNode {
3232
protected get command(): Command {
3333
return {
3434
title: "Open file",
35-
command: Commands.VIEW_PACKAGE_OPEN_FILE,
36-
arguments: [this.uri],
35+
command: Commands.VSCODE_OPEN,
36+
arguments: [Uri.parse(this.uri || ""), { preserveFocus: true }],
3737
};
3838
}
3939

src/views/symbolNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SymbolNode extends BaseSymbolNode {
1616

1717
public getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
1818
const res: ExplorerNode[] = [];
19-
if (this._children && this._children.length) {
19+
if (this._children?.length) {
2020
this._children.forEach((child) => {
2121
res.push(new SymbolNode(child, this.getParent() as PrimaryTypeNode));
2222
});

0 commit comments

Comments
 (0)