コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the DebugService class and uses
        /// the given execution service for all future operations.
        /// </summary>
        public DebugService(
            IInternalPowerShellExecutionService executionService,
            IPowerShellDebugContext debugContext,
            RemoteFileManagerService remoteFileManager,
            BreakpointService breakpointService,
            PsesInternalHost psesHost,
            ILoggerFactory factory)
        {
            Validate.IsNotNull(nameof(executionService), executionService);

            _logger                          = factory.CreateLogger <DebugService>();
            _executionService                = executionService;
            _breakpointService               = breakpointService;
            _psesHost                        = psesHost;
            _debugContext                    = debugContext;
            _debugContext.DebuggerStopped   += OnDebuggerStopAsync;
            _debugContext.DebuggerResuming  += OnDebuggerResuming;
            _debugContext.BreakpointUpdated += OnBreakpointUpdated;
            _remoteFileManager               = remoteFileManager;

            invocationTypeScriptPositionProperty =
                typeof(InvocationInfo)
                .GetProperty(
                    "ScriptPosition",
                    BindingFlags.NonPublic | BindingFlags.Instance);
        }
コード例 #2
0
 public PowerShellDebugContext(
     ILoggerFactory loggerFactory,
     PsesInternalHost psesHost)
 {
     _logger   = loggerFactory.CreateLogger <PowerShellDebugContext>();
     _psesHost = psesHost;
 }
コード例 #3
0
 public EditorOperationsService(
     PsesInternalHost psesHost,
     WorkspaceService workspaceService,
     ILanguageServerFacade languageServer)
 {
     _psesHost         = psesHost;
     _workspaceService = workspaceService;
     _languageServer   = languageServer;
 }
コード例 #4
0
 public LegacyReadLine(
     PsesInternalHost psesHost,
     Func <bool, ConsoleKeyInfo> readKeyFunc,
     Action <CancellationToken> onIdleAction)
 {
     _psesHost     = psesHost;
     _readKeyTasks = new Task[2];
     _readKeyFunc  = readKeyFunc;
     _onIdleAction = onIdleAction;
 }
コード例 #5
0
 public SymbolsServiceTests()
 {
     psesHost       = PsesHostFactory.Create(NullLoggerFactory.Instance);
     workspace      = new WorkspaceService(NullLoggerFactory.Instance);
     symbolsService = new SymbolsService(
         NullLoggerFactory.Instance,
         psesHost,
         psesHost,
         workspace,
         new ConfigurationService());
 }
コード例 #6
0
 public EditorOperationsService(
     PsesInternalHost psesHost,
     WorkspaceService workspaceService,
     IInternalPowerShellExecutionService executionService,
     ILanguageServerFacade languageServer)
 {
     _psesHost         = psesHost;
     _workspaceService = workspaceService;
     _executionService = executionService;
     _languageServer   = languageServer;
 }
コード例 #7
0
 public async Task <DscBreakpointCapability> GetDscBreakpointCapabilityAsync(
     ILogger logger,
     PsesInternalHost psesHost,
     CancellationToken cancellationToken)
 {
     return(_dscBreakpointCapability ??= await DscBreakpointCapability.GetDscCapabilityAsync(
                logger,
                this,
                psesHost,
                cancellationToken)
            .ConfigureAwait(false));
 }
コード例 #8
0
        public ExtensionCommandTests()
        {
            psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
            ExtensionService extensionService = new(
                languageServer : null,
                serviceProvider : null,
                editorOperations : null,
                executionService : psesHost);

            extensionService.InitializeAsync().Wait();
            extensionCommandService = new(extensionService);
        }
コード例 #9
0
 public PsrlReadLine(
     PSReadLineProxy psrlProxy,
     PsesInternalHost psesHost,
     EngineIntrinsics engineIntrinsics,
     Func <bool, ConsoleKeyInfo> readKeyFunc,
     Action <CancellationToken> onIdleAction)
 {
     _psrlProxy        = psrlProxy;
     _psesHost         = psesHost;
     _engineIntrinsics = engineIntrinsics;
     _psrlProxy.OverrideReadKey(readKeyFunc);
     _psrlProxy.OverrideIdleHandler(onIdleAction);
 }
コード例 #10
0
 public SynchronousPSDelegateTask(
     ILogger logger,
     PsesInternalHost psesHost,
     string representation,
     ExecutionOptions executionOptions,
     Action <SMA.PowerShell, CancellationToken> action,
     CancellationToken cancellationToken)
     : base(logger, cancellationToken)
 {
     _psesHost        = psesHost;
     _action          = action;
     _representation  = representation;
     ExecutionOptions = executionOptions ?? s_defaultExecutionOptions;
 }
