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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"explorer"
],
"engines": {
"vscode": "^1.50.0"
"vscode": "^1.52.0"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -570,7 +570,7 @@
"@types/minimatch": "^3.0.3",
"@types/mocha": "^8.0.4",
"@types/node": "^8.10.66",
"@types/vscode": "1.50.0",
"@types/vscode": "1.52.0",
"copy-webpack-plugin": "^6.3.2",
"glob": "^7.1.6",
"gulp": "^4.0.2",
Expand Down
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";

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();
}
9 changes: 9 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export class Utility {

}

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

public static increase(event: string) {
const count = this.dict[event] ?? 0;
this.dict[event] = count + 1;
}
}

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
51 changes: 24 additions & 27 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,32 +42,27 @@ 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) {
const uri: Uri = textEditor.document.uri;
this.reveal(uri);
}
}),
);

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);
}
}
}),
);

context.subscriptions.push(
this._dataProvider.onDidChangeTreeData(() => {
if (window.activeTextEditor) {
this.reveal(window.activeTextEditor.document.uri);
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_IN_PROJECT_EXPLORER, async (uri: Uri) => {
await commands.executeCommand(Commands.JAVA_PROJECT_EXPLORER_FOCUS);
let fsPath: string = uri.fsPath;
Expand All @@ -77,13 +73,26 @@ 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((_e: TreeViewSelectionChangeEvent<ExplorerNode>) => {
EventCounter.increase("didChangeSelection");
}),
this._dependencyViewer.onDidCollapseElement((_e: TreeViewExpansionEvent<ExplorerNode>) => {
EventCounter.increase("didCollapseElement");
}),
this._dependencyViewer.onDidExpandElement((_e: TreeViewExpansionEvent<ExplorerNode>) => {
EventCounter.increase("didExpandElement");
}),
);

// register keybinding commands
context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: DataNode) => {
Expand All @@ -92,33 +101,21 @@ export class DependencyExplorer implements Disposable {
commands.executeCommand("revealFileInOS", Uri.parse(cmdNode.uri));
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node?: DataNode) => {
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
if (cmdNode.uri) {
commands.executeCommand("copyFilePath", Uri.parse(cmdNode.uri));
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node?: DataNode) => {
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
if (cmdNode.uri) {
commands.executeCommand("copyRelativeFilePath", Uri.parse(cmdNode.uri));
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_RENAME_FILE, (node?: DataNode) => {
renameFile(getCmdNode(this._dependencyViewer.selection[0], node));
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_MOVE_FILE_TO_TRASH, (node?: DataNode) => {
deleteFiles(getCmdNode(this._dependencyViewer.selection[0], node));
}),
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