IDiagnosticAnalyzerService.cs 7.8 KB
Newer Older
1
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
2 3 4 5 6 7 8 9 10 11 12 13

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Diagnostics
{
    internal interface IDiagnosticAnalyzerService
    {
        /// <summary>
14
        /// Re-analyze given projects and documents
15
        /// </summary>
16
        void Reanalyze(Workspace workspace, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null, bool highPriority = false);
17 18

        /// <summary>
19
        /// Get specific diagnostics currently stored in the source. returned diagnostic might be out-of-date if solution has changed but analyzer hasn't run for the new solution.
20
        /// </summary>
C
CyrusNajmabadi 已提交
21
        Task<ImmutableArray<DiagnosticData>> GetSpecificCachedDiagnosticsAsync(Workspace workspace, object id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
22 23

        /// <summary>
24
        /// Get diagnostics currently stored in the source. returned diagnostic might be out-of-date if solution has changed but analyzer hasn't run for the new solution.
25
        /// </summary>
C
CyrusNajmabadi 已提交
26
        Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(Workspace workspace, ProjectId projectId = null, DocumentId documentId = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
27 28

        /// <summary>
29
        /// Get specific diagnostics for the given solution. all diagnostics returned should be up-to-date with respect to the given solution.
30
        /// </summary>
C
CyrusNajmabadi 已提交
31
        Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Solution solution, object id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
32 33

        /// <summary>
34
        /// Get diagnostics for the given solution. all diagnostics returned should be up-to-date with respect to the given solution.
35
        /// </summary>
C
CyrusNajmabadi 已提交
36
        Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
37

38
        /// <summary>
39 40 41 42 43 44
        /// Force computes diagnostics and raises diagnostic events for the given project or solution. all diagnostics returned should be up-to-date with respect to the given project or solution.
        /// </summary>
        Task ForceAnalyzeAsync(Solution solution, ProjectId projectId = null, CancellationToken cancellationToken = default);

        /// <summary>
        /// True if given project has any diagnostics
45 46 47
        /// </summary>
        bool ContainsDiagnostics(Workspace workspace, ProjectId projectId);

48
        /// <summary>
49
        /// Get diagnostics of the given diagnostic ids from the given solution. all diagnostics returned should be up-to-date with respect to the given solution.
50
        /// Note that for project case, this method returns diagnostics from all project documents as well. Use <see cref="GetProjectDiagnosticsForIdsAsync(Solution, ProjectId, ImmutableHashSet{string}, bool, CancellationToken)"/>
51 52
        /// if you want to fetch only project diagnostics without source locations.
        /// </summary>
C
CyrusNajmabadi 已提交
53
        Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, ImmutableHashSet<string> diagnosticIds = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
54 55

        /// <summary>
56
        /// Get project diagnostics (diagnostics with no source location) of the given diagnostic ids from the given solution. all diagnostics returned should be up-to-date with respect to the given solution.
57
        /// Note that this method doesn't return any document diagnostics. Use <see cref="GetDiagnosticsForIdsAsync(Solution, ProjectId, DocumentId, ImmutableHashSet{string}, bool, CancellationToken)"/> to also fetch those.
58
        /// </summary>
C
CyrusNajmabadi 已提交
59
        Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId = null, ImmutableHashSet<string> diagnosticIds = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
60 61

        /// <summary>
62
        /// Try to return up to date diagnostics for the given span for the document.
C
Carol Hu 已提交
63
        ///
64
        /// It will return true if it was able to return all up-to-date diagnostics.
65 66
        ///  otherwise, false indicating there are some missing diagnostics in the diagnostic list
        /// </summary>
C
CyrusNajmabadi 已提交
67
        Task<bool> TryAppendDiagnosticsForSpanAsync(Document document, TextSpan range, List<DiagnosticData> diagnostics, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
68 69

        /// <summary>
70
        /// Return up to date diagnostics for the given span for the document
C
Carol Hu 已提交
71
        ///
72 73
        /// This can be expensive since it is force analyzing diagnostics if it doesn't have up-to-date one yet.
        /// If diagnosticIdOpt is not null, it gets diagnostics only for this given diagnosticIdOpt value
74
        /// </summary>
J
JieCarolHu 已提交
75
        Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsync(Document document, TextSpan range, string diagnosticIdOpt = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default);
76 77

        /// <summary>
78
        /// Gets a list of <see cref="DiagnosticAnalyzer"/>s for the given <see cref="Project"/>
79
        /// </summary>
80
        ImmutableArray<DiagnosticAnalyzer> GetDiagnosticAnalyzers(Project project);
81 82

        /// <summary>
83 84 85
        /// Gets a list of <see cref="DiagnosticDescriptor"/>s per <see cref="AnalyzerReference"/>
        /// If the given <paramref name="projectOpt"/> is non-null, then gets <see cref="DiagnosticDescriptor"/>s for the project.
        /// Otherwise, returns the global set of <see cref="DiagnosticDescriptor"/>s enabled for the workspace.
86
        /// </summary>
87 88 89 90 91 92 93
        /// <returns>A mapping from <see cref="AnalyzerReference.Display"/> to the <see cref="DiagnosticDescriptor"/></returns>
        ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptor>> CreateDiagnosticDescriptorsPerReference(Project projectOpt);

        /// <summary>
        /// Gets supported <see cref="DiagnosticDescriptor"/>s of <see cref="DiagnosticAnalyzer"/>.
        /// </summary>
        /// <returns>A list of the diagnostic descriptors of the analyzer</returns>
94
        ImmutableArray<DiagnosticDescriptor> GetDiagnosticDescriptors(DiagnosticAnalyzer analyzer);
95 96 97 98 99

        /// <summary>
        /// Check whether given diagnostic is compiler diagnostic or not
        /// </summary>
        bool IsCompilerDiagnostic(string language, DiagnosticData diagnostic);
H
Heejae Chang 已提交
100 101 102 103 104 105 106 107 108 109

        /// <summary>
        /// Get compiler analyzer for the given language
        /// </summary>
        DiagnosticAnalyzer GetCompilerDiagnosticAnalyzer(string language);

        /// <summary>
        /// Check whether given <see cref="DiagnosticAnalyzer"/> is compiler analyzer for the language or not.
        /// </summary>
        bool IsCompilerDiagnosticAnalyzer(string language, DiagnosticAnalyzer analyzer);
H
Heejae Chang 已提交
110

111 112 113 114 115 116
        /// <summary>
        /// Check whether given <see cref="DiagnosticAnalyzer"/> is compilation end analyzer
        /// By compilation end analyzer, it means compilation end analysis here
        /// </summary>
        bool IsCompilationEndAnalyzer(DiagnosticAnalyzer analyzer, Project project, Compilation compilation);

H
Heejae Chang 已提交
117 118 119 120
        /// <summary>
        /// Return host <see cref="AnalyzerReference"/>s. (ex, analyzers installed by vsix)
        /// </summary>
        IEnumerable<AnalyzerReference> GetHostAnalyzerReferences();
121 122
    }
}