示例#1
0
 public ImmutableArray <DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId?projectId, DocumentId?documentId, object?id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
 => GetPushDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, DiagnosticMode.Default, cancellationToken).AsTask().WaitAndGetResult_CanCallOnBackground(cancellationToken);
 public static TextDocument?GetTextDocument(this Project project, DocumentId?documentId)
 => project.Solution.GetTextDocument(documentId);
示例#3
0
 public static TextDocument?GetTextDocument(this Solution solution, DocumentId?documentId)
 => solution.GetDocument(documentId) ?? solution.GetAdditionalDocument(documentId) ?? solution.GetAnalyzerConfigDocument(documentId);
示例#4
0
 public Task <ImmutableArray <DiagnosticData> > GetCachedDiagnosticsAsync(Solution solution, ProjectId?projectId, DocumentId?documentId, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default)
 {
     return(new IdeCachedDiagnosticGetter(this, solution, projectId, documentId, includeSuppressedDiagnostics).GetDiagnosticsAsync(cancellationToken));
 }
示例#5
0
 public Task <ImmutableArray <DiagnosticData> > GetDiagnosticsForIdsAsync(Solution solution, ProjectId?projectId, DocumentId?documentId, ImmutableHashSet <string>?diagnosticIds, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default)
 {
     return(new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, includeSuppressedDiagnostics).GetDiagnosticsAsync(cancellationToken));
 }
示例#6
0
 public IdeCachedDiagnosticGetter(DiagnosticIncrementalAnalyzer owner, Solution solution, ProjectId?projectId, DocumentId?documentId, bool includeSuppressedDiagnostics)
     : base(owner, solution, projectId, documentId, includeSuppressedDiagnostics)
 {
 }
