Repository navigation
🐛 resolve pythonPath in debug config #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ecc1ca9
7c5778c
9d1bf82
ffba179
905c713
acc2109
d470523
d392e8b
92f775f
32a6e53
4b30f2c
e396752
eff4792
4553c28
3c6520a
966e516
63d2d65
f6d469e
029e055
e8c71c0
51cf9d2
7aadc43
f0f5c59
b2b9da9
30a4091
b16d2f9
c8db345
0df7f16
3ccc881
bb0709e
2c19004
8f224ab
41b7080
dab38dc
ae22dd4
d2340d2
52bb7ae
b6b2531
8d8d2fc
c425a55
3963217
a696f2a
a31e659
2663cd5
7c85e0b
beb82c2
01e722a
d84da8e
78da3e1
685b683
43364fd
8701636
5c8addf
588c2f9
66b1382
e6b4b48
6aa9a2d
57f3982
15aab64
0e7888f
8bc4982
c05d035
08476d1
aeade06
6850da2
04add73
4240c34
713033e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { injectable, unmanaged } from 'inversify'; | ||
| import * as path from 'path'; | ||
| import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, ProviderResult, Uri, WorkspaceFolder } from 'vscode'; | ||
| import { IDocumentManager, IWorkspaceService } from '../../common/application/types'; | ||
| import { PythonLanguage } from '../../common/constants'; | ||
| import { IConfigurationService } from '../../common/types'; | ||
| import { IServiceContainer } from '../../ioc/types'; | ||
| import { DebuggerType, LaunchRequestArguments } from '../Common/Contracts'; | ||
|
|
||
| // tslint:disable:no-invalid-template-strings | ||
|
|
||
| export type PythonDebugConfiguration = DebugConfiguration & LaunchRequestArguments; | ||
|
|
||
| @injectable() | ||
| export abstract class BaseConfigurationProvider implements DebugConfigurationProvider { | ||
| constructor(@unmanaged() public debugType: DebuggerType, private serviceContainer: IServiceContainer) { } | ||
| public resolveDebugConfiguration(folder: WorkspaceFolder | undefined, debugConfiguration: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> { | ||
| const config = debugConfiguration as PythonDebugConfiguration; | ||
| const numberOfSettings = Object.keys(config); | ||
| const provideDefaultConfigSettings = (config.noDebug === true && numberOfSettings.length === 1) || numberOfSettings.length === 0; | ||
| const workspaceFolder = this.getWorkspaceFolder(folder, config); | ||
| if (!provideDefaultConfigSettings) { | ||
| this.resolveAndUpdatePythonPath(workspaceFolder, config); | ||
| return config; | ||
| } | ||
|
|
||
| const configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService); | ||
| const pythonPath = configService.getSettings(workspaceFolder).pythonPath; | ||
| const defaultProgram = this.getProgram(config); | ||
| const envFile = workspaceFolder ? path.join(workspaceFolder.fsPath, '.env') : ''; | ||
|
|
||
| config.name = 'Launch'; | ||
| config.type = this.debugType; | ||
| config.request = 'launch'; | ||
| config.pythonPath = pythonPath; | ||
| config.program = defaultProgram ? defaultProgram : ''; | ||
| config.cwd = workspaceFolder ? workspaceFolder.fsPath : undefined; | ||
| config.envFile = envFile; | ||
| config.env = {}; | ||
| config.debugOptions = []; | ||
|
|
||
| this.provideDefaults(config); | ||
| return config; | ||
| } | ||
| protected abstract provideDefaults(debugConfiguration: PythonDebugConfiguration): void; | ||
| private getWorkspaceFolder(folder: WorkspaceFolder | undefined, config: PythonDebugConfiguration): Uri | undefined { | ||
| if (folder) { | ||
| return folder.uri; | ||
| } | ||
| const program = this.getProgram(config); | ||
| const workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService); | ||
| if (!Array.isArray(workspaceService.workspaceFolders) || workspaceService.workspaceFolders.length === 0) { | ||
| return program ? Uri.file(path.dirname(program)) : undefined; | ||
| } | ||
| if (workspaceService.workspaceFolders.length === 1) { | ||
| return workspaceService.workspaceFolders[0].uri; | ||
| } | ||
| if (program) { | ||
| const workspaceFolder = workspaceService.getWorkspaceFolder(Uri.file(program)); | ||
| if (workspaceFolder) { | ||
| return workspaceFolder.uri; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So with multiple
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No this would happen if the file being debugged doesn't belong to any of the current workspaces. |
||
| } | ||
| private getProgram(config: PythonDebugConfiguration): string | undefined { | ||
| const documentManager = this.serviceContainer.get<IDocumentManager>(IDocumentManager); | ||
| const editor = documentManager.activeTextEditor; | ||
| if (editor && editor.document.languageId === PythonLanguage.language) { | ||
| return editor.document.fileName; | ||
| } | ||
| } | ||
| private resolveAndUpdatePythonPath(workspaceFolder: Uri | undefined, debugConfiguration: PythonDebugConfiguration): void { | ||
| if (!debugConfiguration || debugConfiguration.pythonPath !== '${config:python.pythonPath}') { | ||
| return; | ||
| } | ||
| const configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService); | ||
| const pythonPath = configService.getSettings(workspaceFolder).pythonPath; | ||
| debugConfiguration.pythonPath = pythonPath; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { inject, injectable } from 'inversify'; | ||
| import { IServiceContainer } from '../../ioc/types'; | ||
| import { BaseConfigurationProvider, PythonDebugConfiguration } from './baseProvider'; | ||
|
|
||
| @injectable() | ||
| export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvider { | ||
| constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) { | ||
| super('pythonExperimental', serviceContainer); | ||
| } | ||
| protected provideDefaults(debugConfiguration: PythonDebugConfiguration): void { | ||
| debugConfiguration.stopOnEntry = false; | ||
| debugConfiguration.console = 'integratedTerminal'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { inject, injectable } from 'inversify'; | ||
| import { IServiceContainer } from '../../ioc/types'; | ||
| import { BaseConfigurationProvider, PythonDebugConfiguration } from './baseProvider'; | ||
|
|
||
| @injectable() | ||
| export class PythonDebugConfigurationProvider extends BaseConfigurationProvider { | ||
| constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) { | ||
| super('python', serviceContainer); | ||
| } | ||
| protected provideDefaults(debugConfiguration: PythonDebugConfiguration): void { | ||
| debugConfiguration.stopOnEntry = true; | ||
| debugConfiguration.debugOptions = [ | ||
| 'RedirectOutput' | ||
| ]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { DebugConfigurationProvider } from 'vscode'; | ||
| import { PythonDebugConfigurationProvider, PythonV2DebugConfigurationProvider } from '..'; | ||
| import { IServiceManager } from '../../ioc/types'; | ||
| import { IDebugConfigurationProvider } from '../types'; | ||
|
|
||
| export function registerTypes(serviceManager: IServiceManager) { | ||
| serviceManager.addSingleton<DebugConfigurationProvider>(IDebugConfigurationProvider, PythonDebugConfigurationProvider); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't, this is a native VSCode interface |
||
| serviceManager.addSingleton<DebugConfigurationProvider>(IDebugConfigurationProvider, PythonV2DebugConfigurationProvider); | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './configProviders/simpleProvider'; | ||
| export * from './configProviders/pythonProvider'; | ||
| export * from './configProviders/pyhtonV2Provider'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK for
workspaceFolderto be undefined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.