@@ -219,7 +219,7 @@ public static PowerShellContextService Create(
219
219
220
220
EditorServicesPSHostUserInterface hostUserInterface =
221
221
hostStartupInfo . ConsoleReplEnabled
222
- ? ( EditorServicesPSHostUserInterface ) new TerminalPSHostUserInterface ( powerShellContext , hostStartupInfo . PSHost , logger )
222
+ ? ( EditorServicesPSHostUserInterface ) new TerminalPSHostUserInterface ( powerShellContext , hostStartupInfo . PSHost , logger )
223
223
: new ProtocolPSHostUserInterface ( languageServer , powerShellContext , logger ) ;
224
224
225
225
EditorServicesPSHost psHost =
@@ -230,7 +230,7 @@ public static PowerShellContextService Create(
230
230
logger ) ;
231
231
232
232
logger . LogTrace ( "Creating initial PowerShell runspace" ) ;
233
- Runspace initialRunspace = PowerShellContextService . CreateRunspace ( psHost , hostStartupInfo . LanguageMode ) ;
233
+ Runspace initialRunspace = PowerShellContextService . CreateRunspace ( psHost , hostStartupInfo . InitialSessionState ) ;
234
234
powerShellContext . Initialize ( hostStartupInfo . ProfilePaths , initialRunspace , true , hostUserInterface ) ;
235
235
powerShellContext . ImportCommandsModuleAsync ( ) ;
236
236
@@ -274,7 +274,7 @@ public static Runspace CreateRunspace(
274
274
var psHost = new EditorServicesPSHost ( powerShellContext , hostDetails , hostUserInterface , logger ) ;
275
275
powerShellContext . ConsoleWriter = hostUserInterface ;
276
276
powerShellContext . ConsoleReader = hostUserInterface ;
277
- return CreateRunspace ( psHost , hostDetails . LanguageMode ) ;
277
+ return CreateRunspace ( psHost , hostDetails . InitialSessionState ) ;
278
278
}
279
279
280
280
/// <summary>
@@ -283,20 +283,8 @@ public static Runspace CreateRunspace(
283
283
/// <param name="psHost">The PSHost that will be used for this Runspace.</param>
284
284
/// <param name="languageMode">The language mode inherited from the orginal PowerShell process. This will be used when creating runspaces so that we honor the same language mode.</param>
285
285
/// <returns></returns>
286
- public static Runspace CreateRunspace ( PSHost psHost , PSLanguageMode languageMode )
286
+ public static Runspace CreateRunspace ( PSHost psHost , InitialSessionState initialSessionState )
287
287
{
288
- InitialSessionState initialSessionState ;
289
- if ( Environment . GetEnvironmentVariable ( "PSES_TEST_USE_CREATE_DEFAULT" ) == "1" ) {
290
- initialSessionState = InitialSessionState . CreateDefault ( ) ;
291
- } else {
292
- initialSessionState = InitialSessionState . CreateDefault2 ( ) ;
293
- }
294
-
295
- // Create and initialize a new Runspace while honoring the LanguageMode of the original runspace
296
- // that started PowerShell Editor Services. This is because the PowerShell Integrated Console
297
- // should have the same LanguageMode of whatever is set by the system.
298
- initialSessionState . LanguageMode = languageMode ;
299
-
300
288
// We set the process scope's execution policy (which is really the runspace's scope) to
301
289
// Bypass so we can import our bundled modules. This is equivalent in scope to the CLI
302
290
// argument `-Bypass`, which (for instance) the extension passes. Thus we emulate this
@@ -612,7 +600,7 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
612
600
// cancelled prompt when it's called again.
613
601
if ( executionOptions . AddToHistory )
614
602
{
615
- this . PromptContext . AddToHistory ( executionOptions . InputString ?? psCommand . Commands [ 0 ] . CommandText ) ;
603
+ this . PromptContext . AddToHistory ( executionOptions . InputString ?? psCommand . Commands [ 0 ] . CommandText ) ;
616
604
}
617
605
618
606
bool hadErrors = false ;
@@ -666,7 +654,7 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
666
654
// Instruct PowerShell to send output and errors to the host
667
655
if ( executionOptions . WriteOutputToHost )
668
656
{
669
- psCommand . Commands [ 0 ] . MergeMyResults (
657
+ psCommand . Commands [ 0 ] . MergeMyResults (
670
658
PipelineResultTypes . Error ,
671
659
PipelineResultTypes . Output ) ;
672
660
@@ -701,7 +689,7 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
701
689
if ( executionOptions . WriteInputToHost )
702
690
{
703
691
this . WriteOutput (
704
- executionOptions . InputString ?? psCommand . Commands [ 0 ] . CommandText ,
692
+ executionOptions . InputString ?? psCommand . Commands [ 0 ] . CommandText ,
705
693
includeNewLine : true ) ;
706
694
}
707
695
@@ -1014,7 +1002,7 @@ public Task<IEnumerable<object>> ExecuteScriptStringAsync(
1014
1002
Validate . IsNotNull ( nameof ( scriptString ) , scriptString ) ;
1015
1003
1016
1004
PSCommand command = null ;
1017
- if ( CurrentRunspace . Runspace . SessionStateProxy . LanguageMode != PSLanguageMode . FullLanguage )
1005
+ if ( CurrentRunspace . Runspace . SessionStateProxy . LanguageMode != PSLanguageMode . FullLanguage )
1018
1006
{
1019
1007
try
1020
1008
{
@@ -1029,7 +1017,7 @@ public Task<IEnumerable<object>> ExecuteScriptStringAsync(
1029
1017
}
1030
1018
1031
1019
// fall back to old behavior
1032
- if ( command == null )
1020
+ if ( command == null )
1033
1021
{
1034
1022
command = new PSCommand ( ) . AddScript ( scriptString . Trim ( ) ) ;
1035
1023
}
@@ -1729,7 +1717,7 @@ internal static string WildcardEscapePath(string path, bool escapeSpaces = false
1729
1717
var sb = new StringBuilder ( ) ;
1730
1718
for ( int i = 0 ; i < path . Length ; i ++ )
1731
1719
{
1732
- char curr = path [ i ] ;
1720
+ char curr = path [ i ] ;
1733
1721
switch ( curr )
1734
1722
{
1735
1723
// Escape '[', ']', '?' and '*' with '`'
@@ -1783,11 +1771,11 @@ internal static string UnescapeWildcardEscapedPath(string wildcardEscapedPath)
1783
1771
for ( int i = 0 ; i < wildcardEscapedPath . Length ; i ++ )
1784
1772
{
1785
1773
// If we see a backtick perform a lookahead
1786
- char curr = wildcardEscapedPath [ i ] ;
1774
+ char curr = wildcardEscapedPath [ i ] ;
1787
1775
if ( curr == '`' && i + 1 < wildcardEscapedPath . Length )
1788
1776
{
1789
1777
// If the next char is an escapable one, don't add this backtick to the new string
1790
- char next = wildcardEscapedPath [ i + 1 ] ;
1778
+ char next = wildcardEscapedPath [ i + 1 ] ;
1791
1779
switch ( next )
1792
1780
{
1793
1781
case '[' :
@@ -2178,14 +2166,14 @@ private void SetExecutionPolicy()
2178
2166
// set to expected values, so we must sift through those.
2179
2167
2180
2168
ExecutionPolicy policyToSet = ExecutionPolicy . Bypass ;
2181
- var currentUserPolicy = ( ExecutionPolicy ) policies [ policies . Count - 2 ] . Members [ "ExecutionPolicy" ] . Value ;
2169
+ var currentUserPolicy = ( ExecutionPolicy ) policies [ policies . Count - 2 ] . Members [ "ExecutionPolicy" ] . Value ;
2182
2170
if ( currentUserPolicy != ExecutionPolicy . Undefined )
2183
2171
{
2184
2172
policyToSet = currentUserPolicy ;
2185
2173
}
2186
2174
else
2187
2175
{
2188
- var localMachinePolicy = ( ExecutionPolicy ) policies [ policies . Count - 1 ] . Members [ "ExecutionPolicy" ] . Value ;
2176
+ var localMachinePolicy = ( ExecutionPolicy ) policies [ policies . Count - 1 ] . Members [ "ExecutionPolicy" ] . Value ;
2189
2177
if ( localMachinePolicy != ExecutionPolicy . Undefined )
2190
2178
{
2191
2179
policyToSet = localMachinePolicy ;
0 commit comments