-
Notifications
You must be signed in to change notification settings - Fork 512
Add RunCode command for CodeLens providers #1928
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
Merged
TylerLeonhardt
merged 3 commits into
PowerShell:master
from
TylerLeonhardt:add-run-code-feature
May 3, 2019
+127
−0
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,86 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import * as path from "path"; | ||
import vscode = require("vscode"); | ||
import { IFeature, LanguageClient } from "../feature"; | ||
import { SessionManager } from "../session"; | ||
import Settings = require("../settings"); | ||
import utils = require("../utils"); | ||
|
||
enum LaunchType { | ||
Debug, | ||
Run, | ||
} | ||
|
||
export class RunCodeFeature implements IFeature { | ||
|
||
private command: vscode.Disposable; | ||
private languageClient: LanguageClient; | ||
|
||
constructor(private sessionManager: SessionManager) { | ||
this.command = vscode.commands.registerCommand( | ||
"PowerShell.RunCode", | ||
(runInDebugger: boolean, scriptToRun: string, args: string[]) => { | ||
this.launchTask(runInDebugger, scriptToRun, args); | ||
}); | ||
} | ||
|
||
public dispose() { | ||
this.command.dispose(); | ||
} | ||
|
||
public setLanguageClient(languageClient: LanguageClient) { | ||
this.languageClient = languageClient; | ||
} | ||
|
||
private async launchTask( | ||
runInDebugger: boolean, | ||
scriptToRun: string, | ||
args: string[]) { | ||
|
||
const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run; | ||
const launchConfig = this.createLaunchConfig(launchType, scriptToRun, args); | ||
this.launch(launchConfig); | ||
} | ||
|
||
private createLaunchConfig(launchType: LaunchType, scriptToRun: string, args: string[]) { | ||
const currentDocument = vscode.window.activeTextEditor.document; | ||
const settings = Settings.load(); | ||
|
||
// Since we pass the script path to PSES in single quotes to avoid issues with PowerShell | ||
// special chars like & $ @ () [], we do have to double up the interior single quotes. | ||
|
||
const launchConfig = { | ||
request: "launch", | ||
type: "PowerShell", | ||
name: "PowerShell Launch Pester Tests", | ||
script: scriptToRun, | ||
args, | ||
internalConsoleOptions: "neverOpen", | ||
noDebug: (launchType === LaunchType.Run), | ||
createTemporaryIntegratedConsole: settings.debugging.createTemporaryIntegratedConsole, | ||
cwd: | ||
currentDocument.isUntitled | ||
? vscode.workspace.rootPath | ||
: path.dirname(currentDocument.fileName), | ||
}; | ||
|
||
return launchConfig; | ||
} | ||
|
||
private launch(launchConfig) { | ||
// Create or show the interactive console | ||
// TODO #367: Check if "newSession" mode is configured | ||
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true); | ||
|
||
// Write out temporary debug session file | ||
utils.writeSessionFile( | ||
utils.getDebugSessionFilePath(), | ||
this.sessionManager.getSessionDetails()); | ||
|
||
// TODO: Update to handle multiple root workspaces. | ||
vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], launchConfig); | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.