本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager类的典型用法代码示例。如果您正苦于以下问题:C# AnalyzerManager类的具体用法?C# AnalyzerManager怎么用?C# AnalyzerManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnalyzerManager类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了AnalyzerManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DiagnosticAnalyzersAndStates
public DiagnosticAnalyzersAndStates(DiagnosticIncrementalAnalyzer owner, Workspace workspace, AnalyzerManager analyzerManager)
{
_owner = owner;
_sharedAnalyzersAndStates = new WorkspaceAnalyzersAndStates(analyzerManager);
_projectAnalyzersAndStatesMap = new ConcurrentDictionary<ProjectId, ProjectAnalyzersAndStates>();
this.Workspace = workspace;
}
示例2: DiagnosticIncrementalAnalyzer
public DiagnosticIncrementalAnalyzer(DiagnosticAnalyzerService owner, int correlationId, Workspace workspace, AnalyzerManager analyzerManager)
{
_owner = owner;
_correlationId = correlationId;
_memberRangeMap = new MemberRangeMap();
_analyzersAndState = new DiagnosticAnalyzersAndStates(this, workspace, analyzerManager);
_executor = new AnalyzerExecutor(this);
_diagnosticLogAggregator = new DiagnosticLogAggregator(_owner);
}
示例3: IncrementalAnalyzerDelegatee
public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, AnalyzerManager analyzerManager)
{
_workspace = workspace;
_analyzerManager = analyzerManager;
_owner = owner;
var v1CorrelationId = LogAggregator.GetNextId();
_engineV1 = new EngineV1.DiagnosticIncrementalAnalyzer(_owner, v1CorrelationId, _workspace, _analyzerManager);
var v2CorrelationId = LogAggregator.GetNextId();
_engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(_owner, v2CorrelationId, _workspace, _analyzerManager);
}
示例4: RunCore
internal int RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken)
{
Debug.Assert(!Arguments.IsScriptRunner);
cancellationToken.ThrowIfCancellationRequested();
if (Arguments.DisplayVersion)
{
PrintVersion(consoleOutput);
return Succeeded;
}
if (Arguments.DisplayLogo)
{
PrintLogo(consoleOutput);
}
if (Arguments.DisplayHelp)
{
PrintHelp(consoleOutput);
return Succeeded;
}
if (ReportErrors(Arguments.Errors, consoleOutput, errorLogger))
{
return Failed;
}
var touchedFilesLogger = (Arguments.TouchedFilesPath != null) ? new TouchedFileLogger() : null;
Compilation compilation = CreateCompilation(consoleOutput, touchedFilesLogger, errorLogger);
if (compilation == null)
{
return Failed;
}
var diagnosticInfos = new List<DiagnosticInfo>();
ImmutableArray<DiagnosticAnalyzer> analyzers = ResolveAnalyzersFromArguments(diagnosticInfos, MessageProvider);
var additionalTextFiles = ResolveAdditionalFilesFromArguments(diagnosticInfos, MessageProvider, touchedFilesLogger);
if (ReportErrors(diagnosticInfos, consoleOutput, errorLogger))
{
return Failed;
}
var diagnostics = new List<Diagnostic>();
ImmutableArray<EmbeddedText> embeddedTexts = AcquireEmbeddedTexts(compilation, diagnostics);
if (ReportErrors(diagnostics, consoleOutput, errorLogger))
{
return Failed;
}
bool reportAnalyzer = false;
CancellationTokenSource analyzerCts = null;
AnalyzerManager analyzerManager = null;
AnalyzerDriver analyzerDriver = null;
try
{
// Print the diagnostics produced during the parsing stage and exit if there were any errors.
if (ReportErrors(compilation.GetParseDiagnostics(), consoleOutput, errorLogger))
{
return Failed;
}
ConcurrentSet<Diagnostic> analyzerExceptionDiagnostics = null;
if (!analyzers.IsEmpty)
{
analyzerCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
analyzerManager = new AnalyzerManager();
analyzerExceptionDiagnostics = new ConcurrentSet<Diagnostic>();
Action<Diagnostic> addExceptionDiagnostic = diagnostic => analyzerExceptionDiagnostics.Add(diagnostic);
var analyzerOptions = new AnalyzerOptions(ImmutableArray<AdditionalText>.CastUp(additionalTextFiles));
analyzerDriver = AnalyzerDriver.CreateAndAttachToCompilation(compilation, analyzers, analyzerOptions, analyzerManager, addExceptionDiagnostic, Arguments.ReportAnalyzer, out compilation, analyzerCts.Token);
reportAnalyzer = Arguments.ReportAnalyzer && !analyzers.IsEmpty;
}
if (ReportErrors(compilation.GetDeclarationDiagnostics(), consoleOutput, errorLogger))
{
return Failed;
}
cancellationToken.ThrowIfCancellationRequested();
string outputName = GetOutputFileName(compilation, cancellationToken);
var finalPeFilePath = Path.Combine(Arguments.OutputDirectory, outputName);
var finalPdbFilePath = Arguments.PdbPath ?? Path.ChangeExtension(finalPeFilePath, ".pdb");
var finalXmlFilePath = Arguments.DocumentationPath;
var diagnosticBag = DiagnosticBag.GetInstance();
Stream sourceLinkStreamOpt = null;
try
{
// NOTE: Unlike the PDB path, the XML doc path is not embedded in the assembly, so we don't need to pass it to emit.
var emitOptions = Arguments.EmitOptions.
WithOutputNameOverride(outputName).
WithPdbFilePath(finalPdbFilePath);
//.........这里部分代码省略.........
示例5: DiagnosticAnalyzerService
// internal for testing purposes.
internal DiagnosticAnalyzerService(ImmutableArray<AnalyzerReference> workspaceAnalyzers) : this()
{
_analyzerManager = new AnalyzerManager(workspaceAnalyzers);
}
示例6: IsDiagnosticAnalyzerSuppressed
/// <summary>
/// Returns true if all the diagnostics that can be produced by this analyzer are suppressed through options.
/// </summary>
internal static bool IsDiagnosticAnalyzerSuppressed(
DiagnosticAnalyzer analyzer,
CompilationOptions options,
AnalyzerManager analyzerManager,
AnalyzerExecutor analyzerExecutor)
{
return analyzerManager.IsDiagnosticAnalyzerSuppressed(analyzer, options, IsCompilerAnalyzer, analyzerExecutor);
}
示例7: AnalyzerDriver
/// <summary>
/// Create an analyzer driver.
/// </summary>
/// <param name="analyzers">The set of analyzers to include in the analysis</param>
/// <param name="analyzerManager">AnalyzerManager to manage analyzers for analyzer host's lifetime.</param>
protected AnalyzerDriver(ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerManager analyzerManager)
{
this.analyzers = analyzers;
this.analyzerManager = analyzerManager;
}
示例8: CreateAndAttachToCompilation
/// <summary>
/// Create an <see cref="AnalyzerDriver"/> and attach it to the given compilation.
/// </summary>
/// <param name="compilation">The compilation to which the new driver should be attached.</param>
/// <param name="analyzers">The set of analyzers to include in the analysis.</param>
/// <param name="options">Options that are passed to analyzers.</param>
/// <param name="analyzerManager">AnalyzerManager to manage analyzers for the lifetime of analyzer host.</param>
/// <param name="addExceptionDiagnostic">Delegate to add diagnostics generated for exceptions from third party analyzers.</param>
/// <param name="reportAnalyzer">Report additional information related to analyzers, such as analyzer execution time.</param>
/// <param name="newCompilation">The new compilation with the analyzer driver attached.</param>
/// <param name="cancellationToken">A cancellation token that can be used to abort analysis.</param>
/// <returns>A newly created analyzer driver</returns>
/// <remarks>
/// Note that since a compilation is immutable, the act of creating a driver and attaching it produces
/// a new compilation. Any further actions on the compilation should use the new compilation.
/// </remarks>
public static AnalyzerDriver CreateAndAttachToCompilation(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions options,
AnalyzerManager analyzerManager,
Action<Diagnostic> addExceptionDiagnostic,
bool reportAnalyzer,
out Compilation newCompilation,
CancellationToken cancellationToken)
{
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException =
(ex, analyzer, diagnostic) => addExceptionDiagnostic?.Invoke(diagnostic);
return CreateAndAttachToCompilation(compilation, analyzers, options, analyzerManager, onAnalyzerException, reportAnalyzer, out newCompilation, cancellationToken: cancellationToken);
}
示例9: GetAnalyzerActionsAsync
private static async Task<AnalyzerActions> GetAnalyzerActionsAsync(
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerManager analyzerManager,
AnalyzerExecutor analyzerExecutor)
{
var allAnalyzerActions = new AnalyzerActions();
foreach (var analyzer in analyzers)
{
Debug.Assert(!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor));
var analyzerActions = await analyzerManager.GetAnalyzerActionsAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
if (analyzerActions != null)
{
allAnalyzerActions = allAnalyzerActions.Append(analyzerActions);
}
}
return allAnalyzerActions;
}
示例10: GetUnsuppressedAnalyzers
private static ImmutableArray<DiagnosticAnalyzer> GetUnsuppressedAnalyzers(
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerManager analyzerManager,
AnalyzerExecutor analyzerExecutor)
{
var builder = ImmutableArray.CreateBuilder<DiagnosticAnalyzer>();
foreach (var analyzer in analyzers)
{
if (!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor))
{
builder.Add(analyzer);
}
}
return builder.ToImmutable();
}
示例11: WorkspaceAnalyzersAndStates
public WorkspaceAnalyzersAndStates(AnalyzerManager analyzerManager)
{
_analyzerManager = analyzerManager;
_perLanguageAnalyzersAndStatesMap = ImmutableDictionary<string, PerLanguageAnalyzersAndStates>.Empty;
}
示例12: AnalyzerDriver
/// <summary>
/// Create an analyzer driver.
/// </summary>
/// <param name="analyzers">The set of analyzers to include in the analysis</param>
/// <param name="analyzerManager">AnalyzerManager to manage analyzers for analyzer host's lifetime.</param>
/// <param name="cancellationToken">a cancellation token that can be used to abort analysis</param>
protected AnalyzerDriver(ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerManager analyzerManager, CancellationToken cancellationToken)
{
_analyzers = analyzers;
this.analyzerManager = analyzerManager;
this.CompilationEventQueue = new AsyncQueue<CompilationEvent>();
this.DiagnosticQueue = new AsyncQueue<Diagnostic>();
_queueRegistration = cancellationToken.Register(() =>
{
this.CompilationEventQueue.TryComplete();
this.DiagnosticQueue.TryComplete();
});
}
示例13: Create
// internal for testing purposes
internal static AnalyzerDriver Create(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions options,
AnalyzerManager analyzerManager,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
out Compilation newCompilation,
CancellationToken cancellationToken)
{
options = options ?? AnalyzerOptions.Empty;
AnalyzerDriver analyzerDriver = compilation.AnalyzerForLanguage(analyzers, analyzerManager, cancellationToken);
newCompilation = compilation.WithEventQueue(analyzerDriver.CompilationEventQueue);
var addDiagnostic = GetDiagnosticSinkWithSuppression(analyzerDriver.DiagnosticQueue.Enqueue, newCompilation);
Action<Exception, DiagnosticAnalyzer, Diagnostic> newOnAnalyzerException;
if (onAnalyzerException != null)
{
// Wrap onAnalyzerException to pass in filtered diagnostic.
var comp = newCompilation;
newOnAnalyzerException = (ex, analyzer, diagnostic) =>
onAnalyzerException(ex, analyzer, GetFilteredDiagnostic(diagnostic, comp));
}
else
{
// Add exception diagnostic to regular diagnostic bag.
newOnAnalyzerException = (ex, analyzer, diagnostic) => addDiagnostic(diagnostic);
}
// Assume all analyzers are non-thread safe.
var singleThreadedAnalyzerToGateMap = ImmutableDictionary.CreateRange(analyzers.Select(a => KeyValuePair.Create(a, new object())));
var analyzerExecutor = AnalyzerExecutor.Create(newCompilation, options, addDiagnostic, newOnAnalyzerException, IsCompilerAnalyzer, analyzerManager, singleThreadedAnalyzerToGateMap, cancellationToken);
analyzerDriver.Initialize(newCompilation, analyzerExecutor, cancellationToken);
return analyzerDriver;
}
示例14: AnalyzerForLanguage
internal override AnalyzerDriver AnalyzerForLanguage(ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerManager analyzerManager)
{
throw new NotImplementedException();
}
示例15: GetGeneratedCodeAnalysisFlagsAsync
private static async Task<ImmutableDictionary<DiagnosticAnalyzer, GeneratedCodeAnalysisFlags>> GetGeneratedCodeAnalysisFlagsAsync(
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerManager analyzerManager,
AnalyzerExecutor analyzerExecutor)
{
var builder = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, GeneratedCodeAnalysisFlags>();
foreach (var analyzer in analyzers)
{
Debug.Assert(!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor));
var generatedCodeAnalysisFlags = await analyzerManager.GetGeneratedCodeAnalysisFlagsAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
builder.Add(analyzer, generatedCodeAnalysisFlags);
}
return builder.ToImmutable();
}