Skip to content

Commit fb59b37

Browse files
Handle clearTerminal message by using vscode clear command (#2316)
* handle clearTerminal message by using vscode clear command * Codacy * changed name of setting * delete comment
1 parent dba7d83 commit fb59b37

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@
688688
"default": false,
689689
"description": "Falls back to the legacy (lightweight) ReadLine experience. This will disable the use of PSReadLine in the PowerShell Integrated Console."
690690
},
691+
"powershell.integratedConsole.forceClearScrollbackBuffer": {
692+
"type": "boolean",
693+
"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."
694+
},
691695
"powershell.debugging.createTemporaryIntegratedConsole": {
692696
"type": "boolean",
693697
"default": false,

src/features/ExtensionCommands.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import * as fs from "fs";
66
import * as os from "os";
77
import * as path from "path";
88
import * as vscode from "vscode";
9-
import { LanguageClient, NotificationType, Position, Range, RequestType } from "vscode-languageclient";
9+
import { LanguageClient, NotificationType, NotificationType0,
10+
Position, Range, RequestType } from "vscode-languageclient";
1011
import { IFeature } from "../feature";
1112
import { Logger } from "../logging";
13+
import Settings = require("../settings");
1214

1315
export interface IExtensionCommand {
1416
name: string;
@@ -155,6 +157,9 @@ export const SetStatusBarMessageRequestType =
155157
new RequestType<IStatusBarMessageDetails, EditorOperationResponse, void, void>(
156158
"editor/setStatusBarMessage");
157159

160+
export const ClearTerminalNotificationType =
161+
new NotificationType0("editor/clearTerminal");
162+
158163
export interface ISaveFileDetails {
159164
filePath: string;
160165
newPath?: string;
@@ -265,6 +270,16 @@ export class ExtensionCommandsFeature implements IFeature {
265270
this.languageClient.onRequest(
266271
SetStatusBarMessageRequestType,
267272
(messageDetails) => this.setStatusBarMessage(messageDetails));
273+
274+
this.languageClient.onNotification(
275+
ClearTerminalNotificationType,
276+
() => {
277+
// We check to see if they have TrueClear on. If not, no-op because the
278+
// overriden Clear-Host already calls [System.Console]::Clear()
279+
if (Settings.load().integratedConsole.forceClearScrollbackBuffer) {
280+
vscode.commands.executeCommand("workbench.action.terminal.clear");
281+
}
282+
});
268283
}
269284
}
270285

src/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface IIntegratedConsoleSettings {
9999
showOnStartup?: boolean;
100100
focusConsoleOnExecute?: boolean;
101101
useLegacyReadLine?: boolean;
102+
forceClearScrollbackBuffer?: boolean;
102103
}
103104

104105
export function load(): ISettings {
@@ -154,6 +155,7 @@ export function load(): ISettings {
154155
showOnStartup: true,
155156
focusConsoleOnExecute: true,
156157
useLegacyReadLine: false,
158+
forceClearScrollbackBuffer: false,
157159
};
158160

159161
return {

0 commit comments

Comments
 (0)