Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Add workspace resolution for -vettool in go.vetFlags (#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamayika authored and ramya-rao-a committed May 24, 2019
1 parent d1bf95c commit 9cf61c4
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/goVet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path');
import vscode = require('vscode');
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getGoVersion, SemVersion } from './util';
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getGoVersion, SemVersion, resolvePath } from './util';
import { outputChannel } from './goStatus';
import { diagnosticsStatusBarItem } from './goStatus';
import { vetDiagnosticCollection } from './goMain';
Expand Down Expand Up @@ -61,18 +61,33 @@ export function goVet(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurati
return Promise.resolve([]);
}

const vetFlags = goConfig['vetFlags'] || [];
const vetFlags: string[] = goConfig['vetFlags'] || [];
const vetEnv = Object.assign({}, getToolsEnvVars());
const args: string[] = [];

vetFlags.forEach(flag => {
if (flag.startsWith('--vettool=') || flag.startsWith('-vettool=')) {
let vetToolPath = flag.substr(flag.indexOf('=') + 1).trim();
if (!vetToolPath) {
return;
}
vetToolPath = resolvePath(vetToolPath);
args.push(`${flag.substr(0, flag.indexOf('=') + 1)}${vetToolPath}`);
return;
}
args.push(flag);
});

const vetPromise = getGoVersion().then((version: SemVersion) => {
const tagsArg = [];
if (goConfig['buildTags'] && vetFlags.indexOf('-tags') === -1) {
tagsArg.push('-tags');
tagsArg.push(goConfig['buildTags']);
}

let vetArgs = ['vet', ...vetFlags, ...tagsArg, './...'];
if (version && version.major === 1 && version.minor <= 9 && vetFlags.length) {
vetArgs = ['tool', 'vet', ...vetFlags, ...tagsArg, '.'];
let vetArgs = ['vet', ...args, ...tagsArg, './...'];
if (version && version.major === 1 && version.minor <= 9 && args.length) {
vetArgs = ['tool', 'vet', ...args, ...tagsArg, '.'];
}

outputChannel.appendLine(`Starting "go vet" under the folder ${cwd}`);
Expand Down

0 comments on commit 9cf61c4

Please sign in to comment.