From c4ef11ce0065461ded823da0587a75fc3bc1c4b6 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 18 Nov 2019 21:41:58 -0800 Subject: [PATCH 1/4] handle clearTerminal message by using vscode clear command --- package.json | 4 ++++ src/features/ExtensionCommands.ts | 16 +++++++++++++++- src/settings.ts | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f28fac36ec..55a32635e3 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.useTrueClear": { + "type": "boolean", + "description": "Use the vscode API to clear the terminal since that's the only way to trigger a true clear. A true clear is a clear that shows nothing when you scroll up after running Clear-Host." + }, "powershell.debugging.createTemporaryIntegratedConsole": { "type": "boolean", "default": false, diff --git a/src/features/ExtensionCommands.ts b/src/features/ExtensionCommands.ts index 23c3159b68..8dc7d3d543 100644 --- a/src/features/ExtensionCommands.ts +++ b/src/features/ExtensionCommands.ts @@ -6,9 +6,10 @@ 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 +156,9 @@ export const SetStatusBarMessageRequestType = new RequestType( "editor/setStatusBarMessage"); +export const ClearTerminalNotificationType = + new NotificationType0("editor/clearTerminal"); + export interface ISaveFileDetails { filePath: string; newPath?: string; @@ -265,6 +269,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.useTrueClear) { + vscode.commands.executeCommand("workbench.action.terminal.clear"); + } + }); } } diff --git a/src/settings.ts b/src/settings.ts index e7c9eea499..9c0f58f65e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -99,6 +99,7 @@ export interface IIntegratedConsoleSettings { showOnStartup?: boolean; focusConsoleOnExecute?: boolean; useLegacyReadLine?: boolean; + useTrueClear?: boolean; } export function load(): ISettings { @@ -155,6 +156,8 @@ export function load(): ISettings { showOnStartup: true, focusConsoleOnExecute: true, useLegacyReadLine: false, + // This behavior is expected on Windows but not on non-Windows + useTrueClear: utils.isWindowsOS(), }; return { From 0efeb462a977cefa2cc7c25bb54d9f4e41731067 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 18 Nov 2019 21:57:50 -0800 Subject: [PATCH 2/4] Codacy --- src/features/ExtensionCommands.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/features/ExtensionCommands.ts b/src/features/ExtensionCommands.ts index 8dc7d3d543..ad338c3e5c 100644 --- a/src/features/ExtensionCommands.ts +++ b/src/features/ExtensionCommands.ts @@ -6,7 +6,8 @@ import * as fs from "fs"; import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; -import { LanguageClient, NotificationType, NotificationType0, 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"); From 05056bb972be17f81fa32816fd6192b40308d8ef Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 21 Nov 2019 11:49:06 -0800 Subject: [PATCH 3/4] changed name of setting --- package.json | 4 ++-- src/features/ExtensionCommands.ts | 2 +- src/settings.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 55a32635e3..c65be051d2 100644 --- a/package.json +++ b/package.json @@ -688,9 +688,9 @@ "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.useTrueClear": { + "powershell.integratedConsole.forceClearScrollbackBuffer": { "type": "boolean", - "description": "Use the vscode API to clear the terminal since that's the only way to trigger a true clear. A true clear is a clear that shows nothing when you scroll up after running Clear-Host." + "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", diff --git a/src/features/ExtensionCommands.ts b/src/features/ExtensionCommands.ts index ad338c3e5c..504d660dd1 100644 --- a/src/features/ExtensionCommands.ts +++ b/src/features/ExtensionCommands.ts @@ -276,7 +276,7 @@ export class ExtensionCommandsFeature implements IFeature { () => { // 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.useTrueClear) { + if (Settings.load().integratedConsole.forceClearScrollbackBuffer) { vscode.commands.executeCommand("workbench.action.terminal.clear"); } }); diff --git a/src/settings.ts b/src/settings.ts index 9c0f58f65e..4b2b36b8ee 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -99,7 +99,7 @@ export interface IIntegratedConsoleSettings { showOnStartup?: boolean; focusConsoleOnExecute?: boolean; useLegacyReadLine?: boolean; - useTrueClear?: boolean; + forceClearScrollbackBuffer?: boolean; } export function load(): ISettings { @@ -157,7 +157,7 @@ export function load(): ISettings { focusConsoleOnExecute: true, useLegacyReadLine: false, // This behavior is expected on Windows but not on non-Windows - useTrueClear: utils.isWindowsOS(), + forceClearScrollbackBuffer: false, }; return { From 62fff5bc6b38268c71178692098ec3ffea305888 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 21 Nov 2019 11:55:54 -0800 Subject: [PATCH 4/4] delete comment --- src/settings.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/settings.ts b/src/settings.ts index 4b2b36b8ee..295ecbdaa1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -156,7 +156,6 @@ export function load(): ISettings { showOnStartup: true, focusConsoleOnExecute: true, useLegacyReadLine: false, - // This behavior is expected on Windows but not on non-Windows forceClearScrollbackBuffer: false, };