コード例 #1
0
            public static (IQueueItem, Task <TResponseType?>) Create(
                bool mutatesSolutionState,
                bool requiresLSPSolution,
                ClientCapabilities clientCapabilities,
                string methodName,
                TextDocumentIdentifier?textDocument,
                TRequestType request,
                IRequestHandler <TRequestType, TResponseType> handler,
                Guid activityId,
                ILspLogger logger,
                LspServices lspServices,
                CancellationToken cancellationToken)
            {
                var queueItem = new QueueItem <TRequestType, TResponseType>(
                    mutatesSolutionState,
                    requiresLSPSolution,
                    clientCapabilities,
                    methodName,
                    textDocument,
                    request,
                    handler,
                    activityId,
                    logger,
                    lspServices.GetRequiredService <RequestTelemetryLogger>(),
                    cancellationToken);

                return(queueItem, queueItem._completionSource.Task);
            }
コード例 #2
0
        public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
        {
            var clientCapabilities  = lspServices.GetRequiredService <IClientCapabilitiesProvider>().GetClientCapabilities();
            var notificationManager = lspServices.GetRequiredService <ILanguageServerNotificationManager>();

            return(new SemanticTokensRangeHandler(_globalOptions, _asyncListenerProvider, _lspWorkspaceRegistrationService, notificationManager, clientCapabilities));
        }
コード例 #3
0
    public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
    {
        var logger             = lspServices.GetRequiredService <ILspLogger>();
        var telemetryLogger    = lspServices.GetRequiredService <RequestTelemetryLogger>();
        var miscFilesWorkspace = lspServices.GetService <LspMiscellaneousFilesWorkspace>();

        return(new LspWorkspaceManager(logger, miscFilesWorkspace, _workspaceRegistrationService, telemetryLogger));
    }
コード例 #4
0
 public XamlRequestDispatcher(
     XamlProjectService projectService,
     LspServices services,
     IXamlLanguageServerFeedbackService?feedbackService) : base(services)
 {
     _projectService  = projectService;
     _feedbackService = feedbackService;
 }
コード例 #5
0
        internal LanguageServerTarget(
            AbstractLspServiceProvider lspServiceProvider,
            JsonRpc jsonRpc,
            ICapabilitiesProvider capabilitiesProvider,
            IAsynchronousOperationListenerProvider listenerProvider,
            ILspLogger logger,
            ImmutableArray <string> supportedLanguages,
            WellKnownLspServerKinds serverKind)
        {
            _capabilitiesProvider = capabilitiesProvider;
            _logger = logger;

            _jsonRpc = jsonRpc;
            _jsonRpc.AddLocalRpcTarget(this);
            _jsonRpc.Disconnected += JsonRpc_Disconnected;

            _listener = listenerProvider.GetListener(FeatureAttribute.LanguageServer);

            // Add services that require base dependencies (jsonrpc) or are more complex to create to the set manually.
            _lspServices = lspServiceProvider.CreateServices(serverKind, ImmutableArray.Create(
                                                                 CreateLspServiceInstance <ILanguageServerNotificationManager>(new LanguageServerNotificationManager(_jsonRpc)),
                                                                 CreateLspServiceInstance(logger),
                                                                 CreateLspServiceInstance <IClientCapabilitiesProvider>(this)));

            _queue = new RequestExecutionQueue(
                supportedLanguages,
                serverKind,
                _lspServices);
            _queue.RequestServerShutdown += RequestExecutionQueue_Errored;

            _requestDispatcher = _lspServices.GetRequiredService <RequestDispatcher>();

            var entryPointMethod = typeof(DelegatingEntryPoint).GetMethod(nameof(DelegatingEntryPoint.EntryPointAsync));

            Contract.ThrowIfNull(entryPointMethod, $"{typeof(DelegatingEntryPoint).FullName} is missing method {nameof(DelegatingEntryPoint.EntryPointAsync)}");

            foreach (var metadata in _requestDispatcher.GetRegisteredMethods())
            {
                // Instead of concretely defining methods for each LSP method, we instead dynamically construct the
                // generic method info from the exported handler types.  This allows us to define multiple handlers for
                // the same method but different type parameters.  This is a key functionality to support TS external
                // access as we do not want to couple our LSP protocol version dll to theirs.
                //
                // We also do not use the StreamJsonRpc support for JToken as the rpc method parameters because we want
                // StreamJsonRpc to do the deserialization to handle streaming requests using IProgress<T>.
                var delegatingEntryPoint = new DelegatingEntryPoint(metadata.MethodName, this);

                var genericEntryPointMethod = entryPointMethod.MakeGenericMethod(metadata.RequestType, metadata.ResponseType);

                _jsonRpc.AddLocalRpcMethod(genericEntryPointMethod, delegatingEntryPoint, new JsonRpcMethodAttribute(metadata.MethodName)
                {
                    UseSingleObjectParameterDeserialization = true
                });
            }
コード例 #6
0
 public RequestContext(
     Solution?solution,
     ILspLogger logger,
     ClientCapabilities clientCapabilities,
     WellKnownLspServerKinds serverKind,
     Document?document,
     IDocumentChangeTracker documentChangeTracker,
     ImmutableDictionary <Uri, SourceText> trackedDocuments,
     ImmutableArray <string> supportedLanguages,
     LspServices lspServices,
     CancellationToken queueCancellationToken)
 {
     Document               = document;
     Solution               = solution;
     ClientCapabilities     = clientCapabilities;
     ServerKind             = serverKind;
     SupportedLanguages     = supportedLanguages;
     _documentChangeTracker = documentChangeTracker;
     _logger                = logger;
     _trackedDocuments      = trackedDocuments;
     _lspServices           = lspServices;
     QueueCancellationToken = queueCancellationToken;
 }
コード例 #7
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) => new CompletionListCache();
コード例 #8
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 => new WorkspacePullDiagnosticHandler(_diagnosticService, _editAndContinueDiagnosticUpdateSource, _globalOptions);
コード例 #9
0
        public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
        {
            var completionListCache = lspServices.GetRequiredService <CompletionListCache>();

            return(new CompletionResolveHandler(_globalOptions, completionListCache));
        }
