提交 fa8f20c7 编写于 作者: H Heejae Chang

PR. Feedback

some code clean up - rename and such
上级 12a83529
...@@ -114,7 +114,7 @@ private void ClearAnalyzerDiagnostics(DiagnosticAnalyzer analyzer, ProjectId pro ...@@ -114,7 +114,7 @@ private void ClearAnalyzerDiagnostics(DiagnosticAnalyzer analyzer, ProjectId pro
private DiagnosticsUpdatedArgs MakeArgs(DiagnosticAnalyzer analyzer, ImmutableHashSet<DiagnosticData> items, Project project) private DiagnosticsUpdatedArgs MakeArgs(DiagnosticAnalyzer analyzer, ImmutableHashSet<DiagnosticData> items, Project project)
{ {
var id = analyzer.GetUniqueIdForAnalyzer(); var id = analyzer.GetUniqueId();
return new DiagnosticsUpdatedArgs( return new DiagnosticsUpdatedArgs(
id: Tuple.Create(this, id, project?.Id), id: Tuple.Create(this, id, project?.Id),
......
...@@ -36,12 +36,12 @@ public static bool IsCompilerAnalyzer(this DiagnosticAnalyzer analyzer) ...@@ -36,12 +36,12 @@ public static bool IsCompilerAnalyzer(this DiagnosticAnalyzer analyzer)
return false; return false;
} }
public static ValueTuple<string, VersionStamp> GetUniqueIdForAnalyzer(this DiagnosticAnalyzer analyzer) public static ValueTuple<string, VersionStamp> GetUniqueId(this DiagnosticAnalyzer analyzer)
{ {
// Get the unique ID for given diagnostic analyzer. // Get the unique ID for given diagnostic analyzer.
// note that we also put version stamp so that we can detect changed analyzer. // note that we also put version stamp so that we can detect changed analyzer.
var type = analyzer.GetType(); var type = analyzer.GetType();
return ValueTuple.Create(type.AssemblyQualifiedName, GetProviderVersion(type.Assembly.Location)); return ValueTuple.Create(type.AssemblyQualifiedName, GetAnalyzerVersion(type.Assembly.Location));
} }
public static Action<Diagnostic> GetAddExceptionDiagnosticDelegate(this DiagnosticAnalyzer analyzer, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource, Project project) public static Action<Diagnostic> GetAddExceptionDiagnosticDelegate(this DiagnosticAnalyzer analyzer, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource, Project project)
...@@ -83,7 +83,7 @@ public static Action<Diagnostic> GetAddExceptionDiagnosticDelegate(this Diagnost ...@@ -83,7 +83,7 @@ public static Action<Diagnostic> GetAddExceptionDiagnosticDelegate(this Diagnost
return AnalyzerExecutor.Create(compilation, analyzerOptions, addDiagnostic, addExceptionDiagnostic, continueOnAnalyzerException, cancellationToken); return AnalyzerExecutor.Create(compilation, analyzerOptions, addDiagnostic, addExceptionDiagnostic, continueOnAnalyzerException, cancellationToken);
} }
private static VersionStamp GetProviderVersion(string path) private static VersionStamp GetAnalyzerVersion(string path)
{ {
if (path == null || !File.Exists(path)) if (path == null || !File.Exists(path))
{ {
......
...@@ -218,9 +218,9 @@ private static DiagnosticState[] CreateDiagnosticStates(string language, Diagnos ...@@ -218,9 +218,9 @@ private static DiagnosticState[] CreateDiagnosticStates(string language, Diagnos
} }
/// <summary> /// <summary>
/// Get the unique state name for the given {type, provider} tuple. /// Get the unique state name for the given {type, analyzer} tuple.
/// Note that this name is used by the underlying persistence stream of the corresponding <see cref="DiagnosticState"/> to Read/Write diagnostic data into the stream. /// Note that this name is used by the underlying persistence stream of the corresponding <see cref="DiagnosticState"/> to Read/Write diagnostic data into the stream.
/// If any two distinct {type, provider} tuples have the same diagnostic state name, we will end up sharing the persistence stream between them, leading to duplicate/missing/incorrect diagnostic data. /// If any two distinct {type, analyzer} tuples have the same diagnostic state name, we will end up sharing the persistence stream between them, leading to duplicate/missing/incorrect diagnostic data.
/// </summary> /// </summary>
private static ValueTuple<string, VersionStamp> GetNameAndVersion(DiagnosticAnalyzer analyzer, StateType type) private static ValueTuple<string, VersionStamp> GetNameAndVersion(DiagnosticAnalyzer analyzer, StateType type)
{ {
...@@ -228,7 +228,7 @@ private static DiagnosticState[] CreateDiagnosticStates(string language, Diagnos ...@@ -228,7 +228,7 @@ private static DiagnosticState[] CreateDiagnosticStates(string language, Diagnos
// Get the unique ID for given diagnostic analyzer. // Get the unique ID for given diagnostic analyzer.
// note that we also put version stamp so that we can detect changed analyzer. // note that we also put version stamp so that we can detect changed analyzer.
var tuple = analyzer.GetUniqueIdForAnalyzer(); var tuple = analyzer.GetUniqueId();
return ValueTuple.Create(UserDiagnosticsPrefixTableName + "_" + type.ToString() + "_" + tuple.Item1, tuple.Item2); return ValueTuple.Create(UserDiagnosticsPrefixTableName + "_" + type.ToString() + "_" + tuple.Item1, tuple.Item2);
} }
} }
......
...@@ -72,7 +72,7 @@ public override Task DocumentOpenAsync(Document document, CancellationToken canc ...@@ -72,7 +72,7 @@ public override Task DocumentOpenAsync(Document document, CancellationToken canc
using (Logger.LogBlock(FunctionId.Diagnostics_DocumentOpen, GetOpenLogMessage, document, cancellationToken)) using (Logger.LogBlock(FunctionId.Diagnostics_DocumentOpen, GetOpenLogMessage, document, cancellationToken))
{ {
// we remove whatever information we used to have on document open/close and re-calcuate diagnostics // we remove whatever information we used to have on document open/close and re-calcuate diagnostics
// we had to do this since some diagnostic provider change its behavior based on whether the document is opend or not. // we had to do this since some diagnostic analyzer change its behavior based on whether the document is opend or not.
// so we can't use cached information. // so we can't use cached information.
return ClearDocumentStatesAsync(document, _stateManger.GetStateSets(document.Project), cancellationToken); return ClearDocumentStatesAsync(document, _stateManger.GetStateSets(document.Project), cancellationToken);
} }
...@@ -86,7 +86,7 @@ public override Task DocumentResetAsync(Document document, CancellationToken can ...@@ -86,7 +86,7 @@ public override Task DocumentResetAsync(Document document, CancellationToken can
_memberRangeMap.Remove(document.Id); _memberRangeMap.Remove(document.Id);
// we remove whatever information we used to have on document open/close and re-calcuate diagnostics // we remove whatever information we used to have on document open/close and re-calcuate diagnostics
// we had to do this since some diagnostic provider change its behavior based on whether the document is opend or not. // we had to do this since some diagnostic analyzer change its behavior based on whether the document is opend or not.
// so we can't use cached information. // so we can't use cached information.
return ClearDocumentStatesAsync(document, _stateManger.GetStateSets(document.Project), cancellationToken); return ClearDocumentStatesAsync(document, _stateManger.GetStateSets(document.Project), cancellationToken);
} }
...@@ -138,8 +138,8 @@ private async Task AnalyzeSyntaxAsync(Document document, ImmutableHashSet<string ...@@ -138,8 +138,8 @@ private async Task AnalyzeSyntaxAsync(Document document, ImmutableHashSet<string
{ {
await HandleSuppressedAnalyzerAsync(document, stateSet, StateType.Syntax, cancellationToken).ConfigureAwait(false); await HandleSuppressedAnalyzerAsync(document, stateSet, StateType.Syntax, cancellationToken).ConfigureAwait(false);
} }
else if (ShouldRunProviderForStateType(userDiagnosticDriver, stateSet.Analyzer, StateType.Syntax, diagnosticIds) && else if (ShouldRunAnalyzerForStateType(userDiagnosticDriver, stateSet.Analyzer, StateType.Syntax, diagnosticIds) &&
(skipClosedFileChecks || ShouldRunProviderForClosedFile(openedDocument, stateSet.Analyzer))) (skipClosedFileChecks || ShouldRunAnalyzerForClosedFile(openedDocument, stateSet.Analyzer)))
{ {
var data = await _executor.GetSyntaxAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false); var data = await _executor.GetSyntaxAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false);
if (data.FromCache) if (data.FromCache)
...@@ -215,7 +215,7 @@ private async Task AnalyzeBodyDocumentAsync(Document document, SyntaxNode member ...@@ -215,7 +215,7 @@ private async Task AnalyzeBodyDocumentAsync(Document document, SyntaxNode member
{ {
await HandleSuppressedAnalyzerAsync(document, stateSet, StateType.Document, cancellationToken).ConfigureAwait(false); await HandleSuppressedAnalyzerAsync(document, stateSet, StateType.Document, cancellationToken).ConfigureAwait(false);
} }
else if (ShouldRunProviderForStateType(spanBasedDriver, stateSet.Analyzer, StateType.Document, out supportsSemanticInSpan)) else if (ShouldRunAnalyzerForStateType(spanBasedDriver, stateSet.Analyzer, StateType.Document, out supportsSemanticInSpan))
{ {
var userDiagnosticDriver = supportsSemanticInSpan ? spanBasedDriver : documentBasedDriver; var userDiagnosticDriver = supportsSemanticInSpan ? spanBasedDriver : documentBasedDriver;
...@@ -260,8 +260,8 @@ private async Task AnalyzeDocumentAsync(Document document, VersionArgument versi ...@@ -260,8 +260,8 @@ private async Task AnalyzeDocumentAsync(Document document, VersionArgument versi
{ {
await HandleSuppressedAnalyzerAsync(document, stateSet, StateType.Document, cancellationToken).ConfigureAwait(false); await HandleSuppressedAnalyzerAsync(document, stateSet, StateType.Document, cancellationToken).ConfigureAwait(false);
} }
else if (ShouldRunProviderForStateType(userDiagnosticDriver, stateSet.Analyzer, StateType.Document, diagnosticIds) && else if (ShouldRunAnalyzerForStateType(userDiagnosticDriver, stateSet.Analyzer, StateType.Document, diagnosticIds) &&
(skipClosedFileChecks || ShouldRunProviderForClosedFile(openedDocument, stateSet.Analyzer))) (skipClosedFileChecks || ShouldRunAnalyzerForClosedFile(openedDocument, stateSet.Analyzer)))
{ {
var data = await _executor.GetDocumentAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false); var data = await _executor.GetDocumentAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false);
if (data.FromCache) if (data.FromCache)
...@@ -313,8 +313,8 @@ private async Task AnalyzeProjectAsync(Project project, ImmutableHashSet<string> ...@@ -313,8 +313,8 @@ private async Task AnalyzeProjectAsync(Project project, ImmutableHashSet<string>
{ {
await HandleSuppressedAnalyzerAsync(project, stateSet, cancellationToken).ConfigureAwait(false); await HandleSuppressedAnalyzerAsync(project, stateSet, cancellationToken).ConfigureAwait(false);
} }
else if (ShouldRunProviderForStateType(userDiagnosticDriver, stateSet.Analyzer, StateType.Project, diagnosticIds) && else if (ShouldRunAnalyzerForStateType(userDiagnosticDriver, stateSet.Analyzer, StateType.Project, diagnosticIds) &&
(skipClosedFileChecks || ShouldRunProviderForClosedFile(openedDocument: false, analyzer: stateSet.Analyzer))) (skipClosedFileChecks || ShouldRunAnalyzerForClosedFile(openedDocument: false, analyzer: stateSet.Analyzer)))
{ {
var data = await _executor.GetProjectAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false); var data = await _executor.GetProjectAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false);
if (data.FromCache) if (data.FromCache)
...@@ -459,7 +459,7 @@ public override async Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsy ...@@ -459,7 +459,7 @@ public override async Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsy
{ {
bool supportsSemanticInSpan; bool supportsSemanticInSpan;
if (!spanBasedDriver.IsAnalyzerSuppressed(stateSet.Analyzer) && if (!spanBasedDriver.IsAnalyzerSuppressed(stateSet.Analyzer) &&
ShouldRunProviderForStateType(spanBasedDriver, stateSet.Analyzer, stateType, out supportsSemanticInSpan)) ShouldRunAnalyzerForStateType(spanBasedDriver, stateSet.Analyzer, stateType, out supportsSemanticInSpan))
{ {
var userDiagnosticDriver = supportsSemanticInSpan ? spanBasedDriver : documentBasedDriver; var userDiagnosticDriver = supportsSemanticInSpan ? spanBasedDriver : documentBasedDriver;
...@@ -528,7 +528,7 @@ public override async Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsy ...@@ -528,7 +528,7 @@ public override async Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsy
} }
} }
private bool ShouldRunProviderForClosedFile(bool openedDocument, DiagnosticAnalyzer analyzer) private bool ShouldRunAnalyzerForClosedFile(bool openedDocument, DiagnosticAnalyzer analyzer)
{ {
// we have opened document, doesnt matter // we have opened document, doesnt matter
if (openedDocument) if (openedDocument)
...@@ -539,20 +539,20 @@ private bool ShouldRunProviderForClosedFile(bool openedDocument, DiagnosticAnaly ...@@ -539,20 +539,20 @@ private bool ShouldRunProviderForClosedFile(bool openedDocument, DiagnosticAnaly
return _owner.GetDiagnosticDescriptors(analyzer).Any(d => d.DefaultSeverity != DiagnosticSeverity.Hidden); return _owner.GetDiagnosticDescriptors(analyzer).Any(d => d.DefaultSeverity != DiagnosticSeverity.Hidden);
} }
private bool ShouldRunProviderForStateType(DiagnosticAnalyzerDriver driver, DiagnosticAnalyzer provider, private bool ShouldRunAnalyzerForStateType(DiagnosticAnalyzerDriver driver, DiagnosticAnalyzer analyzer,
StateType stateTypeId, ImmutableHashSet<string> diagnosticIds) StateType stateTypeId, ImmutableHashSet<string> diagnosticIds)
{ {
bool discarded; bool discarded;
return ShouldRunProviderForStateType(driver, provider, stateTypeId, out discarded, diagnosticIds, _owner.GetDiagnosticDescriptors); return ShouldRunAnalyzerForStateType(driver, analyzer, stateTypeId, out discarded, diagnosticIds, _owner.GetDiagnosticDescriptors);
} }
private static bool ShouldRunProviderForStateType(DiagnosticAnalyzerDriver driver, DiagnosticAnalyzer provider, StateType stateTypeId, private static bool ShouldRunAnalyzerForStateType(DiagnosticAnalyzerDriver driver, DiagnosticAnalyzer analyzer, StateType stateTypeId,
out bool supportsSemanticInSpan, ImmutableHashSet<string> diagnosticIds = null, Func<DiagnosticAnalyzer, ImmutableArray<DiagnosticDescriptor>> getDescriptor = null) out bool supportsSemanticInSpan, ImmutableHashSet<string> diagnosticIds = null, Func<DiagnosticAnalyzer, ImmutableArray<DiagnosticDescriptor>> getDescriptor = null)
{ {
Debug.Assert(!driver.IsAnalyzerSuppressed(provider)); Debug.Assert(!driver.IsAnalyzerSuppressed(analyzer));
supportsSemanticInSpan = false; supportsSemanticInSpan = false;
if (diagnosticIds != null && getDescriptor(provider).All(d => !diagnosticIds.Contains(d.Id))) if (diagnosticIds != null && getDescriptor(analyzer).All(d => !diagnosticIds.Contains(d.Id)))
{ {
return false; return false;
} }
...@@ -560,13 +560,13 @@ private bool ShouldRunProviderForClosedFile(bool openedDocument, DiagnosticAnaly ...@@ -560,13 +560,13 @@ private bool ShouldRunProviderForClosedFile(bool openedDocument, DiagnosticAnaly
switch (stateTypeId) switch (stateTypeId)
{ {
case StateType.Syntax: case StateType.Syntax:
return provider.SupportsSyntaxDiagnosticAnalysis(driver); return analyzer.SupportsSyntaxDiagnosticAnalysis(driver);
case StateType.Document: case StateType.Document:
return provider.SupportsSemanticDiagnosticAnalysis(driver, out supportsSemanticInSpan); return analyzer.SupportsSemanticDiagnosticAnalysis(driver, out supportsSemanticInSpan);
case StateType.Project: case StateType.Project:
return provider.SupportsProjectDiagnosticAnalysis(driver); return analyzer.SupportsProjectDiagnosticAnalysis(driver);
default: default:
throw ExceptionUtilities.Unreachable; throw ExceptionUtilities.Unreachable;
......
...@@ -318,7 +318,7 @@ protected override async Task AppendDiagnosticsFromKeyAsync(Project project, Sta ...@@ -318,7 +318,7 @@ protected override async Task AppendDiagnosticsFromKeyAsync(Project project, Sta
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (driver.IsAnalyzerSuppressed(stateSet.Analyzer) || if (driver.IsAnalyzerSuppressed(stateSet.Analyzer) ||
!this.Owner.ShouldRunProviderForStateType(driver, stateSet.Analyzer, stateType, this.DiagnosticIds)) !this.Owner.ShouldRunAnalyzerForStateType(driver, stateSet.Analyzer, stateType, this.DiagnosticIds))
{ {
continue; continue;
} }
......
...@@ -53,7 +53,7 @@ public void Touch(DiagnosticAnalyzer analyzer, Document document, VersionStamp v ...@@ -53,7 +53,7 @@ public void Touch(DiagnosticAnalyzer analyzer, Document document, VersionStamp v
// now update member range map // now update member range map
UpdateMemberRange_NoLock(data, document, newVersion, memberId, span, oldRanges.TextVersion); UpdateMemberRange_NoLock(data, document, newVersion, memberId, span, oldRanges.TextVersion);
// save provider version information // save analyzer version information
Touch_NoLock(data, analyzer, document, newVersion); Touch_NoLock(data, analyzer, document, newVersion);
ValidateMemberRangeMap(document, newVersion); ValidateMemberRangeMap(document, newVersion);
...@@ -188,7 +188,7 @@ private MemberRanges GetSavedMemberRange_NoLock(DictionaryData data, DiagnosticA ...@@ -188,7 +188,7 @@ private MemberRanges GetSavedMemberRange_NoLock(DictionaryData data, DiagnosticA
ImmutableArray<TextSpan> range; ImmutableArray<TextSpan> range;
if (!data.VersionMap.TryGetValue(analyzer, out version)) if (!data.VersionMap.TryGetValue(analyzer, out version))
{ {
// it is first time for this provider // it is first time for this analyzer
Contract.ThrowIfFalse(document.TryGetSyntaxRoot(out root)); Contract.ThrowIfFalse(document.TryGetSyntaxRoot(out root));
Contract.ThrowIfFalse(document.TryGetTextVersion(out version)); Contract.ThrowIfFalse(document.TryGetTextVersion(out version));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册