Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make openFile experience consistent with built-in trees #426

Merged
merged 2 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export namespace Commands {

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

export const VIEW_PACKAGE_OPEN_FILE = "java.view.package.openFile";

export const VIEW_PACKAGE_OUTLINE = "java.view.package.outline";
xqzlgy2 marked this conversation as resolved.
Show resolved Hide resolved

export const VIEW_PACKAGE_REVEAL_FILE_OS = "java.view.package.revealFileInOS";
Expand Down
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import { ExtensionContext, tasks } from "vscode";
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation } from "vscode-extension-telemetry-wrapper";
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
import { contextManager } from "../extension.bundle";
import { Build, Context } from "./constants";
import { LibraryController } from "./controllers/libraryController";
Expand All @@ -11,6 +11,7 @@ import { init as initExpService } from "./ExperimentationService";
import { ExportJarTaskProvider } from "./exportJarSteps/ExportJarTaskProvider";
import { Settings } from "./settings";
import { syncHandler } from "./syncHandler";
import { EventCounter } from "./utility";
import { DependencyExplorer } from "./views/dependencyExplorer";

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

// this method is called when your extension is deactivated
export async function deactivate() {
export async function deactivate(): Promise<void> {
sendInfo("", EventCounter.dict);
await disposeTelemetryWrapper();
}
17 changes: 17 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Uri, window, workspace, WorkspaceFolder } from "vscode";
import { setUserError } from "vscode-extension-telemetry-wrapper";
import { languageServerApiManager } from "./languageServerApi/languageServerApiManager";
import { Settings } from "./settings";
import { Lock } from "./utils/Lock";

export class Utility {

Expand Down Expand Up @@ -38,6 +39,22 @@ export class Utility {

}

export class EventCounter {
public static dict: {[key: string]: number} = {};

public static async increase(event: string) {
try {
await this._lock.acquire();
xqzlgy2 marked this conversation as resolved.
Show resolved Hide resolved
const count = this.dict[event] ?? 0;
this.dict[event] = count + 1;
} finally {
this._lock.release();
}
}

private static _lock: Lock = new Lock();
}

export class UserError extends Error {
public context: ITroubleshootingMessage;

Expand Down
4 changes: 2 additions & 2 deletions src/views/PrimaryTypeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export class PrimaryTypeNode extends DataNode {
protected get command(): Command {
return {
title: "Open source file content",
command: Commands.VIEW_PACKAGE_OPEN_FILE,
arguments: [this.uri],
command: Commands.VSCODE_OPEN,
arguments: [Uri.parse(this.uri || ""), { preserveFocus: true }],
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
}));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_CLASS, (node: DataNode) => newJavaClass(node)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_PACKAGE, (node: DataNode) => newPackage(node)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, (uri) =>
commands.executeCommand(Commands.VSCODE_OPEN, Uri.parse(uri), { preserveFocus: true })));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OUTLINE, (uri, range) =>
window.showTextDocument(Uri.parse(uri), { selection: range })));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_BUILD_WORKSPACE, () =>
Expand Down
36 changes: 30 additions & 6 deletions src/views/dependencyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import * as fse from "fs-extra";
import * as _ from "lodash";
import * as path from "path";
import { commands, Disposable, ExtensionContext, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
import { commands, Disposable, ExtensionContext, TextEditor, TreeView,
TreeViewExpansionEvent, TreeViewSelectionChangeEvent, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
import { instrumentOperationAsVsCodeCommand, sendInfo } from "vscode-extension-telemetry-wrapper";
import { Commands } from "../commands";
import { Build } from "../constants";
import { deleteFiles } from "../explorerCommands/delete";
import { renameFile } from "../explorerCommands/rename";
import { getCmdNode } from "../explorerCommands/utility";
import { Jdtls } from "../java/jdtls";
import { INodeData } from "../java/nodeData";
import { Utility } from "../utility";
import { EventCounter, Utility } from "../utility";
import { Lock } from "../utils/Lock";
import { DataNode } from "./dataNode";
import { DependencyDataProvider } from "./dependencyDataProvider";
Expand Down Expand Up @@ -41,6 +42,7 @@ export class DependencyExplorer implements Disposable {
this._dataProvider = new DependencyDataProvider(context);
this._dependencyViewer = window.createTreeView("javaProjectExplorer", { treeDataProvider: this._dataProvider, showCollapseAll: true });

// register reveal events
context.subscriptions.push(
window.onDidChangeActiveTextEditor((textEditor: TextEditor | undefined) => {
if (this._dependencyViewer.visible && textEditor?.document) {
Expand All @@ -52,8 +54,11 @@ export class DependencyExplorer implements Disposable {

context.subscriptions.push(
this._dependencyViewer.onDidChangeVisibility((e: TreeViewVisibilityChangeEvent) => {
if (e.visible && window.activeTextEditor) {
this.reveal(window.activeTextEditor.document.uri);
if (e.visible) {
sendInfo("", {projectManagerVisible: 1});
if (window.activeTextEditor) {
this.reveal(window.activeTextEditor.document.uri);
}
}
}),
);
Expand All @@ -77,13 +82,32 @@ export class DependencyExplorer implements Disposable {

uri = Uri.file(fsPath);
if ((await fse.stat(fsPath)).isFile()) {
await commands.executeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, uri);
await commands.executeCommand(Commands.VSCODE_OPEN, uri, { preserveFocus: true });
}

this.reveal(uri);
}),
);

// register telemetry events
context.subscriptions.push(
this._dependencyViewer.onDidChangeSelection(async (_e: TreeViewSelectionChangeEvent<ExplorerNode>) => {
xqzlgy2 marked this conversation as resolved.
Show resolved Hide resolved
await EventCounter.increase("didChangeSelection");
}),
);

context.subscriptions.push(
this._dependencyViewer.onDidCollapseElement(async (_e: TreeViewExpansionEvent<ExplorerNode>) => {
await EventCounter.increase("didCollapseElement");
}),
);

context.subscriptions.push(
this._dependencyViewer.onDidExpandElement(async (_e: TreeViewExpansionEvent<ExplorerNode>) => {
await EventCounter.increase("didExpandElement");
}),
);

// register keybinding commands
context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: DataNode) => {
Expand Down
6 changes: 3 additions & 3 deletions src/views/fileNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { Command, ThemeIcon } from "vscode";
import { Command, ThemeIcon, Uri } from "vscode";
import { Commands } from "../commands";
import { Explorer } from "../constants";
import { INodeData } from "../java/nodeData";
Expand Down Expand Up @@ -32,8 +32,8 @@ export class FileNode extends DataNode {
protected get command(): Command {
return {
title: "Open file",
command: Commands.VIEW_PACKAGE_OPEN_FILE,
arguments: [this.uri],
command: Commands.VSCODE_OPEN,
arguments: [Uri.parse(this.uri || ""), { preserveFocus: true }],
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/symbolNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SymbolNode extends BaseSymbolNode {

public getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
const res: ExplorerNode[] = [];
if (this._children && this._children.length) {
if (this._children?.length) {
this._children.forEach((child) => {
res.push(new SymbolNode(child, this.getParent() as PrimaryTypeNode));
});
Expand Down