-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #1298 remove vscode.startDebug command (#1300)
* fix #1298 remove vscode.startDebug command
* fix code review comments
* added period as per code review comments
- Loading branch information
1 parent
9de9f70
commit e1ea437
Showing
4 changed files
with
73 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as os from 'os'; | ||
import { CancellationToken, debug, OutputChannel, workspace, Uri } from 'vscode'; | ||
import { PythonSettings } from '../../common/configSettings'; | ||
import { execPythonFile } from './../../common/utils'; | ||
import { createDeferred } from './../../common/helpers'; | ||
|
||
const pythonSettings = PythonSettings.getInstance(); | ||
export function launchDebugger(rootDirectory: string, testArgs: string[], token?: CancellationToken, outChannel?: OutputChannel) { | ||
const def = createDeferred<any>(); | ||
const launchDef = createDeferred<any>(); | ||
let outputChannelShown = false; | ||
execPythonFile(pythonSettings.pythonPath, testArgs, rootDirectory, true, (data: string) => { | ||
if (data.startsWith('READY' + os.EOL)) { | ||
// debug socket server has started. | ||
launchDef.resolve(); | ||
data = data.substring(('READY' + os.EOL).length); | ||
} | ||
|
||
if (!outputChannelShown) { | ||
outputChannelShown = true; | ||
outChannel.show(); | ||
} | ||
outChannel.append(data); | ||
}, token).catch(reason => { | ||
if (!def.rejected && !def.resolved) { | ||
def.reject(reason); | ||
} | ||
}).then(() => { | ||
if (!def.rejected && !def.resolved) { | ||
def.resolve(); | ||
} | ||
}).catch(reason => { | ||
if (!def.rejected && !def.resolved) { | ||
def.reject(reason); | ||
} | ||
}); | ||
|
||
launchDef.promise.then(() => { | ||
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) { | ||
throw new Error('Please open a workspace'); | ||
} | ||
let workspaceFolder = workspace.getWorkspaceFolder(Uri.file(rootDirectory)); | ||
if (!workspaceFolder) { | ||
workspaceFolder = workspace.workspaceFolders[0]; | ||
} | ||
return debug.startDebugging(workspaceFolder, { | ||
"name": "Debug Unit Test", | ||
"type": "python", | ||
"request": "attach", | ||
"localRoot": rootDirectory, | ||
"remoteRoot": rootDirectory, | ||
"port": pythonSettings.unitTest.debugPort, | ||
"secret": "my_secret", | ||
"host": "localhost" | ||
}); | ||
}).catch(reason => { | ||
if (!def.rejected && !def.resolved) { | ||
def.reject(reason); | ||
} | ||
}); | ||
|
||
return def.promise; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters