Exemple #1
0
 public static IServiceCollection AddPsesLanguageServices(
     this IServiceCollection collection,
     HostStartupInfo hostStartupInfo)
 {
     return(collection.AddSingleton <WorkspaceService>()
            .AddSingleton <SymbolsService>()
            .AddSingleton <ConfigurationService>()
            .AddSingleton <PowerShellContextService>(
                (provider) =>
                PowerShellContextService.Create(
                    provider.GetService <ILoggerFactory>(),
                    provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>(),
                    hostStartupInfo))
            .AddSingleton <TemplateService>()
            .AddSingleton <EditorOperationsService>()
            .AddSingleton <RemoteFileManagerService>()
            .AddSingleton <ExtensionService>(
                (provider) =>
     {
         var extensionService = new ExtensionService(
             provider.GetService <PowerShellContextService>(),
             provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>());
         extensionService.InitializeAsync(
             serviceProvider: provider,
             editorOperations: provider.GetService <EditorOperationsService>())
         .Wait();
         return extensionService;
     })
            .AddSingleton <AnalysisService>());
 }
Exemple #2
0
        public static PowerShellContextService Create(ILogger logger)
        {
            PowerShellContextService powerShellContext = new PowerShellContextService(logger, null, isPSReadLineEnabled: false);

            HostStartupInfo testHostDetails = new HostStartupInfo(
                "PowerShell Editor Services Test Host",
                "Test.PowerShellEditorServices",
                new Version("1.0.0"),
                null,
                TestProfilePaths,
                new List <string>(),
                new List <string>(),
                PSLanguageMode.FullLanguage,
                null,
                0,
                consoleReplEnabled: false,
                usesLegacyReadLine: false);


            powerShellContext.Initialize(
                TestProfilePaths,
                PowerShellContextService.CreateRunspace(
                    testHostDetails,
                    powerShellContext,
                    new TestPSHostUserInterface(powerShellContext, logger),
                    logger),
                true);

            return(powerShellContext);
        }
 public static IServiceCollection AddPsesLanguageServices(
     this IServiceCollection collection,
     HostStartupInfo hostStartupInfo)
 {
     return(collection.AddSingleton <WorkspaceService>()
            .AddSingleton <SymbolsService>()
            .AddSingleton <ConfigurationService>()
            .AddSingleton <PowerShellContextService>(
                (provider) =>
                PowerShellContextService.Create(
                    provider.GetService <ILoggerFactory>(),
                    // NOTE: Giving the context service access to the language server this
                    // early is dangerous because it allows it to start sending
                    // notifications etc. before it has initialized, potentially resulting
                    // in deadlocks. We're working on a solution to this.
                    provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>(),
                    hostStartupInfo))
            .AddSingleton <TemplateService>() // TODO: What's the difference between this and the TemplateHandler?
            .AddSingleton <EditorOperationsService>()
            .AddSingleton <RemoteFileManagerService>()
            .AddSingleton <ExtensionService>(
                (provider) =>
     {
         var extensionService = new ExtensionService(
             provider.GetService <PowerShellContextService>(),
             // NOTE: See above warning.
             provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>());
         extensionService.InitializeAsync(
             serviceProvider: provider,
             editorOperations: provider.GetService <EditorOperationsService>())
         .Wait();
         return extensionService;
     })
            .AddSingleton <AnalysisService>());
 }
 /// <summary>
 /// Creates a new instance of the ConsoleServicePSHost class
 /// with the given IConsoleHost implementation.
 /// </summary>
 /// <param name="powerShellContext">
 /// An implementation of IHostSupportsInteractiveSession for runspace management.
 /// </param>
 /// <param name="hostDetails">
 /// Provides details about the host application.
 /// </param>
 /// <param name="hostUserInterface">
 /// The EditorServicesPSHostUserInterface implementation to use for this host.
 /// </param>
 /// <param name="logger">An ILogger implementation to use for this host.</param>
 public EditorServicesPSHost(
     PowerShellContextService powerShellContext,
     HostStartupInfo hostDetails,
     EditorServicesPSHostUserInterface hostUserInterface,
     ILogger logger)
 {
     this.Logger            = logger;
     this.hostDetails       = hostDetails;
     this.hostUserInterface = hostUserInterface;
     this.hostSupportsInteractiveSession = powerShellContext;
     this.powerShellContext = powerShellContext;
 }
