Skip to content

Commit

Permalink
Add path mappings for remote debugging when attaching to the localhost (
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Jun 5, 2018
1 parent 72789f6 commit 33505d2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/1829.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Automatically add path mappings for remote debugging when attaching to the localhost.
15 changes: 13 additions & 2 deletions src/client/debugger/configProviders/pythonV2Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvide
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super('pythonExperimental', serviceContainer);
}
protected async provideLaunchDefaults(workspaceFolder: Uri, debugConfiguration: PythonLaunchDebugConfiguration<LaunchRequestArguments>): Promise<void> {
protected async provideLaunchDefaults(workspaceFolder: Uri | undefined, debugConfiguration: PythonLaunchDebugConfiguration<LaunchRequestArguments>): Promise<void> {
await super.provideLaunchDefaults(workspaceFolder, debugConfiguration);
const debugOptions = debugConfiguration.debugOptions!;
if (debugConfiguration.debugStdLib) {
Expand Down Expand Up @@ -48,7 +48,8 @@ export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvide
debugConfiguration.program = (await utils.getPyramidStartupScriptFilePath(workspaceFolder))!;
}
}
protected async provideAttachDefaults(workspaceFolder: Uri, debugConfiguration: PythonAttachDebugConfiguration<AttachRequestArguments>): Promise<void> {
// tslint:disable-next-line:cyclomatic-complexity
protected async provideAttachDefaults(workspaceFolder: Uri | undefined, debugConfiguration: PythonAttachDebugConfiguration<AttachRequestArguments>): Promise<void> {
await super.provideAttachDefaults(workspaceFolder, debugConfiguration);
const debugOptions = debugConfiguration.debugOptions!;
if (debugConfiguration.debugStdLib) {
Expand Down Expand Up @@ -82,12 +83,22 @@ export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvide
if (!debugConfiguration.pathMappings) {
debugConfiguration.pathMappings = [];
}
// This is for backwards compatibility.
if (debugConfiguration.localRoot && debugConfiguration.remoteRoot) {
debugConfiguration.pathMappings!.push({
localRoot: debugConfiguration.localRoot,
remoteRoot: debugConfiguration.remoteRoot
});
}
// If attaching to local host, then always map local root and remote roots.
if (workspaceFolder && debugConfiguration.host &&
debugConfiguration.pathMappings!.length === 0 &&
['LOCALHOST', '127.0.0.1', '::1'].indexOf(debugConfiguration.host.toUpperCase()) >= 0) {
debugConfiguration.pathMappings!.push({
localRoot: workspaceFolder.fsPath,
remoteRoot: workspaceFolder.fsPath
});
}
}
private debugOption(debugOptions: DebugOptions[], debugOption: DebugOptions) {
if (debugOptions.indexOf(debugOption) >= 0) {
Expand Down
43 changes: 39 additions & 4 deletions src/test/debugger/configProvider/provider.attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PYTHON_LANGUAGE } from '../../../client/common/constants';
import { EnumEx } from '../../../client/common/enumUtils';
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
import { PythonDebugConfigurationProvider, PythonV2DebugConfigurationProvider } from '../../../client/debugger';
import { DebugOptions } from '../../../client/debugger/Common/Contracts';
import { AttachRequestArguments, DebugOptions } from '../../../client/debugger/Common/Contracts';
import { IServiceContainer } from '../../../client/ioc/types';

enum OS {
Expand Down Expand Up @@ -164,9 +164,44 @@ enum OS {
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, request: 'attach' } as any as DebugConfiguration);

expect(debugConfig).to.have.property('localRoot', localRoot);
if (provider.debugType === 'pythonExperimental') {
expect(debugConfig!.pathMappings).to.be.lengthOf(0);
}
});
['localhost', '127.0.0.1', '::1'].forEach(host => {
test(`Ensure path mappings are automatically added when host is '${host}'`, async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

const localRoot = `Debug_PythonPath_${new Date().toString()}`;
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration);

expect(debugConfig).to.have.property('localRoot', localRoot);
if (provider.debugType === 'pythonExperimental') {
const pathMappings = (debugConfig as AttachRequestArguments).pathMappings;
expect(pathMappings).to.be.lengthOf(1);
expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath);
expect(pathMappings![0].remoteRoot).to.be.equal(workspaceFolder.uri.fsPath);
}
});
});
['192.168.1.123', 'don.debugger.com'].forEach(host => {
test(`Ensure path mappings are not automatically added when host is '${host}'`, async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

const localRoot = `Debug_PythonPath_${new Date().toString()}`;
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration);

expect(debugConfig).to.have.property('localRoot', localRoot);
if (provider.debugType === 'pythonExperimental') {
const pathMappings = (debugConfig as AttachRequestArguments).pathMappings;
expect(pathMappings).to.be.lengthOf(0);
}
});
});
test('Ensure \'localRoot\' and \'remoteRoot\' is used', async function () {
if (provider.debugType !== 'pythonExperimental') {
Expand Down

0 comments on commit 33505d2

Please sign in to comment.