src/goMain.ts: move runBuilds to commands
Change-Id: Id9b8f462e1852c5ce9ae015840abc59f711422ff
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/405550
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/commands/index.ts b/src/commands/index.ts
index e239205..d82ba4a 100644
--- a/src/commands/index.ts
+++ b/src/commands/index.ts
@@ -16,6 +16,7 @@
export { addTags, removeTags } from '../goModifytags';
export * from '../goTest';
export { installTools } from './installTools';
+export { runBuilds } from './runBuilds';
export { showCommands } from './showCommands';
export { startDebugSession } from './startDebugSession';
export { startLanguageServer } from './startLanguageServer';
diff --git a/src/commands/runBuilds.ts b/src/commands/runBuilds.ts
new file mode 100644
index 0000000..17c91fe
--- /dev/null
+++ b/src/commands/runBuilds.ts
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------
+ * Copyright 2022 The Go Authors. All rights reserved.
+ * Licensed under the MIT License. See LICENSE in the project root for license information.
+ *--------------------------------------------------------*/
+
+import * as vscode from 'vscode';
+
+import { buildDiagnosticCollection, lintDiagnosticCollection, vetDiagnosticCollection } from '../goMain';
+import { check } from '../goCheck';
+import { CommandFactory } from '.';
+import { handleDiagnosticErrors } from '../util';
+
+export const runBuilds: CommandFactory = () => (
+ document: vscode.TextDocument,
+ goConfig: vscode.WorkspaceConfiguration
+) => {
+ if (document.languageId !== 'go') {
+ return;
+ }
+
+ buildDiagnosticCollection?.clear();
+ lintDiagnosticCollection?.clear();
+ vetDiagnosticCollection?.clear();
+ check(document.uri, goConfig)
+ .then((results) => {
+ results.forEach((result) => {
+ handleDiagnosticErrors(document, result.errors, result.diagnosticCollection);
+ });
+ })
+ .catch((err) => {
+ vscode.window.showInformationMessage('Error: ' + err);
+ });
+};
diff --git a/src/goMain.ts b/src/goMain.ts
index 32428d9..5ac6fb2 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -12,7 +12,7 @@
import { getGoConfig, getGoplsConfig } from './config';
import { browsePackages } from './goBrowsePackage';
import { buildCode } from './goBuild';
-import { check, notifyIfGeneratedFile, removeTestStatus } from './goCheck';
+import { notifyIfGeneratedFile, removeTestStatus } from './goCheck';
import {
applyCodeCoverage,
initCoverageDecorators,
@@ -61,16 +61,7 @@
updateGlobalState
} from './stateUtils';
import { cancelRunningTests, showTestOutput } from './testUtils';
-import {
- cleanupTempDir,
- getBinPath,
- getGoVersion,
- getToolsGopath,
- GoVersion,
- handleDiagnosticErrors,
- isGoPathSet,
- resolvePath
-} from './util';
+import { cleanupTempDir, getBinPath, getGoVersion, getToolsGopath, GoVersion, isGoPathSet, resolvePath } from './util';
import { clearCacheForTools, dirExists } from './utils/pathUtils';
import { WelcomePanel } from './welcome';
import vscode = require('vscode');
@@ -162,19 +153,20 @@
await commands.startLanguageServer(ctx, goCtx)(RestartReason.ACTIVATION);
- const activeDoc = vscode.window.activeTextEditor?.document;
- if (!goCtx.languageServerIsRunning && activeDoc?.languageId === 'go' && isGoPathSet()) {
- // Check mod status so that cache is updated and then run build/lint/vet
- isModSupported(activeDoc.uri).then(() => {
- runBuilds(activeDoc, getGoConfig());
- });
- }
-
initCoverageDecorators(ctx);
const registerCommand = commands.createRegisterCommand(ctx, goCtx);
registerCommand('go.languageserver.restart', commands.startLanguageServer);
+ registerCommand('go.builds.run', commands.runBuilds);
+
+ const activeDoc = vscode.window.activeTextEditor?.document;
+ if (!goCtx.languageServerIsRunning && activeDoc?.languageId === 'go' && isGoPathSet()) {
+ // Check mod status so that cache is updated and then run build/lint/vet
+ isModSupported(activeDoc.uri).then(() => {
+ vscode.commands.executeCommand('go.builds.run', activeDoc, getGoConfig(activeDoc.uri));
+ });
+ }
// Subscribe to notifications for changes to the configuration
// of the language server, even if it's not currently in use.
@@ -359,25 +351,6 @@
]);
}
-function runBuilds(document: vscode.TextDocument, goConfig: vscode.WorkspaceConfiguration) {
- if (document.languageId !== 'go') {
- return;
- }
-
- buildDiagnosticCollection.clear();
- lintDiagnosticCollection.clear();
- vetDiagnosticCollection.clear();
- check(document.uri, goConfig)
- .then((results) => {
- results.forEach((result) => {
- handleDiagnosticErrors(document, result.errors, result.diagnosticCollection);
- });
- })
- .catch((err) => {
- vscode.window.showInformationMessage('Error: ' + err);
- });
-}
-
function addOnSaveTextDocumentListeners(ctx: vscode.ExtensionContext) {
vscode.workspace.onDidSaveTextDocument(removeCodeCoverageOnFileSave, null, ctx.subscriptions);
vscode.workspace.onDidSaveTextDocument(
@@ -404,7 +377,7 @@
}
}
if (vscode.window.visibleTextEditors.some((e) => e.document.fileName === document.fileName)) {
- runBuilds(document, getGoConfig(document.uri));
+ vscode.commands.executeCommand('go.builds.run', document, getGoConfig(document.uri));
}
},
null,