提交 01810578 编写于 作者: S Sam Harwell

Add annotations for case correction types

上级 f2b0a986
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Composition;
......@@ -19,7 +21,7 @@ public CSharpCaseCorrectionService()
}
protected override void AddReplacements(
SemanticModel semanticModel,
SemanticModel? semanticModel,
SyntaxNode root,
ImmutableArray<TextSpan> spans,
Workspace workspace,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
......@@ -15,7 +17,7 @@ namespace Microsoft.CodeAnalysis.CaseCorrection
{
internal abstract partial class AbstractCaseCorrectionService : ICaseCorrectionService
{
protected abstract void AddReplacements(SemanticModel semanticModel, SyntaxNode root, ImmutableArray<TextSpan> spans, Workspace workspace, ConcurrentDictionary<SyntaxToken, SyntaxToken> replacements, CancellationToken cancellationToken);
protected abstract void AddReplacements(SemanticModel? semanticModel, SyntaxNode root, ImmutableArray<TextSpan> spans, Workspace workspace, ConcurrentDictionary<SyntaxToken, SyntaxToken> replacements, CancellationToken cancellationToken);
public async Task<Document> CaseCorrectAsync(Document document, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
{
......@@ -25,6 +27,11 @@ public async Task<Document> CaseCorrectAsync(Document document, ImmutableArray<T
}
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
if (root is null)
{
throw new NotSupportedException(WorkspacesResources.Document_does_not_support_syntax_trees);
}
var semanticModel = await document.GetSemanticModelForSpanAsync(spans.Collapse(), cancellationToken).ConfigureAwait(false);
var newRoot = CaseCorrect(semanticModel, root, spans, document.Project.Solution.Workspace, cancellationToken);
......@@ -33,10 +40,10 @@ public async Task<Document> CaseCorrectAsync(Document document, ImmutableArray<T
public SyntaxNode CaseCorrect(SyntaxNode root, ImmutableArray<TextSpan> spans, Workspace workspace, CancellationToken cancellationToken)
{
return CaseCorrect(null, root, spans, workspace, cancellationToken);
return CaseCorrect(semanticModel: null, root, spans, workspace, cancellationToken);
}
private SyntaxNode CaseCorrect(SemanticModel semanticModel, SyntaxNode root, ImmutableArray<TextSpan> spans, Workspace workspace, CancellationToken cancellationToken)
private SyntaxNode CaseCorrect(SemanticModel? semanticModel, SyntaxNode root, ImmutableArray<TextSpan> spans, Workspace workspace, CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.CaseCorrection_CaseCorrect, cancellationToken))
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.CaseCorrection
......@@ -22,6 +24,11 @@ internal static class CaseCorrector
public static async Task<Document> CaseCorrectAsync(Document document, CancellationToken cancellationToken = default)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
if (root is null)
{
throw new NotSupportedException(WorkspacesResources.Document_does_not_support_syntax_trees);
}
return await CaseCorrectAsync(document, root.FullSpan, cancellationToken).ConfigureAwait(false);
}
......@@ -32,6 +39,11 @@ public static async Task<Document> CaseCorrectAsync(Document document, Cancellat
public static async Task<Document> CaseCorrectAsync(Document document, SyntaxAnnotation annotation, CancellationToken cancellationToken = default)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
if (root is null)
{
throw new NotSupportedException(WorkspacesResources.Document_does_not_support_syntax_trees);
}
return await CaseCorrectAsync(document, root.GetAnnotatedNodesAndTokens(annotation).Select(n => n.Span).ToImmutableArray(), cancellationToken).ConfigureAwait(false);
}
......@@ -48,12 +60,12 @@ public static async Task<Document> CaseCorrectAsync(Document document, TextSpan
/// Case corrects all names found in the provided spans.
/// </summary>
public static Task<Document> CaseCorrectAsync(Document document, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken = default)
=> document.GetLanguageService<ICaseCorrectionService>().CaseCorrectAsync(document, spans, cancellationToken);
=> document.Project.LanguageServices.GetRequiredService<ICaseCorrectionService>().CaseCorrectAsync(document, spans, cancellationToken);
/// <summary>
/// Case correct only things that don't require semantic information
/// </summary>
internal static SyntaxNode CaseCorrect(SyntaxNode root, ImmutableArray<TextSpan> spans, Workspace workspace, CancellationToken cancellationToken = default)
=> workspace.Services.GetLanguageServices(root.Language).GetService<ICaseCorrectionService>().CaseCorrect(root, spans, workspace, cancellationToken);
=> workspace.Services.GetLanguageServices(root.Language).GetRequiredService<ICaseCorrectionService>().CaseCorrect(root, spans, workspace, cancellationToken);
}
}
......@@ -691,6 +691,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Document does not support syntax trees.
/// </summary>
internal static string Document_does_not_support_syntax_trees {
get {
return ResourceManager.GetString("Document_does_not_support_syntax_trees", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Documentation comment id must start with E, F, M, N, P or T.
/// </summary>
......
......@@ -1476,4 +1476,7 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<data name="Warning_adding_imports_will_bring_an_extension_method_into_scope_with_the_same_name_as_member_access" xml:space="preserve">
<value>Adding imports will bring an extension method into scope with the same name as '{0}'</value>
</data>
<data name="Document_does_not_support_syntax_trees" xml:space="preserve">
<value>Document does not support syntax trees</value>
</data>
</root>
\ No newline at end of file
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind musí být Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Předvolby na úrovni výrazů</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">"DateTimeKind" muss UTC sein.</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Einstellungen für Ausdrucksebene</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind debe ser Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Preferencias de nivel de expresión</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind doit être UTC</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Préférences de niveau expression</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">Il valore di DateTimeKind deve essere Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Preferenze a livello di espressione</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind は Utc にする必要があります</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">式レベルの設定</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind는 UTC여야 합니다.</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">식 수준 기본 설정</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">Element DateTimeKind musi mieć wartość Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Preferencje na poziomie wyrażeń</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind deve ser Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Preferências de nível de expressão</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">Параметр DateTimeKind должен содержать время и дату в формате UTC</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">Выражения уровень предпочтения</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind Utc olmalıdır</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">İfade düzey tercihleri</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind 必须是 Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">表达式级首选项</target>
......
......@@ -37,6 +37,11 @@
<target state="translated">DateTimeKind 必須是 Utc</target>
<note />
</trans-unit>
<trans-unit id="Document_does_not_support_syntax_trees">
<source>Document does not support syntax trees</source>
<target state="new">Document does not support syntax trees</target>
<note />
</trans-unit>
<trans-unit id="Expression_level_preferences">
<source>Expression-level preferences</source>
<target state="translated">運算式層級喜好設定</target>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册