예제 #1
0
        public async Task <DiagnosticResult> GetDiagnostics(WorkspaceRequest request, Budget budget)
        {
            budget ??= new TimeBudget(TimeSpan.FromSeconds(defaultBudgetInSeconds));

            var package = await _packageFinder.Find <ICreateWorkspace>(request.Workspace.WorkspaceType);

            var workspace = await request.Workspace.InlineBuffersAsync();

            var sourceFiles = workspace.GetSourceFiles();

            var(_, documents) = await package.GetCompilationForLanguageServices(sourceFiles, GetSourceCodeKind(request), GetUsings(request.Workspace), budget);

            var selectedDocument = documents.FirstOrDefault(doc => doc.IsMatch(request.ActiveBufferId.FileName))
                                   ??
                                   (documents.Count == 1 ? documents.Single() : null);

            if (selectedDocument == null)
            {
                return(new DiagnosticResult(requestId: request.RequestId));
            }

            var diagnostics = await DiagnosticsExtractor.ExtractSerializableDiagnosticsFromDocument(request.ActiveBufferId, budget, selectedDocument, workspace);

            var result = new DiagnosticResult(diagnostics, request.RequestId);

            return(result);
        }
예제 #2
0
        public async Task <SignatureHelpResult> GetSignatureHelp(WorkspaceRequest request, Budget budget)
        {
            budget ??= new TimeBudget(TimeSpan.FromSeconds(defaultBudgetInSeconds));

            var package = await _packageFinder.Find <ICreateWorkspace>(request.Workspace.WorkspaceType);

            var workspace = await request.Workspace.InlineBuffersAsync();

            var sourceFiles = workspace.GetSourceFiles();

            var(compilation, project) = await package.GetCompilationForLanguageServices(sourceFiles, GetSourceCodeKind(request), GetUsings(request.Workspace), budget);

            var documents = project.Documents.ToList();

            var selectedDocument = documents.FirstOrDefault(doc => doc.IsMatch(request.ActiveBufferId.FileName))
                                   ??
                                   (documents.Count == 1 ? documents.Single() : null);

            if (selectedDocument == null)
            {
                return(new SignatureHelpResult(requestId: request.RequestId));
            }

            var diagnostics = await DiagnosticsExtractor.ExtractSerializableDiagnosticsFromDocument(request.ActiveBufferId, budget, selectedDocument, workspace);

            var tree = await selectedDocument.GetSyntaxTreeAsync();

            var absolutePosition = workspace.GetAbsolutePositionForGetBufferWithSpecifiedIdOrSingleBufferIfThereIsOnlyOne(request.ActiveBufferId);

            var syntaxNode = tree.GetRoot().FindToken(absolutePosition).Parent;

            var result = await SignatureHelpService.GetSignatureHelp(
                () => Task.FromResult(compilation.GetSemanticModel(tree)),
                syntaxNode,
                absolutePosition);

            result.RequestId = request.RequestId;
            if (diagnostics?.Count > 0)
            {
                result.Diagnostics = diagnostics;
            }

            return(result);
        }