コード例 #11
0
        public PsesConfigurationHandler(
            ILoggerFactory factory,
            WorkspaceService workspaceService,
            AnalysisService analysisService,
            ConfigurationService configurationService,
            ILanguageServerFacade languageServer,
            ExtensionService extensionService,
            PsesInternalHost psesHost)
        {
            _logger               = factory.CreateLogger <PsesConfigurationHandler>();
            _workspaceService     = workspaceService;
            _configurationService = configurationService;
            _languageServer       = languageServer;
            _extensionService     = extensionService;
            _psesHost             = psesHost;

            ConfigurationUpdated += analysisService.OnConfigurationUpdated;
        }
        public static IServiceCollection AddPsesDebugServices(
            this IServiceCollection collection,
            IServiceProvider languageServiceProvider,
            PsesDebugServer psesDebugServer)
        {
            PsesInternalHost internalHost = languageServiceProvider.GetService <PsesInternalHost>();

            return(collection
                   .AddSingleton(internalHost)
                   .AddSingleton <IRunspaceContext>(internalHost)
                   .AddSingleton <IPowerShellDebugContext>(internalHost.DebugContext)
                   .AddSingleton(languageServiceProvider.GetService <IInternalPowerShellExecutionService>())
                   .AddSingleton(languageServiceProvider.GetService <WorkspaceService>())
                   .AddSingleton(languageServiceProvider.GetService <RemoteFileManagerService>())
                   .AddSingleton(psesDebugServer)
                   .AddSingleton <DebugService>()
                   .AddSingleton <BreakpointService>()
                   .AddSingleton <DebugStateService>()
                   .AddSingleton <DebugEventHandlerService>());
        }
コード例 #13
0
        /// <summary>
        /// Start the debug server listening.
        /// </summary>
        /// <returns>A task that completes when the server is ready.</returns>
        public async Task StartAsync()
        {
            _debugAdapterServer = await DebugAdapterServer.From(options =>
            {
                // We need to let the PowerShell Context Service know that we are in a debug session
                // so that it doesn't send the powerShell/startDebugger message.
                _psesHost = ServiceProvider.GetService <PsesInternalHost>();
                _psesHost.DebugContext.IsDebugServerActive = true;

                options
                .WithInput(_inputStream)
                .WithOutput(_outputStream)
                .WithServices(serviceCollection =>
                              serviceCollection
                              .AddLogging()
                              .AddOptions()
                              .AddPsesDebugServices(ServiceProvider, this))
                // TODO: Consider replacing all WithHandler with AddSingleton
                .WithHandler <LaunchAndAttachHandler>()
                .WithHandler <DisconnectHandler>()
                .WithHandler <BreakpointHandlers>()
                .WithHandler <ConfigurationDoneHandler>()
                .WithHandler <ThreadsHandler>()
                .WithHandler <StackTraceHandler>()
                .WithHandler <ScopesHandler>()
                .WithHandler <VariablesHandler>()
                .WithHandler <ContinueHandler>()
                .WithHandler <NextHandler>()
                .WithHandler <PauseHandler>()
                .WithHandler <StepInHandler>()
                .WithHandler <StepOutHandler>()
                .WithHandler <SourceHandler>()
                .WithHandler <SetVariableHandler>()
                .WithHandler <DebugEvaluateHandler>()
                // The OnInitialize delegate gets run when we first receive the _Initialize_ request:
                // https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
                .OnInitialize(async(server, request, cancellationToken) =>
                {
                    // We need to make sure the host has been started
                    _startedPses = !await _psesHost.TryStartAsync(new HostStartOptions(), CancellationToken.None).ConfigureAwait(false);

                    // Ensure the debugger mode is set correctly - this is required for remote debugging to work
                    _psesHost.DebugContext.EnableDebugMode();

                    BreakpointService breakpointService = server.GetService <BreakpointService>();
                    // Clear any existing breakpoints before proceeding
                    await breakpointService.RemoveAllBreakpointsAsync().ConfigureAwait(false);
                })
                // The OnInitialized delegate gets run right before the server responds to the _Initialize_ request:
                // https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
                .OnInitialized((server, request, response, cancellationToken) =>
                {
                    response.SupportsConditionalBreakpoints    = true;
                    response.SupportsConfigurationDoneRequest  = true;
                    response.SupportsFunctionBreakpoints       = true;
                    response.SupportsHitConditionalBreakpoints = true;
                    response.SupportsLogPoints   = true;
                    response.SupportsSetVariable = true;

                    return(Task.CompletedTask);
                });
            }).ConfigureAwait(false);
        }
