Skip to content

Commit

Permalink
Use getGoConfig() utility (#2818)
Browse files Browse the repository at this point in the history
  • Loading branch information
stamblerre authored and ramya-rao-a committed Oct 20, 2019
1 parent 3adbc57 commit cd1ad4b
Show file tree
Hide file tree
Showing 32 changed files with 95 additions and 96 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"runtimeExecutable": "${execPath}",
// the workspace path should be GOPATH
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/integration/index",
"--timeout",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"out/": true
},
"editor.insertSpaces": false,
"typescript.tsdk": "node_modules\\typescript\\lib"
"typescript.tsdk": "node_modules\\typescript\\lib",
}
4 changes: 2 additions & 2 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getNonVendorPackages } from './goPackages';
import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { diagnosticsStatusBarItem, outputChannel } from './goStatus';
import { getTestFlags } from './testUtils';
import { getCurrentGoPath, getModuleCache, getTempFilePath, getToolsEnvVars, getWorkspaceFolderPath, handleDiagnosticErrors, ICheckResult, runTool } from './util';
import { getCurrentGoPath, getGoConfig, getModuleCache, getTempFilePath, getToolsEnvVars, getWorkspaceFolderPath, handleDiagnosticErrors, ICheckResult, runTool } from './util';
/**
* Builds current package or workspace.
*/
Expand All @@ -29,7 +29,7 @@ export function buildCode(buildWorkspace?: boolean) {
}

const documentUri = editor ? editor.document.uri : null;
const goConfig = vscode.workspace.getConfiguration('go', documentUri);
const goConfig = getGoConfig(documentUri);

