Skip to content

Commit d669d15

Browse files
authored
Simplify the method calling (#228)
1 parent 2397d9e commit d669d15

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

src/controllers/libraryController.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as fse from "fs-extra";
55
import * as _ from "lodash";
66
import * as minimatch from "minimatch";
77
import * as path from "path";
8-
import { commands, Disposable, ExtensionContext, Uri, window, workspace, WorkspaceFolder } from "vscode";
9-
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
8+
import { Disposable, ExtensionContext, Uri, window, workspace, WorkspaceFolder } from "vscode";
9+
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
1010
import { Commands } from "../commands";
1111
import { Jdtls } from "../java/jdtls";
1212
import { Settings } from "../settings";
@@ -19,13 +19,11 @@ export class LibraryController implements Disposable {
1919

2020
public constructor(public readonly context: ExtensionContext) {
2121
this.disposable = Disposable.from(
22-
commands.registerCommand(Commands.JAVA_PROJECT_ADD_LIBRARIES,
23-
instrumentOperation(Commands.JAVA_PROJECT_ADD_LIBRARIES, (operationId: string, node: DataNode) => this.addLibraries())),
24-
commands.registerCommand(Commands.JAVA_PROJECT_REMOVE_LIBRARY,
25-
instrumentOperation(Commands.JAVA_PROJECT_REMOVE_LIBRARY, (operationId: string, node: DataNode) =>
26-
this.removeLibrary(Uri.parse(node.uri).fsPath))),
27-
commands.registerCommand(Commands.JAVA_PROJECT_REFRESH_LIBRARIES,
28-
instrumentOperation(Commands.JAVA_PROJECT_REFRESH_LIBRARIES, (operationId: string, node: DataNode) => this.refreshLibraries())),
22+
instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_ADD_LIBRARIES, () => this.addLibraries()),
23+
instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_REMOVE_LIBRARY, (node: DataNode) =>
24+
this.removeLibrary(Uri.parse(node.uri).fsPath)),
25+
instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_REFRESH_LIBRARIES, () =>
26+
this.refreshLibraries()),
2927
);
3028
}
3129

src/controllers/projectController.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fse from "fs-extra";
55
import * as _ from "lodash";
66
import * as path from "path";
77
import { commands, Disposable, ExtensionContext, Uri, window, workspace } from "vscode";
8-
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
8+
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
99
import * as xml2js from "xml2js";
1010
import { Commands } from "../commands";
1111
import { Utility } from "../utility";
@@ -16,8 +16,7 @@ export class ProjectController implements Disposable {
1616

1717
public constructor(public readonly context: ExtensionContext) {
1818
this.disposable = Disposable.from(
19-
commands.registerCommand(Commands.JAVA_PROJECT_CREATE,
20-
instrumentOperation(Commands.JAVA_PROJECT_CREATE, () => this.createJavaProject())),
19+
instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_CREATE, () => this.createJavaProject()),
2120
);
2221
}
2322

src/settings.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
commands, ConfigurationChangeEvent, ExtensionContext,
66
workspace, WorkspaceConfiguration,
77
} from "vscode";
8-
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
8+
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
99
import { Commands } from "./commands";
1010
import { SyncHandler } from "./fileWather";
1111

@@ -40,17 +40,15 @@ export class Settings {
4040

4141
context.subscriptions.push({ dispose: () => { this._configurationListeners = []; } });
4242

43-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_LINKWITHFOLDER,
44-
instrumentOperation(Commands.VIEW_PACKAGE_LINKWITHFOLDER, Settings.linkWithFolderCommand)));
43+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_LINKWITHFOLDER, Settings.linkWithFolderCommand));
4544

46-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_UNLINKWITHFOLDER,
47-
instrumentOperation(Commands.VIEW_PACKAGE_UNLINKWITHFOLDER, Settings.unlinkWithFolderCommand)));
45+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_UNLINKWITHFOLDER, Settings.unlinkWithFolderCommand));
4846

49-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_CHANGETOFLATPACKAGEVIEW,
50-
instrumentOperation(Commands.VIEW_PACKAGE_CHANGETOFLATPACKAGEVIEW, Settings.changeToFlatPackageView)));
47+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_CHANGETOFLATPACKAGEVIEW,
48+
Settings.changeToFlatPackageView));
5149

52-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_CHANGETOHIERARCHICALPACKAGEVIEW,
53-
instrumentOperation(Commands.VIEW_PACKAGE_CHANGETOHIERARCHICALPACKAGEVIEW, Settings.changeToHierarchicalPackageView)));
50+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_CHANGETOHIERARCHICALPACKAGEVIEW,
51+
Settings.changeToHierarchicalPackageView));
5452
}
5553

5654
public static registerConfigurationListener(listener: Listener) {

src/views/dependencyDataProvider.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
commands, Event, EventEmitter, ExtensionContext, ProviderResult, Range,
77
Selection, TextEditorRevealType, TreeDataProvider, TreeItem, Uri, window, workspace,
88
} from "vscode";
9-
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
9+
import { instrumentOperation, instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
1010
import { Commands } from "../commands";
1111
import { Jdtls } from "../java/jdtls";
1212
import { INodeData, NodeKind } from "../java/nodeData";
@@ -28,19 +28,14 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
2828

2929
constructor(public readonly context: ExtensionContext) {
3030
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_REFRESH, (debounce?: boolean) => this.refreshWithLog(debounce)));
31-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS,
32-
instrumentOperation(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (_operationId, node: INodeData) =>
33-
commands.executeCommand("revealFileInOS", Uri.parse(node.uri)))));
34-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH,
35-
instrumentOperation(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (_operationId, node: INodeData) =>
36-
commands.executeCommand("copyFilePath", Uri.parse(node.uri)))));
37-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH,
38-
instrumentOperation(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (_operationId, node: INodeData) =>
39-
commands.executeCommand("copyRelativeFilePath", Uri.parse(node.uri)))));
40-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OPEN_FILE,
41-
instrumentOperation(Commands.VIEW_PACKAGE_OPEN_FILE, (_operationId, uri) => this.openFile(uri))));
42-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OUTLINE,
43-
instrumentOperation(Commands.VIEW_PACKAGE_OUTLINE, (_operationId, uri, range) => this.goToOutline(uri, range))));
31+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node: INodeData) =>
32+
commands.executeCommand("revealFileInOS", Uri.parse(node.uri))));
33+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node: INodeData) =>
34+
commands.executeCommand("copyFilePath", Uri.parse(node.uri))));
35+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node: INodeData) =>
36+
commands.executeCommand("copyRelativeFilePath", Uri.parse(node.uri))));
37+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, (uri) => this.openFile(uri)));
38+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OUTLINE, (uri, range) => this.goToOutline(uri, range)));
4439
Settings.registerConfigurationListener((updatedConfig, oldConfig) => {
4540
if (updatedConfig.refreshDelay !== oldConfig.refreshDelay) {
4641
this.setRefreshDelay(updatedConfig.refreshDelay);

0 commit comments

Comments
 (0)