コード例 #14
0
        /// <summary>
        /// Start the server listening for input.
        /// </summary>
        /// <remarks>
        /// For the services (including the <see cref="PowerShellContextService">
        /// context wrapper around PowerShell itself) see <see
        /// cref="PsesServiceCollectionExtensions.AddPsesLanguageServices"/>.
        /// </remarks>
        /// <returns>A task that completes when the server is ready and listening.</returns>
        public async Task StartAsync()
        {
            LanguageServer = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(options =>
            {
                options
                .WithInput(_inputStream)
                .WithOutput(_outputStream)
                .WithServices(serviceCollection =>
                {
                    // NOTE: This adds a lot of services!
                    serviceCollection.AddPsesLanguageServices(_hostDetails);
                })
                .ConfigureLogging(builder => builder
                                  .AddSerilog(Log.Logger) // TODO: Set dispose to true?
                                  .AddLanguageProtocolLogging()
                                  .SetMinimumLevel(_minimumLogLevel))
                // TODO: Consider replacing all WithHandler with AddSingleton
                .WithHandler <PsesWorkspaceSymbolsHandler>()
                .WithHandler <PsesTextDocumentHandler>()
                .WithHandler <GetVersionHandler>()
                .WithHandler <PsesConfigurationHandler>()
                .WithHandler <PsesFoldingRangeHandler>()
                .WithHandler <PsesDocumentFormattingHandler>()
                .WithHandler <PsesDocumentRangeFormattingHandler>()
                .WithHandler <PsesReferencesHandler>()
                .WithHandler <PsesDocumentSymbolHandler>()
                .WithHandler <PsesDocumentHighlightHandler>()
                .WithHandler <PSHostProcessAndRunspaceHandlers>()
                .WithHandler <PsesCodeLensHandlers>()
                .WithHandler <PsesCodeActionHandler>()
                .WithHandler <InvokeExtensionCommandHandler>()
                .WithHandler <PsesCompletionHandler>()
                .WithHandler <PsesHoverHandler>()
                .WithHandler <PsesSignatureHelpHandler>()
                .WithHandler <PsesDefinitionHandler>()
                .WithHandler <TemplateHandlers>()
                .WithHandler <GetCommentHelpHandler>()
                .WithHandler <EvaluateHandler>()
                .WithHandler <GetCommandHandler>()
                .WithHandler <ShowHelpHandler>()
                .WithHandler <ExpandAliasHandler>()
                .WithHandler <PsesSemanticTokensHandler>()
                // NOTE: The OnInitialize delegate gets run when we first receive the
                // _Initialize_ request:
                // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize
                .OnInitialize(
                    (languageServer, request, _) =>
                {
                    Log.Logger.Debug("Initializing OmniSharp Language Server");

                    IServiceProvider serviceProvider = languageServer.Services;

                    _psesHost = serviceProvider.GetService <PsesInternalHost>();

                    WorkspaceService workspaceService = serviceProvider.GetService <WorkspaceService>();

                    // Grab the workspace path from the parameters
                    if (request.RootUri != null)
                    {
                        workspaceService.WorkspacePath = request.RootUri.GetFileSystemPath();
                    }
                    else if (request.WorkspaceFolders != null)
                    {
                        // If RootUri isn't set, try to use the first WorkspaceFolder.
                        // TODO: Support multi-workspace.
                        foreach (OmniSharp.Extensions.LanguageServer.Protocol.Models.WorkspaceFolder workspaceFolder in request.WorkspaceFolders)
                        {
                            workspaceService.WorkspacePath = workspaceFolder.Uri.GetFileSystemPath();
                            break;
                        }
                    }

                    return(Task.CompletedTask);
                });
            }).ConfigureAwait(false);

            _serverStart.SetResult(true);
        }
コード例 #15
0
 public CompletionHandlerTests()
 {
     psesHost          = PsesHostFactory.Create(NullLoggerFactory.Instance);
     workspace         = new WorkspaceService(NullLoggerFactory.Instance);
     completionHandler = new PsesCompletionHandler(NullLoggerFactory.Instance, psesHost, psesHost, workspace);
 }