Skip to content
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

fix #1270 debugger contribution changes #1288

Merged
merged 2 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.9.0"
"vscode": "^1.17.0"
},
"recommendations": [
"donjayamanne.jupyter"
Expand All @@ -44,8 +44,8 @@
"Other"
],
"activationEvents": [
"onDebug",
"onLanguage:python",
"onCommand:python.python-debug.startSession",
"onCommand:python.execInTerminal",
"onCommand:python.sortImports",
"onCommand:python.runtests",
Expand Down Expand Up @@ -278,7 +278,6 @@
"languages": [
"python"
],
"startSessionCommand": "python.python-debug.startSession",
"enableBreakpointsFor": {
"languageIds": [
"python",
Expand Down Expand Up @@ -1570,4 +1569,4 @@
"vscode": "^1.0.3",
"webpack": "^1.13.2"
}
}
}
66 changes: 66 additions & 0 deletions src/client/debugger/configProviders/simpleProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as path from 'path';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume other providers are going to end up here, hence the generic name?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will rename, got some more information about this on vscode issue i raised.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, ignore me; missed that the file is in the debugger/ sub-directory.

import { PythonSettings } from '../../common/configSettings';
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, ProviderResult, Uri, window, workspace, WorkspaceFolder } from 'vscode';

type PythonDebugConfiguration = DebugConfiguration & {
stopOnEntry?: boolean,
pythonPath?: string,
program?: string,
cwd?: string,
env?: object,
envFile?: string,
debugOptions?: string[]
};

export class SimpleConfigurationProvider implements DebugConfigurationProvider {
private getProgram(config: PythonDebugConfiguration): string | undefined {
const editor = window.activeTextEditor;
if (editor && editor.document.languageId === 'python') {
return editor.document.fileName;
}
return undefined;
}
private getWorkspaceFolder(config: PythonDebugConfiguration): string | undefined {
const program = this.getProgram(config);
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) {
return program ? path.dirname(program) : undefined;
}
if (workspace.workspaceFolders.length === 1) {
return workspace.workspaceFolders[0].uri.fsPath;
}
if (program) {
const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(program));
if (workspaceFolder) {
return workspaceFolder.uri.fsPath;
}
}

return undefined;
}
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, debugConfiguration: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {
if (Object.keys(debugConfiguration).length > 0) {
return debugConfiguration;
}

const config = debugConfiguration as PythonDebugConfiguration;
const defaultProgram = this.getProgram(config);
const workspaceFolder = this.getWorkspaceFolder(config);
const envFile = workspaceFolder ? path.join(workspaceFolder, '.env') : undefined;
return {
name: 'Launch',
type: 'python',
request: 'launch',
stopOnEntry: true,
pythonPath: PythonSettings.getInstance().pythonPath,
program: defaultProgram,
cwd: workspaceFolder,
envFile,
env: {},
debugOptions: [
'WaitOnAbnormalExit',
'WaitOnNormalExit',
'RedirectOutput'
]
};
}
}
1 change: 1 addition & 0 deletions src/client/debugger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './configProviders/simpleProvider';
4 changes: 2 additions & 2 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { WorkspaceSymbols } from './workspaceSymbols/main';
import { BlockFormatProviders } from './typeFormatters/blockFormatProvider';
import * as os from 'os';
import * as fs from 'fs';
import { activateSingleFileDebug } from './singleFileDebug';
import { getPathFromPythonCommand } from './common/utils';
import { JupyterProvider } from './jupyter/provider';
import { activateGoToObjectDefinitionProvider } from './providers/objectDefinitionProvider';
import { InterpreterManager } from './interpreter';
import { SimpleConfigurationProvider } from './debugger';

const PYTHON: vscode.DocumentFilter = { language: 'python' };
let unitTestOutChannel: vscode.OutputChannel;
Expand Down Expand Up @@ -152,7 +152,7 @@ export async function activate(context: vscode.ExtensionContext) {
const hepProvider = new HelpProvider();
context.subscriptions.push(hepProvider);

context.subscriptions.push(activateSingleFileDebug());
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('python', new SimpleConfigurationProvider()));
}

class PythonExt implements vscode.Disposable {
Expand Down
51 changes: 0 additions & 51 deletions src/client/singleFileDebug.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/autocomplete/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ suite('Autocomplete', () => {
const position = new vscode.Position(10, 9);
const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'sleep').length, 0, 'sleep not found');
assert.notEqual(list.items.filter(item => item.documentation.startsWith("Delay execution for a given number of seconds. The argument may be")).length, 0, 'Documentation incorrect');
assert.notEqual(list.items.filter(item => item.documentation.toString().startsWith("Delay execution for a given number of seconds. The argument may be")).length, 0, 'Documentation incorrect');
});

test('For custom class', done => {
Expand Down