66using Microsoft . Extensions . Logging . Abstractions ;
77using Microsoft . PowerShell . EditorServices . Extensions ;
88using Microsoft . PowerShell . EditorServices . Services ;
9+ using Microsoft . PowerShell . EditorServices . Services . Configuration ;
910using Microsoft . PowerShell . EditorServices . Services . Extension ;
1011using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
12+ using Newtonsoft . Json ;
1113using OmniSharp . Extensions . LanguageServer . Protocol ;
1214using Xunit ;
1315
1416namespace PowerShellEditorServices . Test . Extensions
1517{
18+ [ CollectionDefinition ( "Console" , DisableParallelization = true ) ]
19+ public class ConsoleCollectionDefinition
20+ {
21+ }
22+
23+ [ Collection ( "Console" ) ]
1624 [ Trait ( "Category" , "Extensions" ) ]
1725 public class EditorOperationsServiceTests
1826 {
@@ -36,7 +44,8 @@ public void GetWorkspaceOpenDocumentsReturnsOnlyOpenDocumentsAndCurrentInMemoryS
3644 EditorOperationsService editorOperationsService = new (
3745 psesHost : null ,
3846 workspaceService ,
39- languageServer : null ) ;
47+ languageServer : null ,
48+ new ConfigurationService ( ) ) ;
4049
4150 WorkspaceOpenDocument [ ] documents = editorOperationsService . GetWorkspaceOpenDocuments ( ) ;
4251
@@ -60,7 +69,8 @@ public void GetWorkspaceOpenDocumentsTracksEditedAndUntitledSaveStates()
6069 EditorOperationsService editorOperationsService = new (
6170 psesHost : null ,
6271 workspaceService ,
63- languageServer : null ) ;
72+ languageServer : null ,
73+ new ConfigurationService ( ) ) ;
6474
6575 WorkspaceOpenDocument [ ] initialDocuments = editorOperationsService . GetWorkspaceOpenDocuments ( ) ;
6676 Assert . Contains ( initialDocuments , static document => document . Path . EndsWith ( "open-saved.ps1" ) && document . Saved ) ;
@@ -87,6 +97,45 @@ public void GetWorkspaceOpenDocumentsTracksEditedAndUntitledSaveStates()
8797 Assert . Contains ( savedDocuments , static document => document . Path . StartsWith ( "untitled:" , StringComparison . Ordinal ) && ! document . Saved ) ;
8898 }
8999
100+ [ Fact ]
101+ public void LanguageServerSettingsUpdatesForceClearScrollbackBuffer ( )
102+ {
103+ LanguageServerSettings incomingSettings = JsonConvert . DeserializeObject < LanguageServerSettings > (
104+ "{\" integratedConsole\" :{\" forceClearScrollbackBuffer\" :true}}" ) ;
105+ LanguageServerSettings currentSettings = new ( ) ;
106+
107+ currentSettings . Update ( incomingSettings , workspaceRootPath : string . Empty , NullLogger . Instance ) ;
108+
109+ Assert . True ( currentSettings . IntegratedConsole . ForceClearScrollbackBuffer ) ;
110+ }
111+
112+ [ Fact ]
113+ public void ClearTerminalWritesEraseSavedLinesWhenConfigured ( )
114+ {
115+ WorkspaceService workspaceService = new ( NullLoggerFactory . Instance ) ;
116+ ConfigurationService configurationService = new ( ) ;
117+ configurationService . CurrentSettings . IntegratedConsole . ForceClearScrollbackBuffer = true ;
118+ EditorOperationsService editorOperationsService = new (
119+ psesHost : null ,
120+ workspaceService ,
121+ languageServer : null ,
122+ configurationService ) ;
123+ StringWriter output = new ( ) ;
124+ TextWriter originalOutput = Console . Out ;
125+
126+ try
127+ {
128+ Console . SetOut ( output ) ;
129+ editorOperationsService . ClearTerminal ( ) ;
130+ }
131+ finally
132+ {
133+ Console . SetOut ( originalOutput ) ;
134+ }
135+
136+ Assert . Equal ( "\u001b [3J" , output . ToString ( ) ) ;
137+ }
138+
90139 private static ScriptFile CreateFileBuffer ( WorkspaceService workspaceService , string fileName )
91140 {
92141 string filePath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( "N" ) , fileName ) ;
0 commit comments