From c4ef11ce0065461ded823da0587a75fc3bc1c4b6 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 18 Nov 2019 21:41:58 -0800 Subject: [PATCH 1/3] 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/3] 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 31536afc085a6c06b1a59cf1b2e1df15020ec3c9 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 19 Nov 2019 10:25:07 -0800 Subject: [PATCH 3/3] remove setting because we'll use param --- package.json | 4 ---- src/features/ExtensionCommands.ts | 8 +------- src/settings.ts | 3 --- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/package.json b/package.json index 55a32635e3..f28fac36ec 100644 --- a/package.json +++ b/package.json @@ -688,10 +688,6 @@ "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 ad338c3e5c..82b58cb60b 100644 --- a/src/features/ExtensionCommands.ts +++ b/src/features/ExtensionCommands.ts @@ -273,13 +273,7 @@ export class ExtensionCommandsFeature implements IFeature { 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"); - } - }); + () => vscode.commands.executeCommand("workbench.action.terminal.clear")); } } diff --git a/src/settings.ts b/src/settings.ts index 9c0f58f65e..e7c9eea499 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -99,7 +99,6 @@ export interface IIntegratedConsoleSettings { showOnStartup?: boolean; focusConsoleOnExecute?: boolean; useLegacyReadLine?: boolean; - useTrueClear?: boolean; } export function load(): ISettings { @@ -156,8 +155,6 @@ 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 {