Skip to content

What new F8 could look like - Client side handling #2060

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 12 additions & 6 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as path from "path";
import vscode = require("vscode");
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/checkboxQuickPick";
Expand Down Expand Up @@ -224,6 +225,9 @@ export class ConsoleFeature implements IFeature {
return;
}

// For the Integrated Console, we'll try to replace $PSScriptRoot. In the future, this should
// be the default behavior.

const editor = vscode.window.activeTextEditor;
let selectionRange: vscode.Range;

Expand All @@ -236,13 +240,15 @@ export class ConsoleFeature implements IFeature {
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
}

this.languageClient.sendRequest(EvaluateRequestType, {
expression: editor.document.getText(selectionRange),
});
const rawText = vscode.window.activeTextEditor.document.getText(selectionRange);

// Replace $PSScriptRoot with the file path.
// TODO: Handle inside quotes.
const psScriptRootValue = path.resolve(vscode.window.activeTextEditor.document.uri.fsPath, "..");
const formattedText = rawText.replace(/\$PSScriptRoot/i, psScriptRootValue);

// Show the integrated console if it isn't already visible and
// scroll terminal to bottom so new output is visible
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
// Send the formatted text and scroll the terminal to the bottom.
await vscode.window.activeTerminal.sendText(formattedText, true);
await vscode.commands.executeCommand("workbench.action.terminal.scrollToBottom");
}),
];
Expand Down