forked from golang/vscode-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b03d33b
commit 7adc180
Showing
6 changed files
with
92 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import path = require('path'); | ||
import vscode = require('vscode'); | ||
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath } from './util'; | ||
import { outputChannel } from './goStatus'; | ||
|
||
/** | ||
* Runs go vet in the current package or workspace. | ||
*/ | ||
export function vetCode(vetWorkspace?: boolean) { | ||
let editor = vscode.window.activeTextEditor; | ||
if (!editor && !vetWorkspace) { | ||
vscode.window.showInformationMessage('No editor is active, cant find current package to vet'); | ||
return; | ||
} | ||
|
||
let documentUri = editor ? editor.document.uri : null; | ||
let goConfig = vscode.workspace.getConfiguration('go', documentUri); | ||
outputChannel.clear(); | ||
goVet(documentUri, goConfig, vetWorkspace) | ||
.then(warnings => handleDiagnosticErrors(editor ? editor.document : null, warnings, vscode.DiagnosticSeverity.Warning)) | ||
.catch(err => { | ||
vscode.window.showInformationMessage('Error: ' + err); | ||
}); | ||
} | ||
|
||
/** | ||
* Runs go vet or go tool vet and presents the output in the 'Go' channel and in the diagnostic collections. | ||
* | ||
* @param fileUri Document uri. | ||
* @param goConfig Configuration for the Go extension. | ||
* @param vetWorkspace If true vets code in all workspace. | ||
*/ | ||
export function goVet(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, vetWorkspace?: boolean): Promise<ICheckResult[]> { | ||
let vetFlags = goConfig['vetFlags'] || []; | ||
let vetEnv = Object.assign({}, getToolsEnvVars()); | ||
let vetArgs = vetFlags.length ? ['tool', 'vet', ...vetFlags, '.'] : ['vet', './...']; | ||
let currentWorkspace = getWorkspaceFolderPath(fileUri); | ||
|
||
return runTool( | ||
vetArgs, | ||
(vetWorkspace && currentWorkspace) ? currentWorkspace : path.dirname(fileUri.fsPath), | ||
'warning', | ||
true, | ||
null, | ||
vetEnv | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters