src/goModifyTags.ts: refactor goModifyTags to factory pattern
Change-Id: Id2518cbf6a41aac8d2561d444b102a5b0d411b60
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/404580
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/commands/index.ts b/src/commands/index.ts
index 4a48fdd..aac8912 100644
--- a/src/commands/index.ts
+++ b/src/commands/index.ts
@@ -10,6 +10,7 @@
export { applyCoverprofile } from './applyCoverprofile';
export { getConfiguredGoTools } from './getConfiguredGoTools';
export { getCurrentGoPath } from './getCurrentGoPath';
+export { addTags, removeTags } from '../goModifytags';
export { installTools } from './installTools';
export { showCommands } from './showCommands';
export { startDebugSession } from './startDebugSession';
diff --git a/src/goMain.ts b/src/goMain.ts
index bda4338..3458f08 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -47,7 +47,6 @@
import { lintCode } from './goLint';
import { logVerbose, setLogConfig } from './goLogging';
import { GO_MODE } from './goMode';
-import { addTags, removeTags } from './goModifytags';
import { GO111MODULE, goModInit, isModSupported } from './goModules';
import { playgroundCommand } from './goPlayground';
import { GoReferencesCodeLensProvider } from './goReferencesCodelens';
@@ -219,8 +218,8 @@
registerCommand('go.gopath', commands.getCurrentGoPath);
registerCommand('go.locate.tools', commands.getConfiguredGoTools);
- registerCommand('go.add.tags', () => addTags);
- registerCommand('go.remove.tags', () => removeTags);
+ registerCommand('go.add.tags', commands.addTags);
+ registerCommand('go.remove.tags', commands.removeTags);
registerCommand('go.fill.struct', () => () => runFillStruct(vscode.window.activeTextEditor));
registerCommand('go.impl.cursor', () => implCursor);
registerCommand('go.godoctor.extract', () => extractFunction);
diff --git a/src/goModifytags.ts b/src/goModifytags.ts
index 9ea6ea6..5cd87ec 100644
--- a/src/goModifytags.ts
+++ b/src/goModifytags.ts
@@ -9,6 +9,7 @@
import cp = require('child_process');
import vscode = require('vscode');
+import { CommandFactory } from './commands';
import { getGoConfig } from './config';
import { toolExecutionEnvironment } from './goEnv';
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
@@ -30,7 +31,7 @@
template: string;
}
-export function addTags(commandArgs: GoTagsConfig) {
+export const addTags: CommandFactory = () => (commandArgs: GoTagsConfig) => {
const args = getCommonArgs();
if (!args) {
return;
@@ -60,9 +61,9 @@
runGomodifytags(args);
}
);
-}
+};
-export function removeTags(commandArgs: GoTagsConfig) {
+export const removeTags: CommandFactory = () => (commandArgs: GoTagsConfig) => {
const args = getCommonArgs();
if (!args) {
return;
@@ -83,7 +84,7 @@
}
runGomodifytags(args);
});
-}
+};
function getCommonArgs(): string[] {
const editor = vscode.window.activeTextEditor;