提交 961f5610 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14622 from CyrusNajmabadi/portFix14

Spell checking fixes.
......@@ -22,6 +22,13 @@ internal partial class CSharpSpellCheckCodeFixProvider : AbstractSpellCheckCodeF
GenerateMethodDiagnosticIds.FixableDiagnosticIds).Concat(
ImmutableArray.Create(CS0426));
protected override bool DescendIntoChildren(SyntaxNode arg)
{
// Don't dive into type argument lists. We don't want to report spell checking
// fixes for type args when we're called on an outer generic type.
return !(arg is TypeArgumentListSyntax);
}
protected override bool IsGeneric(SimpleNameSyntax nameNode)
{
return nameNode is GenericNameSyntax;
......
......@@ -76,7 +76,9 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
// Wrap the spell checking actions into a single top level suggestion
// so as to not clutter the list.
context.RegisterCodeFix(new GroupingCodeAction(codeActions), context.Diagnostics);
context.RegisterCodeFix(new GroupingCodeAction(
string.Format(FeaturesResources.Fully_qualify_0, GetNodeName(document, node)),
codeActions), context.Diagnostics);
}
else
{
......@@ -86,19 +88,16 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
}
private IEnumerable<CodeAction> CreateActions(
CodeFixContext context, Document document, Diagnostic diagnostic,
SyntaxNode node, SemanticModel semanticModel,
IEnumerable<INamespaceOrTypeSymbol> proposedContainers,
CodeFixContext context, Document document, Diagnostic diagnostic,
SyntaxNode node, SemanticModel semanticModel,
IEnumerable<INamespaceOrTypeSymbol> proposedContainers,
ISymbolDisplayService displayService)
{
foreach (var container in proposedContainers)
{
var containerName = displayService.ToMinimalDisplayString(semanticModel, node.SpanStart, container);
var syntaxFacts = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
string name;
int arity;
syntaxFacts.GetNameAndArityOfSimpleName(node, out name, out arity);
var name = GetNodeName(document, node);
// Actual member name might differ by case.
string memberName;
......@@ -120,6 +119,15 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
}
}
private static string GetNodeName(Document document, SyntaxNode node)
{
var syntaxFacts = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
string name;
int arity;
syntaxFacts.GetNameAndArityOfSimpleName(node, out name, out arity);
return name;
}
private async Task<Document> ProcessNode(Document document, SyntaxNode node, string containerName, CancellationToken cancellationToken)
{
var newRoot = await this.ReplaceNodeAsync(node, containerName, cancellationToken).ConfigureAwait(false);
......@@ -231,7 +239,7 @@ private bool BindsWithoutErrors(INamespaceSymbol ns, string rightName, bool isAt
{
return false;
}
return BindsWithoutErrors(ns, rightName + "Attribute", isAttributeName: false);
}
......@@ -270,17 +278,17 @@ private IEnumerable<INamespaceOrTypeSymbol> FilterAndSort(IEnumerable<SymbolResu
private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument) :
base(title, createChangedDocument)
base(title, createChangedDocument, equivalenceKey: title)
{
}
}
private class GroupingCodeAction : CodeAction.SimpleCodeAction
{
public GroupingCodeAction(ImmutableArray<CodeAction> nestedActions)
: base(FeaturesResources.Fully_qualify_name, nestedActions)
public GroupingCodeAction(string title, ImmutableArray<CodeAction> nestedActions)
: base(title, nestedActions)
{
}
}
}
}
}
\ No newline at end of file
......@@ -1306,20 +1306,20 @@ internal class FeaturesResources {
}
/// <summary>
/// Looks up a localized string similar to Generate type.
/// Looks up a localized string similar to Generate type &apos;{0}&apos;.
/// </summary>
internal static string Generate_type {
internal static string Generate_type_0 {
get {
return ResourceManager.GetString("Generate_type", resourceCulture);
return ResourceManager.GetString("Generate_type_0", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Generate variable.
/// Looks up a localized string similar to Generate variable &apos;{0}&apos;.
/// </summary>
internal static string Generate_variable {
internal static string Generate_variable_0 {
get {
return ResourceManager.GetString("Generate_variable", resourceCulture);
return ResourceManager.GetString("Generate_variable_0", resourceCulture);
}
}
......
......@@ -858,8 +858,8 @@ Do you want to continue?</value>
<data name="Method_referenced_implicitly" xml:space="preserve">
<value>Method referenced implicitly</value>
</data>
<data name="Generate_type" xml:space="preserve">
<value>Generate type</value>
<data name="Generate_type_0" xml:space="preserve">
<value>Generate type '{0}'</value>
</data>
<data name="Generate_0_1" xml:space="preserve">
<value>Generate {0} '{1}'</value>
......@@ -956,8 +956,8 @@ This version used in: {2}</value>
<data name="Install_version_0" xml:space="preserve">
<value>Install version '{0}'</value>
</data>
<data name="Generate_variable" xml:space="preserve">
<value>Generate variable</value>
<data name="Generate_variable_0" xml:space="preserve">
<value>Generate variable '{0}'</value>
</data>
<data name="Classes" xml:space="preserve">
<value>Classes</value>
......
......@@ -78,8 +78,9 @@ protected AbstractGenerateVariableService()
{
// Wrap the generate variable actions into a single top level suggestion
// so as to not clutter the list.
return ImmutableArray.Create<CodeAction>(
new MyCodeAction(FeaturesResources.Generate_variable, actions.ToImmutableAndFree()));
return ImmutableArray.Create<CodeAction>(new MyCodeAction(
string.Format(FeaturesResources.Generate_variable_0, state.IdentifierToken.ValueText),
actions.ToImmutableAndFree()));
}
return actions.ToImmutableAndFree();
......@@ -154,4 +155,4 @@ public MyCodeAction(string title, ImmutableArray<CodeAction> nestedActions)
}
}
}
}
}
\ No newline at end of file
......@@ -78,8 +78,8 @@ protected AbstractGenerateTypeService()
{
// Wrap the generate type actions into a single top level suggestion
// so as to not clutter the list.
return ImmutableArray.Create<CodeAction>(
new MyCodeAction(FeaturesResources.Generate_type, actions.AsImmutable()));
return ImmutableArray.Create<CodeAction>(new MyCodeAction(
string.Format(FeaturesResources.Generate_type_0, state.Name), actions.AsImmutable()));
}
else
{
......@@ -305,4 +305,4 @@ public MyCodeAction(string title, ImmutableArray<CodeAction> nestedActions)
}
}
}
}
}
\ No newline at end of file
......@@ -33,7 +33,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
}
SemanticModel semanticModel = null;
foreach (var name in node.DescendantNodesAndSelf().OfType<TSimpleName>())
foreach (var name in node.DescendantNodesAndSelf(DescendIntoChildren).OfType<TSimpleName>())
{
// Only bother with identifiers that are at least 3 characters long.
// We don't want to be too noisy as you're just starting to type something.
......@@ -50,6 +50,8 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
}
}
protected abstract bool DescendIntoChildren(SyntaxNode arg);
private async Task CreateSpellCheckCodeIssueAsync(CodeFixContext context, TSimpleName nameNode, string nameText, CancellationToken cancellationToken)
{
var document = context.Document;
......@@ -103,7 +105,8 @@ private async Task CreateSpellCheckCodeIssueAsync(CodeFixContext context, TSimpl
{
// Wrap the spell checking actions into a single top level suggestion
// so as to not clutter the list.
context.RegisterCodeFix(new MyCodeAction(codeActions), context.Diagnostics);
context.RegisterCodeFix(new MyCodeAction(
String.Format(FeaturesResources.Spell_check_0, nameText), codeActions), context.Diagnostics);
}
else
{
......@@ -145,8 +148,8 @@ public SpellCheckCodeAction(string title, Func<CancellationToken, Task<Document>
private class MyCodeAction : CodeAction.SimpleCodeAction
{
public MyCodeAction(ImmutableArray<CodeAction> nestedActions)
: base(FeaturesResources.Fix_spelling, nestedActions)
public MyCodeAction(string title, ImmutableArray<CodeAction> nestedActions)
: base(title, nestedActions)
{
}
}
......
......@@ -40,6 +40,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Spellcheck
End Get
End Property
Protected Overrides Function DescendIntoChildren(arg As SyntaxNode) As Boolean
Return TypeOf arg IsNot TypeArgumentListSyntax
End Function
Protected Overrides Function IsGeneric(nameNode As SimpleNameSyntax) As Boolean
Return nameNode.Kind() = SyntaxKind.GenericName
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册