本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerDriver类的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticAnalyzerDriver类的具体用法?C# DiagnosticAnalyzerDriver怎么用?C# DiagnosticAnalyzerDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiagnosticAnalyzerDriver类属于Microsoft.CodeAnalysis.Diagnostics.EngineV1命名空间,在下文中一共展示了DiagnosticAnalyzerDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDocumentBodyAnalysisDataAsync
public async Task<AnalysisData> GetDocumentBodyAnalysisDataAsync(
StateSet stateSet, VersionArgument versions, DiagnosticAnalyzerDriver analyzerDriver,
SyntaxNode root, SyntaxNode member, int memberId, bool supportsSemanticInSpan, MemberRangeMap.MemberRanges ranges)
{
try
{
var document = analyzerDriver.Document;
var cancellationToken = analyzerDriver.CancellationToken;
var state = stateSet.GetState(StateType.Document);
var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
ImmutableArray<DiagnosticData> diagnosticData;
if (supportsSemanticInSpan && CanUseRange(memberId, ranges.Ranges) && CanUseDocumentState(existingData, ranges.TextVersion, versions.DataVersion))
{
var memberDxData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
diagnosticData = _owner.UpdateDocumentDiagnostics(existingData, ranges.Ranges, memberDxData.AsImmutableOrEmpty(), root.SyntaxTree, member, memberId);
ValidateMemberDiagnostics(stateSet.Analyzer, document, root, diagnosticData);
}
else
{
// if we can't re-use existing document state, only option we have is updating whole document state here.
var dx = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
diagnosticData = dx.AsImmutableOrEmpty();
}
return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
示例2: LatestDiagnosticsForSpanGetter
public LatestDiagnosticsForSpanGetter(
DiagnosticIncrementalAnalyzer owner, Document document, SyntaxNode root, TextSpan range, bool blockForData, List<DiagnosticData> diagnostics, CancellationToken cancellationToken)
{
_owner = owner;
_document = document;
_range = range;
_blockForData = blockForData;
_cancellationToken = cancellationToken;
Diagnostics = diagnostics;
// Share the diagnostic analyzer driver across all analyzers.
var fullSpan = root?.FullSpan;
_spanBasedDriver = new DiagnosticAnalyzerDriver(_document, _range, root, _owner, _cancellationToken);
_documentBasedDriver = new DiagnosticAnalyzerDriver(_document, fullSpan, root, _owner, _cancellationToken);
_projectDriver = new DiagnosticAnalyzerDriver(_document.Project, _owner, _cancellationToken);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:19,代码来源:DiagnosticIncrementalAnalyzer_GetLatestDiagnosticsForSpan.cs
示例3: GetDocumentAnalysisDataAsync
public async Task<AnalysisData> GetDocumentAnalysisDataAsync(DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, VersionArgument versions)
{
try
{
var document = analyzerDriver.Document;
var cancellationToken = analyzerDriver.CancellationToken;
var state = stateSet.GetState(StateType.Document);
var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
if (CheckSemanticVersions(document, existingData, versions))
{
return existingData;
}
var diagnosticData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData.AsImmutableOrEmpty());
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
示例4: GetSyntaxAnalysisDataAsync
public async Task<AnalysisData> GetSyntaxAnalysisDataAsync(
DiagnosticAnalyzer provider, ProviderId providerId, VersionArgument versions, DiagnosticAnalyzerDriver analyzerDriver)
{
try
{
var document = analyzerDriver.Document;
var cancellationToken = analyzerDriver.CancellationToken;
var state = AnalyzersAndState.GetOrCreateDiagnosticState(StateType.Syntax, providerId, provider, document.Project.Id, document.Project.Language);
var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
if (CheckSyntaxVersions(document, existingData, versions))
{
return existingData;
}
var diagnosticData = await GetSyntaxDiagnosticsAsync(providerId, provider, analyzerDriver).ConfigureAwait(false);
return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData.AsImmutableOrEmpty());
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:24,代码来源:DiagnosticIncrementalAnalyzer.IncrementalAnalyzer.AnalyzerExecutor.cs
示例5: GetDiagnosticAnalysisDataAsync
protected abstract Task<AnalysisData> GetDiagnosticAnalysisDataAsync(Solution solution, DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, StateType stateType, VersionArgument versions);
示例6: SkipRunningAnalyzer
private bool SkipRunningAnalyzer(
CompilationOptions compilationOptions,
DiagnosticAnalyzerDriver userDiagnosticDriver,
bool openedDocument,
bool skipClosedFileChecks,
StateSet stateSet)
{
if (Owner.IsAnalyzerSuppressed(stateSet.Analyzer, userDiagnosticDriver.Project))
{
return true;
}
if (skipClosedFileChecks)
{
return false;
}
if (ShouldRunAnalyzerForClosedFile(compilationOptions, openedDocument, stateSet.Analyzer))
{
return false;
}
return true;
}
示例7: AnalyzeDocumentAsync
private async Task AnalyzeDocumentAsync(Document document, VersionArgument versions, ImmutableHashSet<string> diagnosticIds, bool skipClosedFileChecks, CancellationToken cancellationToken)
{
try
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var fullSpan = root == null ? null : (TextSpan?)root.FullSpan;
var userDiagnosticDriver = new DiagnosticAnalyzerDriver(document, fullSpan, root, this, cancellationToken);
bool openedDocument = document.IsOpen();
foreach (var stateSet in _stateManager.GetOrUpdateStateSets(document.Project))
{
if (SkipRunningAnalyzer(document.Project.CompilationOptions, userDiagnosticDriver, openedDocument, skipClosedFileChecks, stateSet))
{
await ClearExistingDiagnostics(document, stateSet, StateType.Document, cancellationToken).ConfigureAwait(false);
continue;
}
if (ShouldRunAnalyzerForStateType(stateSet.Analyzer, StateType.Document, diagnosticIds))
{
var data = await _executor.GetDocumentAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false);
if (data.FromCache)
{
RaiseDiagnosticsUpdated(StateType.Document, document.Id, stateSet, new SolutionArgument(document), data.Items);
continue;
}
if (openedDocument)
{
_memberRangeMap.Touch(stateSet.Analyzer, document, versions.TextVersion);
}
var state = stateSet.GetState(StateType.Document);
await state.PersistAsync(document, data.ToPersistData(), cancellationToken).ConfigureAwait(false);
RaiseDocumentDiagnosticsUpdatedIfNeeded(StateType.Document, document, stateSet, data.OldItems, data.Items);
}
}
_solutionCrawlerAnalysisState.OnDocumentAnalyzed(document);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
示例8: AnalyzeProjectAsync
private async Task AnalyzeProjectAsync(Project project, CancellationToken cancellationToken)
{
try
{
if (!CheckOptions(project, forceAnalysis: false))
{
return;
}
var projectTextVersion = await project.GetLatestDocumentVersionAsync(cancellationToken).ConfigureAwait(false);
var semanticVersion = await project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);
var projectVersion = await project.GetDependentVersionAsync(cancellationToken).ConfigureAwait(false);
var versions = new VersionArgument(projectTextVersion, semanticVersion, projectVersion);
var stateSets = _stateManager.GetOrUpdateStateSets(project);
var analyzers = stateSets.Select(s => s.Analyzer);
var analyzerDriver = new DiagnosticAnalyzerDriver(project, this, analyzers, ConcurrentAnalysis, ReportSuppressedDiagnostics, cancellationToken);
foreach (var stateSet in stateSets)
{
// Compilation actions can report diagnostics on open files, so we skipClosedFileChecks.
if (await SkipRunningAnalyzerAsync(project, stateSet.Analyzer, openedDocument: false, skipClosedFileCheck: true, cancellationToken: cancellationToken).ConfigureAwait(false))
{
await ClearExistingDiagnostics(project, stateSet, cancellationToken).ConfigureAwait(false);
continue;
}
if (ShouldRunAnalyzerForStateType(stateSet.Analyzer, StateType.Project, diagnosticIds: null))
{
var data = await _executor.GetProjectAnalysisDataAsync(analyzerDriver, stateSet, versions).ConfigureAwait(false);
if (data.FromCache)
{
RaiseProjectDiagnosticsUpdatedIfNeeded(project, stateSet, ImmutableArray<DiagnosticData>.Empty, data.Items);
continue;
}
var state = stateSet.GetState(StateType.Project);
await PersistProjectData(project, state, data).ConfigureAwait(false);
RaiseProjectDiagnosticsUpdatedIfNeeded(project, stateSet, data.OldItems, data.Items);
}
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
示例9: TryGetDocumentDiagnosticsAsync
private async Task<bool> TryGetDocumentDiagnosticsAsync(
StateSet stateSet, StateType stateType, bool supportsSemanticInSpan,
Func<VersionStamp, VersionStamp, bool> versionCheck,
Func<DiagnosticAnalyzerDriver, DiagnosticAnalyzer, Task<IEnumerable<DiagnosticData>>> getDiagnostics,
DiagnosticAnalyzerDriver analyzerDriverOpt = null)
{
Func<DiagnosticData, bool> shouldInclude = d =>
d.DocumentId == _document.Id &&
_range.IntersectsWith(d.TextSpan) &&
(_includeSuppressedDiagnostics || !d.IsSuppressed);
// make sure we get state even when none of our analyzer has ran yet.
// but this shouldn't create analyzer that doesn't belong to this project (language)
var state = stateSet.GetState(stateType);
// see whether we can use existing info
var existingData = await state.TryGetExistingDataAsync(_document, _cancellationToken).ConfigureAwait(false);
if (existingData != null && versionCheck(existingData.TextVersion, existingData.DataVersion))
{
if (existingData.Items == null || existingData.Items.Length == 0)
{
return true;
}
Diagnostics.AddRange(existingData.Items.Where(shouldInclude));
return true;
}
// check whether we want up-to-date document wide diagnostics
if (!BlockForData(stateType, supportsSemanticInSpan))
{
return false;
}
var dx = await getDiagnostics(analyzerDriverOpt, stateSet.Analyzer).ConfigureAwait(false);
if (dx != null)
{
// no state yet
Diagnostics.AddRange(dx.Where(shouldInclude));
}
return true;
}
示例10: GetDiagnosticAnalysisDataAsync
protected override async Task<AnalysisData> GetDiagnosticAnalysisDataAsync(
Solution solution, DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, StateType stateType, VersionArgument versions)
{
// we don't care about result
switch (stateType)
{
case StateType.Syntax:
await GetSyntaxDiagnosticsAsync(analyzerDriver, _analyzer).ConfigureAwait(false);
break;
case StateType.Document:
await GetSemanticDiagnosticsAsync(analyzerDriver, _analyzer).ConfigureAwait(false);
break;
case StateType.Project:
default:
return Contract.FailWithReturn<AnalysisData>("Can't reach here");
}
return AnalysisData.Empty;
}
示例11: ValidateMemberDiagnostics
private void ValidateMemberDiagnostics(DiagnosticAnalyzer analyzer, Document document, SyntaxNode root, ImmutableArray<DiagnosticData> diagnostics)
{
#if RANGE
var documentBasedDriver = new DiagnosticAnalyzerDriver(document, root.FullSpan, root, this, CancellationToken.None);
var expected = GetSemanticDiagnosticsAsync(documentBasedDriver, analyzer).WaitAndGetResult(documentBasedDriver.CancellationToken) ?? SpecializedCollections.EmptyEnumerable<DiagnosticData>();
Contract.Requires(diagnostics.SetEquals(expected));
#endif
}
示例12: UpdateAllSemanticDiagnosticsAsync
private static async Task<ImmutableArray<DiagnosticData>> UpdateAllSemanticDiagnosticsAsync(
StateSet stateSet, DiagnosticAnalyzerDriver analyzerDriver, ImmutableArray<DiagnosticData> diagnosticData)
{
var dx = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
diagnosticData = dx.AsImmutableOrEmpty();
return diagnosticData;
}
示例13: GetSpecificDiagnosticsAsync
protected abstract Task<AnalysisData> GetSpecificDiagnosticsAsync(Solution solution, DiagnosticAnalyzer provider, ProviderId providerId, StateType stateType, VersionArgument versions, DiagnosticAnalyzerDriver analyzerDriver);
示例14: ShouldRunAnalyzerForStateTypeAsync
private static async Task<bool> ShouldRunAnalyzerForStateTypeAsync(DiagnosticAnalyzerDriver driver, DiagnosticAnalyzer analyzer, StateType stateTypeId,
ImmutableHashSet<string> diagnosticIds = null, Func<DiagnosticAnalyzer, ImmutableArray<DiagnosticDescriptor>> getDescriptors = null)
{
Debug.Assert(!driver.IsAnalyzerSuppressed(analyzer));
if (diagnosticIds != null && getDescriptors(analyzer).All(d => !diagnosticIds.Contains(d.Id)))
{
return false;
}
switch (stateTypeId)
{
case StateType.Syntax:
return await analyzer.SupportsSyntaxDiagnosticAnalysisAsync(driver).ConfigureAwait(false);
case StateType.Document:
return await analyzer.SupportsSemanticDiagnosticAnalysisAsync(driver).ConfigureAwait(false);
case StateType.Project:
return await analyzer.SupportsProjectDiagnosticAnalysisAsync(driver).ConfigureAwait(false);
default:
throw ExceptionUtilities.Unreachable;
}
}
示例15: IsAnalyzerSuppressed
private static bool IsAnalyzerSuppressed(DiagnosticAnalyzer provider, CompilationOptions options, DiagnosticAnalyzerDriver driver)
{
if (options != null && CompilationWithAnalyzers.IsDiagnosticAnalyzerSuppressed(provider, options, driver.CatchAnalyzerExceptionHandler))
{
// All diagnostics that are generated by this DiagnosticAnalyzer will be suppressed, so we need not run the analyzer.
return true;
}
return false;
}