diff --git a/package.json b/package.json index a1786a22c5..847e3a6133 100644 --- a/package.json +++ b/package.json @@ -688,6 +688,10 @@ "default": false, "description": "Falls back to the legacy (lightweight) ReadLine experience. This will disable the use of PSReadLine in the PowerShell Integrated Console." }, + "powershell.integratedConsole.forceClearScrollbackBuffer": { + "type": "boolean", + "description": "Use the vscode API to clear the terminal since that's the only reliable way to clear the scrollback buffer. Turn this on if you're use to 'Clear-Host' clearing scroll history as wellclear-terminal-via-lsp." + }, "powershell.debugging.createTemporaryIntegratedConsole": { "type": "boolean", "default": false, diff --git a/src/features/ExtensionCommands.ts b/src/features/ExtensionCommands.ts index 23c3159b68..504d660dd1 100644 --- a/src/features/ExtensionCommands.ts +++ b/src/features/ExtensionCommands.ts @@ -6,9 +6,11 @@ import * as fs from "fs"; import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; -import { LanguageClient, NotificationType, Position, Range, RequestType } from "vscode-languageclient"; +import { LanguageClient, NotificationType, NotificationType0, + Position, Range, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; import { Logger } from "../logging"; +import Settings = require("../settings"); export interface IExtensionCommand { name: string; @@ -155,6 +157,9 @@ export const SetStatusBarMessageRequestType = new RequestType( "editor/setStatusBarMessage"); +export const ClearTerminalNotificationType = + new NotificationType0("editor/clearTerminal"); + export interface ISaveFileDetails { filePath: string; newPath?: string; @@ -265,6 +270,16 @@ export class ExtensionCommandsFeature implements IFeature { this.languageClient.onRequest( SetStatusBarMessageRequestType, (messageDetails) => this.setStatusBarMessage(messageDetails)); + + this.languageClient.onNotification( + ClearTerminalNotificationType, + () => { + // We check to see if they have TrueClear on. If not, no-op because the + // overriden Clear-Host already calls [System.Console]::Clear() + if (Settings.load().integratedConsole.forceClearScrollbackBuffer) { + vscode.commands.executeCommand("workbench.action.terminal.clear"); + } + }); } } diff --git a/src/settings.ts b/src/settings.ts index d29e4ee33c..397a0a9328 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -99,6 +99,7 @@ export interface IIntegratedConsoleSettings { showOnStartup?: boolean; focusConsoleOnExecute?: boolean; useLegacyReadLine?: boolean; + forceClearScrollbackBuffer?: boolean; } export function load(): ISettings { @@ -154,6 +155,7 @@ export function load(): ISettings { showOnStartup: true, focusConsoleOnExecute: true, useLegacyReadLine: false, + forceClearScrollbackBuffer: false, }; return {