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

Commit

Permalink
Use mod file to determine module mode when debugging (#2846)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Nov 4, 2019
1 parent d6a0fac commit c1669d1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {

showGlobalVariables?: boolean;
currentFile: string;
packagePathToGoModPathMap: {[key: string]: string};
}

interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
Expand Down Expand Up @@ -435,7 +436,7 @@ class Delve {
dlvArgs.push(mode || 'debug');
if (mode === 'exec') {
dlvArgs.push(program);
} else if (currentGOWorkspace && env['GO111MODULE'] !== 'on') {
} else if (currentGOWorkspace && !launchArgs.packagePathToGoModPathMap[dirname]) {
dlvArgs.push(dirname.substr(currentGOWorkspace.length + 1));
}
dlvArgs.push('--headless=true', `--listen=${launchArgs.host}:${launchArgs.port}`);
Expand Down
3 changes: 3 additions & 0 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path = require('path');
import { promptForMissingTool } from './goInstallTools';
import { getFromGlobalState, updateGlobalState } from './stateUtils';
import { getBinPath, getCurrentGoPath, getGoConfig, getToolsEnvVars, sendTelemetryEvent } from './util';
import { packagePathToGoModPathMap } from './goModules';

export class GoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {

Expand Down Expand Up @@ -62,6 +63,8 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
};
}

debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;

const gopath = getCurrentGoPath(folder ? folder.uri : null);
if (!debugConfiguration['env']) {
debugConfiguration['env'] = { 'GOPATH': gopath };
Expand Down
7 changes: 5 additions & 2 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { registerLanguageFeatures } from './goLanguageServer';
import { lintCode } from './goLint';
import { GO_MODE } from './goMode';
import { addTags, removeTags } from './goModifytags';
import { GO111MODULE } from './goModules';
import { GO111MODULE, isModSupported } from './goModules';
import { clearCacheForTools } from './goPath';
import { playgroundCommand } from './goPlayground';
import { GoReferencesCodeLensProvider } from './goReferencesCodelens';
Expand Down Expand Up @@ -90,7 +90,10 @@ export function activate(ctx: vscode.ExtensionContext): void {
await registerLanguageFeatures(ctx);

if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document.languageId === 'go' && isGoPathSet()) {
runBuilds(vscode.window.activeTextEditor.document, getGoConfig());
// Check mod status so that cache is updated and then run build/lint/vet
isModSupported(vscode.window.activeTextEditor.document.uri).then(() => {
runBuilds(vscode.window.activeTextEditor.document, getGoConfig());
});
}

});
Expand Down
8 changes: 4 additions & 4 deletions src/goModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export function isModSupported(fileuri: vscode.Uri): Promise<boolean> {
return getModFolderPath(fileuri).then(modPath => !!modPath);
}

const packagePathToGoModPathMap = new Map<string, string>();
export const packagePathToGoModPathMap: {[key: string]: string} = {};

export async function getModFolderPath(fileuri: vscode.Uri): Promise<string> {
const pkgPath = path.dirname(fileuri.fsPath);
if (packagePathToGoModPathMap.has(pkgPath)) {
return packagePathToGoModPathMap.get(pkgPath);
if (packagePathToGoModPathMap[pkgPath]) {
return packagePathToGoModPathMap[pkgPath];
}

// We never would be using the path under module cache for anything
Expand Down Expand Up @@ -82,7 +82,7 @@ export async function getModFolderPath(fileuri: vscode.Uri): Promise<string> {
await promptToUpdateToolForModules('switchFormatToolToGoimports', promptMsgForFormatTool, goConfig);
}
}
packagePathToGoModPathMap.set(pkgPath, goModEnvResult);
packagePathToGoModPathMap[pkgPath] = goModEnvResult;
return goModEnvResult;
}

Expand Down

0 comments on commit c1669d1

Please sign in to comment.