示例#7
0
            private async Task <ImmutableArray <DiagnosticData> > GetProjectStateDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                if (!stateSet.TryGetProjectState(project.Id, out var state))
                {
                    // never analyzed this project yet.
                    return(ImmutableArray <DiagnosticData> .Empty);
                }

                if (documentId != null)
                {
                    // file doesn't exist in current solution
                    var document = project.Solution.GetDocument(documentId);
                    if (document == null)
                    {
                        return(ImmutableArray <DiagnosticData> .Empty);
                    }

                    var result = await state.GetAnalysisDataAsync(Owner.PersistentStorageService, document, avoidLoadingData : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(result.GetDocumentDiagnostics(documentId, kind));
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var nonLocalResult = await state.GetProjectAnalysisDataAsync(Owner.PersistentStorageService, project, avoidLoadingData : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                return(nonLocalResult.GetOtherDiagnostics());
            }
            private static async Task <ImmutableArray <DiagnosticData> > GetProjectStateDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                if (!stateSet.TryGetProjectState(project.Id, out var state))
                {
                    // never analyzed this project yet.
                    return(ImmutableArray <DiagnosticData> .Empty);
                }

                if (documentId != null)
                {
                    // file doesn't exist in current solution
                    var document = await project.Solution.GetDocumentAsync(
                        documentId,
                        includeSourceGenerated : project.Solution.Workspace.Services.GetService <IWorkspaceConfigurationService>()?.Options.EnableOpeningSourceGeneratedFiles == true,
                        cancellationToken).ConfigureAwait(false);

                    if (document == null)
                    {
                        return(ImmutableArray <DiagnosticData> .Empty);
                    }

                    var result = await state.GetAnalysisDataAsync(document, avoidLoadingData : false, cancellationToken).ConfigureAwait(false);

                    return(result.GetDocumentDiagnostics(documentId, kind));
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var nonLocalResult = await state.GetProjectAnalysisDataAsync(project, avoidLoadingData : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                return(nonLocalResult.GetOtherDiagnostics());
            }
        public WorkspaceChangeEventArgs(WorkspaceChangeKind kind, Solution oldSolution, Solution newSolution, ProjectId?projectId = null, DocumentId?documentId = null)
        {
            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(kind));
            }

            this.Kind        = kind;
            this.OldSolution = oldSolution ?? throw new ArgumentNullException(nameof(oldSolution));
            this.NewSolution = newSolution ?? throw new ArgumentNullException(nameof(newSolution));
            this.ProjectId   = projectId;
            this.DocumentId  = documentId;
        }
        private ImmutableArray <DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId?projectId, DocumentId?documentId)
        {
            Assert.Equal(projectId, GetProjectId(workspace));
            Assert.Equal(documentId, GetDocumentId(workspace));

            return(_diagnostic == null ? ImmutableArray <DiagnosticData> .Empty : ImmutableArray.Create(_diagnostic));
        }
 public ImmutableArray <DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId?projectId, DocumentId?documentId, Option2 <DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
 {
     return(GetDiagnosticBuckets(workspace, projectId, documentId));
 }
 public ImmutableArray <DiagnosticData> GetPushDiagnostics(Workspace workspace, ProjectId?projectId, DocumentId?documentId, object?id, bool includeSuppressedDiagnostics, Option2 <DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
 {
     return(GetDiagnostics(workspace, projectId, documentId));
 }
 public ImmutableArray <DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId?projectId, DocumentId?documentId, object?id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
 => GetPushDiagnostics(workspace, projectId, documentId, id, includeSuppressedDiagnostics, InternalDiagnosticsOptions.NormalDiagnosticMode, cancellationToken);
示例#14
0
 public ValueTask <ImmutableArray <DiagnosticData> > GetPushDiagnosticsAsync(Workspace workspace, ProjectId?projectId, DocumentId?documentId, object?id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 {
     return(new ValueTask <ImmutableArray <DiagnosticData> >(GetDiagnostics(workspace, projectId, documentId)));
 }
 /// <summary>
 /// Construct an instance of <see cref="SolutionPreviewItem"/>
 /// </summary>
 /// <param name="projectId"><see cref="ProjectId"/> for the <see cref="Project"/> that contains the content being visualized in the supplied <paramref name="lazyPreview"/></param>
 /// <param name="documentId"><see cref="DocumentId"/> for the <see cref="Document"/> being visualized in the supplied <paramref name="lazyPreview"/></param>
 /// <param name="lazyPreview">Lazily instantiated preview content.</param>
 /// <remarks>Use lazy instantiation to ensure that any <see cref="ITextView"/> that may be present inside a given preview are only instantiated at the point
 /// when the VS lightbulb requests that preview. Otherwise, we could end up instantiating a bunch of <see cref="ITextView"/>s most of which will never get
 /// passed to the VS lightbulb. Such zombie <see cref="ITextView"/>s will never get closed and we will end up leaking memory.</remarks>
 public SolutionPreviewItem(ProjectId?projectId, DocumentId?documentId, Func <CancellationToken, Task <object?> > lazyPreview)
 {
     ProjectId   = projectId;
     DocumentId  = documentId;
     LazyPreview = lazyPreview;
 }
 public ValueTask <ImmutableArray <ActiveStatementSpan> > GetSpansAsync(RemoteServiceCallbackId callbackId, DocumentId?documentId, string filePath, CancellationToken cancellationToken)
 => ((ActiveStatementSpanProviderCallback)GetCallback(callbackId)).GetSpansAsync(documentId, filePath, cancellationToken);
 public SolutionPreviewItem(ProjectId?projectId, DocumentId?documentId, string text)
     : this(projectId, documentId, c => Task.FromResult <object?>(text))
 {
     Text = text;
 }
示例#18
0
        public ImmutableArray <DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId?projectId, DocumentId?documentId, object?id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
        {
            Assert.Equal(projectId, GetProjectId(workspace));
            Assert.Equal(documentId, GetDocumentId(workspace));

            return(_diagnostic == null ? ImmutableArray <DiagnosticData> .Empty : ImmutableArray.Create(_diagnostic));
        }
示例#19
0
            protected override async Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                // active file diagnostics:
                if (documentId != null && kind != AnalysisKind.NonLocal && stateSet.TryGetActiveFileState(documentId, out var state))
                {
                    return(state.GetAnalysisData(kind).Items);
                }

                // project diagnostics:
                return(await GetProjectStateDiagnosticsAsync(stateSet, project, documentId, kind, cancellationToken).ConfigureAwait(false));
            }
示例#20
0
        public ImmutableArray <DiagnosticBucket> GetDiagnosticBuckets(Workspace workspace, ProjectId?projectId, DocumentId?documentId, CancellationToken cancellationToken)
        {
            Assert.Equal(projectId, GetProjectId(workspace));
            Assert.Equal(documentId, GetDocumentId(workspace));

            return(_diagnostic == null
                ? ImmutableArray <DiagnosticBucket> .Empty
                : ImmutableArray.Create(new DiagnosticBucket(this, workspace, GetProjectId(workspace), GetDocumentId(workspace))));
        }
示例#21
0
 public IdeLatestDiagnosticGetter(DiagnosticIncrementalAnalyzer owner, Solution solution, ProjectId?projectId, DocumentId?documentId, ImmutableHashSet <string>?diagnosticIds, bool includeSuppressedDiagnostics)
     : base(owner, solution, projectId, documentId, includeSuppressedDiagnostics)
 {
     _diagnosticIds = diagnosticIds;
 }
示例#22
0
        public ActiveStatementSpan(int ordinal, LinePositionSpan lineSpan, ActiveStatementFlags flags, DocumentId?unmappedDocumentId)
        {
            Debug.Assert(ordinal >= 0);

            Ordinal            = ordinal;
            LineSpan           = lineSpan;
            Flags              = flags;
            UnmappedDocumentId = unmappedDocumentId;
        }
示例#23
0
            protected override async Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var stateSets = SpecializedCollections.SingletonCollection(stateSet);

                // Here, we don't care what kind of analyzer (StateSet) is given.
                var forceAnalyzerRun = true;
                var compilation      = await CreateCompilationWithAnalyzersAsync(project, stateSets, IncludeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);

                if (documentId != null)
                {
                    var document = project.Solution.GetDocument(documentId);
                    Contract.ThrowIfNull(document);

                    switch (kind)
                    {
                    case AnalysisKind.Syntax:
                    case AnalysisKind.Semantic:
                        return((await Owner.GetDocumentAnalysisDataAsync(compilation, document, stateSet, kind, cancellationToken).ConfigureAwait(false)).Items);

                    case AnalysisKind.NonLocal:
                        var nonLocalDocumentResult = await Owner.GetProjectAnalysisDataAsync(compilation, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false);

                        var analysisResult = nonLocalDocumentResult.GetResult(stateSet.Analyzer);
                        return(analysisResult.GetDocumentDiagnostics(documentId, AnalysisKind.NonLocal));

                    default:
                        throw ExceptionUtilities.UnexpectedValue(kind);
                    }
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var projectResult = await Owner.GetProjectAnalysisDataAsync(compilation, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false);

                return(projectResult.GetResult(stateSet.Analyzer).GetOtherDiagnostics());
            }
示例#24
0
            private static async Task <ImmutableArray <DiagnosticData> > GetProjectStateDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                if (!stateSet.TryGetProjectState(project.Id, out var state))
                {
                    // never analyzed this project yet.
                    return(ImmutableArray <DiagnosticData> .Empty);
                }

                if (documentId != null)
                {
                    // file doesn't exist in current solution
                    var document = await project.Solution.GetDocumentAsync(
                        documentId,
                        includeSourceGenerated : project.Solution.Workspace.Services.GetService <ISyntaxTreeConfigurationService>() is { EnableOpeningSourceGeneratedFilesInWorkspace : true },
示例#25
0
 protected abstract Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken);
示例#26
0
 public ActiveStatementTrackingSpan(ITrackingSpan trackingSpan, int ordinal, ActiveStatementFlags flags, DocumentId?unmappedDocumentId)
 {
     Span               = trackingSpan;
     Ordinal            = ordinal;
     Flags              = flags;
     UnmappedDocumentId = unmappedDocumentId;
 }
 public TableEntriesSource(LiveTableDataSource source, Workspace workspace, ProjectId?projectId, DocumentId?documentId, object id)
 {
     _source     = source;
     _workspace  = workspace;
     _projectId  = projectId;
     _documentId = documentId;
     _id         = id;
     _buildTool  = (id as BuildToolId)?.BuildTool ?? string.Empty;
 }
示例#28
0
 public Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(Solution solution, ProjectId?projectId, DocumentId?documentId, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default)
 => new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds: null, includeSuppressedDiagnostics).GetDiagnosticsAsync(cancellationToken);
        public Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(Solution solution, ProjectId?projectId = null, DocumentId?documentId = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default)
        {
            if (_map.TryGetValue(solution.Workspace, out var analyzer))
            {
                return(analyzer.GetDiagnosticsAsync(solution, projectId, documentId, includeSuppressedDiagnostics, cancellationToken));
            }

            return(SpecializedTasks.EmptyImmutableArray <DiagnosticData>());
        }
示例#30
0
 public ValueTask <ImmutableArray <ActiveStatementSpan> > GetSpansAsync(Solution solution, DocumentId?documentId, string filePath, CancellationToken cancellationToken)
 => _session?.GetSpansAsync(solution, documentId, filePath, cancellationToken) ?? new(ImmutableArray <ActiveStatementSpan> .Empty);