@@ -28,7 +28,7 @@ namespace Microsoft.PowerShell.EditorServices.Services
28
28
using System . Management . Automation ;
29
29
using Microsoft . PowerShell . EditorServices . Handlers ;
30
30
using Microsoft . PowerShell . EditorServices . Hosting ;
31
- using Microsoft . PowerShell . EditorServices . Services . PowerShellContext ;
31
+ using Microsoft . PowerShell . EditorServices . Services . PowerShellContext ;
32
32
33
33
/// <summary>
34
34
/// Manages the lifetime and usage of a PowerShell session.
@@ -222,8 +222,8 @@ public static PowerShellContextService Create(
222
222
hostStartupInfo . InitialSessionState . ImportPSModule ( ( IEnumerable < Commands . ModuleSpecification > ) hostStartupInfo . AdditionalModules ) ;
223
223
hostStartupInfo . InitialSessionState . ImportPSModule ( new string [ ] { s_commandsModulePath } ) ;
224
224
}
225
- Runspace runspace = PowerShellContextService . CreateRunspace ( psHost , hostStartupInfo . InitialSessionState ) ;
226
- powerShellContext . Initialize ( hostStartupInfo . ProfilePaths , runspace , true , hostUserInterface ) ;
225
+ Runspace initialRunspace = PowerShellContextService . CreateRunspace ( psHost , hostStartupInfo . InitialSessionState ) ;
226
+ powerShellContext . Initialize ( hostStartupInfo . ProfilePaths , initialRunspace , true , hostUserInterface ) ;
227
227
// TODO: This can be moved to the point after the $psEditor object
228
228
// gets initialized when that is done earlier than LanguageServer.Initialize
229
229
if ( hostStartupInfo . InitialSessionState . LanguageMode == PSLanguageMode . FullLanguage )
@@ -270,15 +270,50 @@ public static Runspace CreateRunspace(
270
270
powerShellContext . ConsoleReader = hostUserInterface ;
271
271
return CreateRunspace ( psHost , hostDetails . InitialSessionState ) ;
272
272
}
273
-
273
+ private static InitialSessionState GetUsefulConstrainedISS ( )
274
+ {
275
+ InitialSessionState iss = InitialSessionState . Create ( "Microsoft.PowerShell.Core" ) ;
276
+ iss . LanguageMode = PSLanguageMode . ConstrainedLanguage ;
277
+ iss . ImportPSModule ( new string [ ] { "Microsoft.Powershell.Utility" , "Microsoft.Powershell.Core" , "Microsoft.PowerShell.Security" } ) ;
278
+
279
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Get-Command" , typeof ( GetCommandCommand ) , null ) ) ;
280
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Get-ChildItem" , typeof ( PSCommand ) , null ) ) ; //
281
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Export-ModuleMember" , typeof ( ExportModuleMemberCommand ) , null ) ) ;
282
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Where-Object" , typeof ( WhereObjectCommand ) , null ) ) ;
283
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Select-Object" , typeof ( PSCommand ) , null ) ) ;
284
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Set-Variable" , typeof ( PSCommand ) , null ) ) ;
285
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "ForEach-Object" , typeof ( ForEachObjectCommand ) , null ) ) ;
286
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Format-List" , typeof ( PSCommand ) , null ) ) ;
287
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Format-Table" , typeof ( PSCommand ) , null ) ) ;
288
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Set-ExecutionPolicy" , typeof ( PSCommand ) , null ) ) ;
289
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Format-Hex" , typeof ( PSCommand ) , null ) ) ;
290
+ //iss.Commands.Add(new SessionStateCmdletEntry("Out-Default", typeof(OutDefaultCommand), null));
291
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Microsoft.PowerShell.Core\\ Out-Default" , typeof ( OutDefaultCommand ) , null ) { Visibility = SessionStateEntryVisibility . Public } ) ;
292
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Out-Host" , typeof ( OutHostCommand ) , null ) ) ;
293
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Import-Module" , typeof ( ImportModuleCommand ) , null ) ) ;
294
+ iss . Commands . Add ( new SessionStateCmdletEntry ( "Start-EditorServices" , typeof ( PSCommand ) , null ) ) ;
295
+
296
+ return iss ;
297
+ }
274
298
/// <summary>
275
299
///
276
300
/// </summary>
277
301
/// <param name="psHost">The PSHost that will be used for this Runspace.</param>
278
302
/// <param name="initialSessionState">The initialSessionState inherited from the orginal PowerShell process. This will be used when creating runspaces so that we honor the same initialSessionState including allowed modules, cmdlets and language mode.</param>
279
303
/// <returns></returns>
280
- internal static Runspace CreateRunspace ( PSHost psHost , InitialSessionState initialSessionState )
304
+ public static Runspace CreateRunspace ( PSHost psHost , InitialSessionState initialSessionState )
281
305
{
306
+ if ( initialSessionState == null )
307
+ {
308
+ if ( Environment . GetEnvironmentVariable ( "PSES_TEST_USE_CREATE_DEFAULT" ) == "1" )
309
+ {
310
+ initialSessionState = InitialSessionState . CreateDefault ( ) ;
311
+ }
312
+ else
313
+ {
314
+ initialSessionState = InitialSessionState . CreateDefault2 ( ) ;
315
+ }
316
+ }
282
317
Runspace runspace = RunspaceFactory . CreateRunspace ( psHost , initialSessionState ) ;
283
318
284
319
// Windows PowerShell must be hosted in STA mode
0 commit comments