コード例 #10
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 => new DocumentPullDiagnosticHandler(_analyzerService, _editAndContinueDiagnosticUpdateSource, _globalOptions);
コード例 #11
0
        private static ImmutableDictionary <RequestHandlerMetadata, Lazy <IRequestHandler> > CreateMethodToHandlerMap(LspServices lspServices)
        {
            var requestHandlerDictionary = ImmutableDictionary.CreateBuilder <RequestHandlerMetadata, Lazy <IRequestHandler> >();

            var requestHandlerTypes = lspServices.GetRegisteredServices().Where(type => IsTypeRequestHandler(type));

            foreach (var handlerType in requestHandlerTypes)
            {
                var(requestType, responseType) = ConvertHandlerTypeToRequestResponseTypes(handlerType);
                var method = GetRequestHandlerMethod(handlerType);

                // Using the lazy set of handlers, create a lazy instance that will resolve the set of handlers for the provider
                // and then lookup the correct handler for the specified method.
                requestHandlerDictionary.Add(new RequestHandlerMetadata(method, requestType, responseType), new Lazy <IRequestHandler>(() =>
                {
                    Contract.ThrowIfFalse(lspServices.TryGetService(handlerType, out var lspService));
                    return((IRequestHandler)lspService);
                }));
            }

            return(requestHandlerDictionary.ToImmutable());
コード例 #12
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) => new StatefulLspService();
コード例 #13
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 {
     return(CreateRequestHandler());
 }
コード例 #14
0
 public RequestDispatcher(LspServices lspServices)
 {
     _requestHandlers = CreateMethodToHandlerMap(lspServices);
 }
コード例 #15
0
        public static async Task <RequestContext?> CreateAsync(
            bool requiresLSPSolution,
            bool mutatesSolutionState,
            TextDocumentIdentifier?textDocument,
            WellKnownLspServerKinds serverKind,
            ClientCapabilities clientCapabilities,
            ImmutableArray <string> supportedLanguages,
            LspServices lspServices,
            CancellationToken queueCancellationToken,
            CancellationToken requestCancellationToken)
        {
            var lspWorkspaceManager = lspServices.GetRequiredService <LspWorkspaceManager>();
            var logger = lspServices.GetRequiredService <ILspLogger>();
            var documentChangeTracker = mutatesSolutionState ? (IDocumentChangeTracker)lspWorkspaceManager : new NonMutatingDocumentChangeTracker();

            // 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, lspServices: lspServices,
                           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,
                lspServices,
                queueCancellationToken);

            return(context);
        }
コード例 #16
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 => new ExperimentalWorkspacePullDiagnosticsHandler(_analyzerService, _editAndContinueDiagnosticUpdateSource, _globalOptions);
コード例 #17
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) => new LspMiscellaneousFilesWorkspace();
コード例 #18
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 {
     return(new RequestTelemetryLogger(serverKind.ToTelemetryString()));
 }
コード例 #19
0
 public virtual ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 {
     return(new RequestDispatcher(lspServices));
 }
コード例 #20
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 => new DocumentSpellCheckHandler();
コード例 #21
0
 public override ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 {
     return(new XamlRequestDispatcher(_projectService, lspServices, _feedbackService));
 }
コード例 #22
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
 => new WorkspaceSpellCheckHandler();
コード例 #23
0
 public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) => new CodeActionsCache();