提交 37876752 编写于 作者: C Cyrus Najmabadi

Move diagnostic analyzer down.

上级 2d2995e4
......@@ -1917,15 +1917,6 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to JSON issue: {0}.
/// </summary>
internal static string JSON_issue_0 {
get {
return ResourceManager.GetString("JSON_issue_0", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Keywords.
/// </summary>
......
......@@ -1340,9 +1340,6 @@ This version used in: {2}</value>
<data name="Probable_JSON_string_detected" xml:space="preserve">
<value>Probable JSON string detected</value>
</data>
<data name="JSON_issue_0" xml:space="preserve">
<value>JSON issue: {0}</value>
</data>
<data name="Alias_ambiguous_type_0" xml:space="preserve">
<value>Alias ambiguous type '{0}'</value>
</data>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.EmbeddedLanguages.Json;
using Microsoft.CodeAnalysis.EmbeddedLanguages.LanguageServices;
using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis.ValidateJsonString
{
internal abstract class AbstractValidateEmbeddedLanguageDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
{
private readonly ImmutableArray<IEmbeddedDiagnosticAnalyzer> _analyzers;
protected AbstractValidateEmbeddedLanguageDiagnosticAnalyzer(
IEmbeddedLanguageProvider embeddedLanguageProvider)
{
var supportedDiagnostics = ArrayBuilder<DiagnosticDescriptor>.GetInstance();
var analyzers = ArrayBuilder<IEmbeddedDiagnosticAnalyzer>.GetInstance();
foreach (var language in embeddedLanguageProvider.GetEmbeddedLanguages())
{
var analyzer = language.GetDiagnosticAnalyzer(DiagnosticCategory.Style);
if (analyzer != null)
{
analyzers.Add(analyzer);
supportedDiagnostics.AddRange(analyzer.SupportedDiagnostics);
}
}
_analyzers = analyzers.ToImmutableAndFree();
this.SupportedDiagnostics = supportedDiagnostics.ToImmutableAndFree();
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
public DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticSpanAnalysis;
public bool OpenFileOnly(Workspace workspace)
=> false;
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterSemanticModelAction(AnalyzeSemanticModel);
}
private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
{
var cancellationToken = context.CancellationToken;
var options = context.Options;
var optionSet = options.GetDocumentOptionSetAsync(
context.SemanticModel.SyntaxTree, cancellationToken).GetAwaiter().GetResult();
if (optionSet == null)
{
return;
}
foreach (var analyzer in _analyzers)
{
analyzer.Analyze(context, optionSet);
}
}
}
}
......@@ -1990,11 +1990,6 @@ Tato verze se používá zde: {2}.</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Diese Version wird verwendet in: {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Esta versión se utiliza en: {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Version utilisée dans : {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Questa versione è usata {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ This version used in: {2}</source>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ This version used in: {2}</source>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Ta wersja jest używana wersja: {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Essa versão é usada no: {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ This version used in: {2}</source>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ Bu sürüm şurada kullanılır: {2}</target>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ This version used in: {2}</source>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -1990,11 +1990,6 @@ This version used in: {2}</source>
<target state="new">Probable JSON string detected</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
<trans-unit id="Enable_JSON_editor_features">
<source>Enable JSON editor features</source>
<target state="new">Enable JSON editor features</target>
......
......@@ -13,7 +13,8 @@ internal class CSharpEmbeddedLanguageProvider : AbstractEmbeddedLanguageProvider
public static IEmbeddedLanguageProvider Instance = new CSharpEmbeddedLanguageProvider();
private CSharpEmbeddedLanguageProvider()
: base(CSharpSyntaxFactsService.Instance,
: base((int)SyntaxKind.StringLiteralToken,
CSharpSyntaxFactsService.Instance,
CSharpSemanticFactsService.Instance,
CSharpVirtualCharService.Instance)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.EmbeddedLanguages.Json;
using Microsoft.CodeAnalysis.EmbeddedLanguages.LanguageServices;
using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.ValidateJsonString
namespace Microsoft.CodeAnalysis.EmbeddedLanguages.Json.LanguageServices
{
internal abstract class AbstractValidateJsonStringDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class JsonDiagnosticAnalyzer : IEmbeddedDiagnosticAnalyzer
{
private readonly int _stringLiteralKind;
private readonly ISyntaxFactsService _syntaxFacts;
private readonly ISemanticFactsService _semanticFacts;
private readonly IVirtualCharService _virtualCharService;
protected AbstractValidateJsonStringDiagnosticAnalyzer(
private readonly DiagnosticDescriptor _descriptor;
public JsonDiagnosticAnalyzer(
string style,
int stringLiteralKind,
ISyntaxFactsService syntaxFacts,
ISemanticFactsService semanticFacts,
IVirtualCharService virtualCharService)
: base(IDEDiagnosticIds.JsonPatternDiagnosticId,
new LocalizableResourceString(nameof(FeaturesResources.JSON_issue_0), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
_stringLiteralKind = stringLiteralKind;
_syntaxFacts = syntaxFacts;
_semanticFacts = semanticFacts;
_virtualCharService = virtualCharService;
}
public override DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticSpanAnalysis;
_descriptor = new DiagnosticDescriptor("IDE0047",
new LocalizableResourceString(nameof(WorkspacesResources.JSON_issue_0), WorkspacesResources.ResourceManager, typeof(WorkspacesResources)),
new LocalizableResourceString(nameof(WorkspacesResources.JSON_issue_0), WorkspacesResources.ResourceManager, typeof(WorkspacesResources)),
style,
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
public override bool OpenFileOnly(Workspace workspace)
=> false;
SupportedDiagnostics = ImmutableArray.Create(_descriptor);
}
protected override void InitializeWorker(AnalysisContext context)
=> context.RegisterSemanticModelAction(AnalyzeSemanticModel);
public ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
public void Analyze(SemanticModelAnalysisContext context, OptionSet optionSet)
{
var semanticModel = context.SemanticModel;
var syntaxTree = semanticModel.SyntaxTree;
var cancellationToken = context.CancellationToken;
var options = context.Options;
var optionSet = options.GetDocumentOptionSetAsync(syntaxTree, cancellationToken).GetAwaiter().GetResult();
if (optionSet == null)
{
return;
}
var option = optionSet.GetOption(JsonOptions.ReportInvalidJsonPatterns, syntaxTree.Options.Language);
if (!option)
......@@ -61,7 +60,7 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
semanticModel, _syntaxFacts, _semanticFacts, _virtualCharService);
var root = syntaxTree.GetRoot(cancellationToken);
Analyze(context, detector,root, cancellationToken);
Analyze(context, detector, root, cancellationToken);
}
private void Analyze(
......@@ -88,7 +87,7 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
foreach (var diag in tree.Diagnostics)
{
context.ReportDiagnostic(Diagnostic.Create(
this.GetDescriptorWithSeverity(DiagnosticSeverity.Warning),
_descriptor,
Location.Create(context.SemanticModel.SyntaxTree, diag.Span),
diag.Message));
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.EmbeddedLanguages.LanguageServices;
using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars;
using Microsoft.CodeAnalysis.LanguageServices;
......@@ -10,15 +9,30 @@ namespace Microsoft.CodeAnalysis.EmbeddedLanguages.Json.LanguageServices
internal class JsonEmbeddedLanguage : IEmbeddedLanguage
{
private readonly JsonEmbeddedClassifier _classifier;
private readonly int _stringLiteralKind;
private readonly ISyntaxFactsService _syntaxFacts;
private readonly ISemanticFactsService _semanticFacts;
private readonly IVirtualCharService _virtualCharService;
public JsonEmbeddedLanguage(
ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, IVirtualCharService virtualCharService)
int stringLiteralKind,
ISyntaxFactsService syntaxFacts,
ISemanticFactsService semanticFacts,
IVirtualCharService virtualCharService)
{
_stringLiteralKind = stringLiteralKind;
_syntaxFacts = syntaxFacts;
_semanticFacts = semanticFacts;
_virtualCharService = virtualCharService;
_classifier = new JsonEmbeddedClassifier(syntaxFacts, semanticFacts, virtualCharService);
}
public IEmbeddedBraceMatcher BraceMatcher => JsonEmbeddedBraceMatcher.Instance;
public IEmbeddedClassifier Classifier => _classifier;
public IEmbeddedDiagnosticAnalyzer GetDiagnosticAnalyzer(string style)
=> new JsonDiagnosticAnalyzer(style, _stringLiteralKind, _syntaxFacts, _semanticFacts, _virtualCharService);
}
}
......@@ -7,17 +7,18 @@
namespace Microsoft.CodeAnalysis.EmbeddedLanguages.LanguageServices
{
internal class AbstractEmbeddedLanguageProvider : IEmbeddedLanguageProvider
internal abstract class AbstractEmbeddedLanguageProvider : IEmbeddedLanguageProvider
{
private readonly ImmutableArray<IEmbeddedLanguage> _embeddedLanguages;
protected AbstractEmbeddedLanguageProvider(
int stringLiteralKind,
ISyntaxFactsService syntaxFacts,
ISemanticFactsService semanticFacts,
IVirtualCharService virtualCharService)
{
_embeddedLanguages = ImmutableArray.Create<IEmbeddedLanguage>(
new JsonEmbeddedLanguage(syntaxFacts, semanticFacts, virtualCharService));
new JsonEmbeddedLanguage(stringLiteralKind, syntaxFacts, semanticFacts, virtualCharService));
}
public ImmutableArray<IEmbeddedLanguage> GetEmbeddedLanguages()
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.EmbeddedLanguages.LanguageServices
{
internal interface IEmbeddedDiagnosticAnalyzer
{
ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
void Analyze(SemanticModelAnalysisContext context, OptionSet options);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.EmbeddedLanguages.LanguageServices
{
internal interface IEmbeddedLanguage
{
IEmbeddedBraceMatcher BraceMatcher { get; }
IEmbeddedClassifier Classifier { get; }
IEmbeddedDiagnosticAnalyzer GetDiagnosticAnalyzer(string style);
}
}
......@@ -1034,6 +1034,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to JSON issue: {0}.
/// </summary>
internal static string JSON_issue_0 {
get {
return ResourceManager.GetString("JSON_issue_0", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Label for node &apos;{0}&apos; is invalid, it must be within [0, {1})..
/// </summary>
......
......@@ -781,4 +781,7 @@
<data name="_0_literal_not_allowed" xml:space="preserve">
<value>'{0}' literal not allowed</value>
</data>
<data name="JSON_issue_0" xml:space="preserve">
<value>JSON issue: {0}</value>
</data>
</root>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -1077,6 +1077,11 @@
<target state="new">Variables captured:</target>
<note />
</trans-unit>
<trans-unit id="JSON_issue_0">
<source>JSON issue: {0}</source>
<target state="new">JSON issue: {0}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -13,7 +13,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EmbeddedLanguages.LanguageServices
Public Shared Instance As New VisualBasicEmbeddedLanguageProvider()
Private Sub New()
MyBase.New(VisualBasicSyntaxFactsService.Instance,
MyBase.New(SyntaxKind.StringLiteralToken,
VisualBasicSyntaxFactsService.Instance,
VisualBasicSemanticFactsService.Instance,
VisualBasicVirtualCharService.Instance)
End Sub
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册