Exemple #5
0
 /// <summary>
 /// Create a new language server instance.
 /// </summary>
 /// <param name="factory">Factory to create loggers with.</param>
 /// <param name="inputStream">Protocol transport input stream.</param>
 /// <param name="outputStream">Protocol transport output stream.</param>
 /// <param name="hostStartupInfo">Host configuration to instantiate the server and services with.</param>
 public PsesLanguageServer(
     ILoggerFactory factory,
     Stream inputStream,
     Stream outputStream,
     HostStartupInfo hostStartupInfo)
 {
     LoggerFactory    = factory;
     _minimumLogLevel = (LogLevel)hostStartupInfo.LogLevel;
     _inputStream     = inputStream;
     _outputStream    = outputStream;
     _hostDetails     = hostStartupInfo;
     _serverStart     = new TaskCompletionSource <bool>();
 }
        public static PowerShellContextService Create(ILogger logger)
        {
            PowerShellContextService powerShellContext = new PowerShellContextService(logger, null, isPSReadLineEnabled: false);

            // We intentionally use `CreateDefault2()` as it loads `Microsoft.PowerShell.Core` only,
            // which is a more minimal and therefore safer state.
            var initialSessionState = InitialSessionState.CreateDefault2();

            // We set the process scope's execution policy (which is really the runspace's scope) to
            // `Bypass` so we can import our bundled modules. This is equivalent in scope to the CLI
            // argument `-ExecutionPolicy Bypass`, which (for instance) the extension passes. Thus
            // we emulate this behavior for consistency such that unit tests can pass in a similar
            // environment.
            if (VersionUtils.IsWindows)
            {
                initialSessionState.ExecutionPolicy = ExecutionPolicy.Bypass;
            }

            HostStartupInfo testHostDetails = new HostStartupInfo(
                "PowerShell Editor Services Test Host",
                "Test.PowerShellEditorServices",
                new Version("1.0.0"),
                null,
                TestProfilePaths,
                new List <string>(),
                new List <string>(),
                initialSessionState,
                null,
                0,
                consoleReplEnabled: false,
                usesLegacyReadLine: false,
                bundledModulePath: BundledModulePath);

            InitialRunspace = PowerShellContextService.CreateTestRunspace(
                testHostDetails,
                powerShellContext,
                new TestPSHostUserInterface(powerShellContext, logger),
                logger);

            powerShellContext.Initialize(
                TestProfilePaths,
                InitialRunspace,
                ownsInitialRunspace: true,
                consoleHost: null);

            return(powerShellContext);
        }
        public static IServiceCollection AddPsesLanguageServices(
            this IServiceCollection collection,
            HostStartupInfo hostStartupInfo)
        {
            return(collection
                   .AddSingleton(hostStartupInfo)
                   .AddSingleton <WorkspaceService>()
                   .AddSingleton <SymbolsService>()
                   .AddSingleton <PsesInternalHost>()
                   .AddSingleton <IRunspaceContext>(
                       (provider) => provider.GetService <PsesInternalHost>())
                   .AddSingleton <IInternalPowerShellExecutionService>(
                       (provider) => provider.GetService <PsesInternalHost>())
                   .AddSingleton <ConfigurationService>()
                   .AddSingleton <IPowerShellDebugContext>(
                       (provider) => provider.GetService <PsesInternalHost>().DebugContext)
                   .AddSingleton <TemplateService>()
                   .AddSingleton <EditorOperationsService>()
                   .AddSingleton <RemoteFileManagerService>()
                   .AddSingleton((provider) =>
            {
                ExtensionService extensionService = new(
                    provider.GetService <ILanguageServerFacade>(),
                    provider,
                    provider.GetService <EditorOperationsService>(),
                    provider.GetService <IInternalPowerShellExecutionService>());

                // This is where we create the $psEditor variable
                // so that when the console is ready, it will be available
                // TODO: Improve the sequencing here so that:
                //  - The variable is guaranteed to be initialized when the console first appears
                //  - Any errors that occur are handled rather than lost by the unawaited task
                extensionService.InitializeAsync();

                return extensionService;
            })
                   .AddSingleton <AnalysisService>());
        }