outputChannel.clear(); // Ensures stale output from build on save is cleared
diagnosticsStatusBarItem.show();
Expand Down
4 changes: 0 additions & 4 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export function notifyIfGeneratedFile(this: void, e: vscode.TextDocumentChangeEv
if (e.document.isUntitled || e.document.languageId !== 'go') {
return;
}

const documentUri = e ? e.document.uri : null;
const goConfig = vscode.workspace.getConfiguration('go', documentUri);

if ((ctx.globalState.get('ignoreGeneratedCodeWarning') !== true) && e.document.lineAt(0).text.match(/^\/\/ Code generated .* DO NOT EDIT\.$/)) {
vscode.window.showWarningMessage('This file seems to be generated. DO NOT EDIT.', neverAgain).then(result => {
if (result === neverAgain) {
Expand Down
9 changes: 4 additions & 5 deletions src/goCover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import fs = require('fs');
import rl = require('readline');
import { isModSupported } from './goModules';
import { getTestFlags, goTest, showTestOutput, TestConfig } from './testUtils';
import { getTempFilePath } from './util';
import { getGoConfig, getTempFilePath } from './util';

let gutterSvgs: { [key: string]: string };
let decorators: {
Expand Down Expand Up @@ -51,9 +51,8 @@ export function initCoverageDecorators(ctx: vscode.ExtensionContext) {
verticalyellow: ctx.asAbsolutePath('images/gutter-vertyellow.svg')
};

const editor = vscode.window.activeTextEditor;
// Update the coverageDecorator in User config, if they are using the old style.
const goConfig = vscode.workspace.getConfiguration('go', editor ? editor.document.uri : null);
const goConfig = getGoConfig();
const inspectResult = goConfig.inspect('coverageDecorator');
if (typeof inspectResult.globalValue === 'string') {
goConfig.update('coverageDecorator', { type: inspectResult.globalValue }, vscode.ConfigurationTarget.Global);
Expand Down Expand Up @@ -239,7 +238,7 @@ export function applyCodeCoverage(editor: vscode.TextEditor) {
return;
}

const cfg = vscode.workspace.getConfiguration('go', editor.document.uri);
const cfg = getGoConfig(editor.document.uri);
const coverageOptions = cfg['coverageOptions'];
for (const filename in coverageFiles) {
if (editor.document.uri.fsPath.endsWith(filename)) {
Expand Down Expand Up @@ -293,7 +292,7 @@ export function toggleCoverageCurrentPackage() {
return;
}

const goConfig = vscode.workspace.getConfiguration('go', editor.document.uri);
const goConfig = getGoConfig();
const cwd = path.dirname(editor.document.uri.fsPath);

const testFlags = getTestFlags(goConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import vscode = require('vscode');
import path = require('path');
import { promptForMissingTool } from './goInstallTools';
import { getFromGlobalState, updateGlobalState } from './stateUtils';
import { getBinPath, getCurrentGoPath, getToolsEnvVars, sendTelemetryEvent } from './util';
import { getBinPath, getCurrentGoPath, getGoConfig, getToolsEnvVars, sendTelemetryEvent } from './util';

export class GoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {

Expand Down Expand Up @@ -69,7 +69,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
debugConfiguration['env']['GOPATH'] = gopath;
}

const goConfig = vscode.workspace.getConfiguration('go', folder ? folder.uri : null);
const goConfig = getGoConfig(folder && folder.uri);
const goToolsEnvVars = getToolsEnvVars();
Object.keys(goToolsEnvVars).forEach(key => {
if (!debugConfiguration['env'].hasOwnProperty(key)) {
Expand Down
6 changes: 3 additions & 3 deletions src/goDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import cp = require('child_process');
import path = require('path');
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
import { getModFolderPath, promptToUpdateToolForModules } from './goModules';
import { byteOffsetAt, getBinPath, getFileArchive, getModuleCache, getToolsEnvVars, getWorkspaceFolderPath, goKeywords, isPositionInString, killProcess, runGodoc } from './util';
import { byteOffsetAt, getBinPath, getFileArchive, getGoConfig, getModuleCache, getToolsEnvVars, getWorkspaceFolderPath, goKeywords, isPositionInString, killProcess, runGodoc } from './util';

const missingToolMsg = 'Missing tool: ';

Expand Down Expand Up @@ -55,7 +55,7 @@ export function definitionLocation(document: vscode.TextDocument, position: vsco
position = adjustedPos[2];

if (!goConfig) {
goConfig = vscode.workspace.getConfiguration('go', document.uri);
goConfig = getGoConfig(document.uri);
}
const toolForDocs = goConfig['docsTool'] || 'godoc';
return getModFolderPath(document.uri).then(modFolderPath => {
Expand Down Expand Up @@ -189,7 +189,7 @@ function definitionLocation_gogetdoc(input: GoDefinitionInput, token: vscode.Can
return new Promise<GoDefinitionInformation>((resolve, reject) => {

const gogetdocFlagsWithoutTags = ['-u', '-json', '-modified', '-pos', input.document.fileName + ':#' + offset.toString()];
const buildTags = vscode.workspace.getConfiguration('go', input.document.uri)['buildTags'];
const buildTags = getGoConfig(input.document.uri)['buildTags'];
const gogetdocFlags = (buildTags && useTags) ? [...gogetdocFlagsWithoutTags, '-tags', buildTags] : gogetdocFlagsWithoutTags;
p = cp.execFile(gogetdoc, gogetdocFlags, { env, cwd: input.cwd }, (err, stdout, stderr) => {
try {
Expand Down
3 changes: 2 additions & 1 deletion src/goExtraInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import vscode = require('vscode');
import { CancellationToken, Hover, HoverProvider, Position, TextDocument, WorkspaceConfiguration } from 'vscode';
import { definitionLocation } from './goDeclaration';
import { getGoConfig } from './util';

export class GoHoverProvider implements HoverProvider {
private goConfig: WorkspaceConfiguration = null;
Expand All @@ -18,7 +19,7 @@ export class GoHoverProvider implements HoverProvider {

public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable<Hover> {
if (!this.goConfig) {
this.goConfig = vscode.workspace.getConfiguration('go', document.uri);
this.goConfig = getGoConfig(document.uri);
}
let goConfig = this.goConfig;

Expand Down
4 changes: 2 additions & 2 deletions src/goFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
import { getBinPath, getToolsEnvVars, killTree, sendTelemetryEvent } from './util';
import { getBinPath, getGoConfig, getToolsEnvVars, killTree, sendTelemetryEvent } from './util';

export class GoDocumentFormattingEditProvider implements vscode.DocumentFormattingEditProvider {

Expand All @@ -19,7 +19,7 @@ export class GoDocumentFormattingEditProvider implements vscode.DocumentFormatti
}

const filename = document.fileName;
const goConfig = vscode.workspace.getConfiguration('go', document.uri);
const goConfig = getGoConfig(document.uri);
const formatTool = goConfig['formatTool'] || 'goreturns';
const formatFlags = goConfig['formatFlags'].slice() || [];

Expand Down
8 changes: 4 additions & 4 deletions src/goGenerateTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import vscode = require('vscode');
import { promptForMissingTool } from './goInstallTools';
import { GoDocumentSymbolProvider } from './goOutline';
import { outputChannel } from './goStatus';
import { getBinPath, getToolsEnvVars } from './util';
import { getBinPath, getGoConfig, getToolsEnvVars } from './util';

const generatedWord = 'Generated ';

Expand Down Expand Up @@ -71,7 +71,7 @@ export function generateTestCurrentPackage(): Promise<boolean> {
return;
}
return generateTests({ dir: path.dirname(editor.document.uri.fsPath) },
vscode.workspace.getConfiguration('go', editor.document.uri));
getGoConfig(editor.document.uri));
}

export function generateTestCurrentFile(): Promise<boolean> {
Expand All @@ -80,7 +80,7 @@ export function generateTestCurrentFile(): Promise<boolean> {
return;
}
return generateTests({ dir: editor.document.uri.fsPath },
vscode.workspace.getConfiguration('go', editor.document.uri));
getGoConfig(editor.document.uri));
}

export async function generateTestCurrentFunction(): Promise<boolean> {
Expand All @@ -101,7 +101,7 @@ export async function generateTestCurrentFunction(): Promise<boolean> {
if (funcName.includes('.')) {
funcName = funcName.split('.')[1];
}
return generateTests({ dir: editor.document.uri.fsPath, func: funcName }, vscode.workspace.getConfiguration('go', editor.document.uri));
return generateTests({ dir: editor.document.uri.fsPath, func: funcName }, getGoConfig(editor.document.uri));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/goImplementations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import cp = require('child_process');
import path = require('path');
import { promptForMissingTool } from './goInstallTools';
import { envPath } from './goPath';
import { byteOffsetAt, canonicalizeGOPATHPrefix, getBinPath, getToolsEnvVars, getWorkspaceFolderPath, killTree } from './util';
import { byteOffsetAt, canonicalizeGOPATHPrefix, getBinPath, getGoConfig, getToolsEnvVars, getWorkspaceFolderPath, killTree } from './util';

interface GoListOutput {
Dir: string;
Expand Down Expand Up @@ -62,7 +62,7 @@ export class GoImplementationProvider implements vscode.ImplementationProvider {
const cwd = path.dirname(filename);
const offset = byteOffsetAt(document, position);
const goGuru = getBinPath('guru');
const buildTags = vscode.workspace.getConfiguration('go', document.uri)['buildTags'];
const buildTags = getGoConfig(document.uri)['buildTags'];
const args = buildTags ? ['-tags', buildTags] : [];
if (listOutput.Root && listOutput.ImportPath) {
args.push('-scope', `${listOutput.ImportPath}/...`);
Expand Down
4 changes: 2 additions & 2 deletions src/goInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import vscode = require('vscode');
import { isModSupported } from './goModules';
import { envPath, getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { outputChannel } from './goStatus';
import { getBinPath, getCurrentGoPath, getModuleCache, getToolsEnvVars } from './util';
import { getBinPath, getCurrentGoPath, getGoConfig, getModuleCache, getToolsEnvVars } from './util';
import cp = require('child_process');

export async function installCurrentPackage(): Promise<void> {
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function installCurrentPackage(): Promise<void> {
return;
}

const goConfig = vscode.workspace.getConfiguration('go', editor.document.uri);
const goConfig = getGoConfig();
const buildFlags = goConfig['buildFlags'] || [];
const args = ['install', ...buildFlags];

Expand Down
8 changes: 4 additions & 4 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getLanguageServerToolPath } from './goLanguageServer';
import { envPath, getToolFromToolPath } from './goPath';
import { hideGoStatus, outputChannel, showGoStatus } from './goStatus';
import { containsString, containsTool, getConfiguredTools, getImportPath, getTool, hasModSuffix, isGocode, isWildcard, Tool } from './goTools';
import { getBinPath, getCurrentGoPath, getGoVersion, getTempFilePath, getToolsGopath, GoVersion, resolvePath } from './util';
import { getBinPath, getCurrentGoPath, getGoConfig, getGoVersion, getTempFilePath, getToolsGopath, GoVersion, resolvePath } from './util';

// declinedUpdates tracks the tools that the user has declined to update.
const declinedUpdates: Tool[] = [];
Expand Down Expand Up @@ -68,7 +68,7 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
}

// http.proxy setting takes precedence over environment variables
const httpProxy = vscode.workspace.getConfiguration('http').get('proxy');
const httpProxy = vscode.workspace.getConfiguration('http', null).get('proxy');
let envForTools = Object.assign({}, process.env);
if (httpProxy) {
envForTools = Object.assign({}, process.env, {
Expand Down Expand Up @@ -301,7 +301,7 @@ export async function promptForUpdatingTool(toolName: string) {
}

export function updateGoPathGoRootFromConfig(): Promise<void> {
const goroot = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null)['goroot'];
const goroot = getGoConfig()['goroot'];
if (goroot) {
process.env['GOROOT'] = resolvePath(goroot);
}
Expand Down Expand Up @@ -384,7 +384,7 @@ export async function offerToInstallTools() {
vscode.window.showInformationMessage('Reload VS Code window to enable the use of Go language server');
});
} else if (selected === disableLabel) {
const goConfig = vscode.workspace.getConfiguration('go');
const goConfig = getGoConfig();
const inspectLanguageServerSetting = goConfig.inspect('useLanguageServer');
if (inspectLanguageServerSetting.globalValue === true) {
goConfig.update('useLanguageServer', false, vscode.ConfigurationTarget.Global);
Expand Down
6 changes: 3 additions & 3 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { GoCompletionItemProvider } from './goSuggest';
import { GoWorkspaceSymbolProvider } from './goSymbol';
import { getTool, Tool } from './goTools';
import { GoTypeDefinitionProvider } from './goTypeDefinition';
import { getBinPath, getCurrentGoPath, getToolsEnvVars } from './util';
import { getBinPath, getCurrentGoPath, getGoConfig, getToolsEnvVars } from './util';

interface LanguageServerConfig {
enabled: boolean;
Expand Down Expand Up @@ -288,7 +288,7 @@ function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) {
}

export function parseLanguageServerConfig(): LanguageServerConfig {
const goConfig = vscode.workspace.getConfiguration('go');
const goConfig = getGoConfig();

const config = {
enabled: goConfig['useLanguageServer'],
Expand Down Expand Up @@ -323,7 +323,7 @@ export function parseLanguageServerConfig(): LanguageServerConfig {
*/
export function getLanguageServerToolPath(): string {
// If language server is not enabled, return
const goConfig = vscode.workspace.getConfiguration('go');
const goConfig = getGoConfig();
if (!goConfig['useLanguageServer']) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/goLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path = require('path');
import vscode = require('vscode');
import { lintDiagnosticCollection } from './goMain';
import { diagnosticsStatusBarItem, outputChannel } from './goStatus';
import { getToolsEnvVars, getToolsGopath, getWorkspaceFolderPath, handleDiagnosticErrors, ICheckResult, resolvePath, runTool } from './util';
import { getGoConfig, getToolsEnvVars, getToolsGopath, getWorkspaceFolderPath, handleDiagnosticErrors, ICheckResult, resolvePath, runTool } from './util';
/**
* Runs linter on the current file, package or workspace.
*/
Expand All @@ -23,7 +23,7 @@ export function lintCode(scope?: string) {
}

const documentUri = editor ? editor.document.uri : null;
const goConfig = vscode.workspace.getConfiguration('go', documentUri);
const goConfig = getGoConfig(documentUri);

outputChannel.clear(); // Ensures stale output from lint on save is cleared
diagnosticsStatusBarItem.show();
Expand Down
4 changes: 2 additions & 2 deletions src/goLiveErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function goLiveErrorsEnabled() {
if (goConfig === null || goConfig === undefined || !goConfig.enabled) {
return false;
}
const files = vscode.workspace.getConfiguration('files');
const files = vscode.workspace.getConfiguration('files', null);
const autoSave = files['autoSave'];
const autoSaveDelay = files['autoSaveDelay'];
if (autoSave !== null && autoSave !== undefined &&
Expand Down Expand Up @@ -55,7 +55,7 @@ export function parseLiveFile(e: vscode.TextDocumentChangeEvent) {
runner = setTimeout(() => {
processFile(e);
runner = null;
}, vscode.workspace.getConfiguration('go', e.document.uri)['liveErrors']['delay']);
}, getGoConfig(e.document.uri)['liveErrors']['delay']);
}

// processFile does the actual work once the timeout has fired
Expand Down
Loading

0 comments on commit cd1ad4b

Please sign in to comment.