Esempio n. 1
0
 public RequestContext(
     Solution?solution,
     ILspLogger logger,
     ClientCapabilities clientCapabilities,
     WellKnownLspServerKinds serverKind,
     Document?document,
     IDocumentChangeTracker documentChangeTracker,
     ImmutableDictionary <Uri, SourceText> trackedDocuments,
     ImmutableArray <string> supportedLanguages,
     IGlobalOptionService globalOptions,
     ILanguageServerNotificationManager notificationManager,
     CancellationToken queueCancellationToken)
 {
     Document               = document;
     Solution               = solution;
     ClientCapabilities     = clientCapabilities;
     ServerKind             = serverKind;
     SupportedLanguages     = supportedLanguages;
     GlobalOptions          = globalOptions;
     _documentChangeTracker = documentChangeTracker;
     _logger                = logger;
     _trackedDocuments      = trackedDocuments;
     NotificationManager    = notificationManager;
     QueueCancellationToken = queueCancellationToken;
 }
Esempio n. 2
0
        public static async Task <RequestContext?> CreateAsync(
            bool requiresLSPSolution,
            TextDocumentIdentifier?textDocument,
            WellKnownLspServerKinds serverKind,
            ILspLogger logger,
            ClientCapabilities clientCapabilities,
            LspWorkspaceManager lspWorkspaceManager,
            ILanguageServerNotificationManager notificationManager,
            IDocumentChangeTracker documentChangeTracker,
            ImmutableArray <string> supportedLanguages,
            IGlobalOptionService globalOptions,
            CancellationToken queueCancellationToken,
            CancellationToken requestCancellationToken)
        {
            // Retrieve the current LSP tracked text as of this request.
            // This is safe as all creation of request contexts cannot happen concurrently.
            var trackedDocuments = lspWorkspaceManager.GetTrackedLspText();

            // If the handler doesn't need an LSP solution we do two important things:
            // 1. We don't bother building the LSP solution for perf reasons
            // 2. We explicitly don't give the handler a solution or document, even if we could
            //    so they're not accidentally operating on stale solution state.
            if (!requiresLSPSolution)
            {
                return(new RequestContext(
                           solution: null, logger: logger, clientCapabilities: clientCapabilities, serverKind: serverKind, document: null,
                           documentChangeTracker: documentChangeTracker, trackedDocuments: trackedDocuments, supportedLanguages: supportedLanguages, globalOptions: globalOptions,
                           notificationManager: notificationManager, queueCancellationToken: queueCancellationToken));
            }

            Solution?workspaceSolution;
            Document?document = null;

            if (textDocument is not null)
            {
                // we were given a request associated with a document.  Find the corresponding roslyn document for this.
                // There are certain cases where we may be asked for a document that does not exist (for example a document is removed)
                // For example, document pull diagnostics can ask us after removal to clear diagnostics for a document.
                document = await lspWorkspaceManager.GetLspDocumentAsync(textDocument, requestCancellationToken).ConfigureAwait(false);
            }

            workspaceSolution = document?.Project.Solution ?? await lspWorkspaceManager.TryGetHostLspSolutionAsync(requestCancellationToken).ConfigureAwait(false);

            if (workspaceSolution == null)
            {
                logger.TraceError("Could not find appropriate solution for operation");
                return(null);
            }

            var context = new RequestContext(
                workspaceSolution,
                logger,
                clientCapabilities,
                serverKind,
                document,
                documentChangeTracker,
                trackedDocuments,
                supportedLanguages,
                globalOptions,
                notificationManager,
                queueCancellationToken);

            return(context);
        }