提交 eda43a63 编写于 作者: V Victor Zaytsev

Fixed #19260

上级 743f42eb
......@@ -196,6 +196,68 @@ public class C
await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async void EscapeKeywords1()
{
var markup = @"
using System.Text;
public class C
{
void Foo(StringBuilder $$) {}
}
";
await VerifyItemExistsAsync(markup, "stringBuilder", glyph: (int) Glyph.Parameter);
await VerifyItemExistsAsync(markup, "@string", glyph: (int) Glyph.Parameter);
await VerifyItemExistsAsync(markup, "builder", glyph: (int) Glyph.Parameter);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async void EscapeKeywords2()
{
var markup = @"
class For { }
public class C
{
void Foo(For $$) {}
}
";
await VerifyItemExistsAsync(markup, "@for", glyph: (int) Glyph.Parameter);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async void EscapeKeywords3()
{
var markup = @"
class For { }
public class C
{
void foo()
{
For $$
}
}
";
await VerifyItemExistsAsync(markup, "@for");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async void EscapeKeywords4()
{
var markup = @"
using System.Text;
public class C
{
void foo()
{
StringBuilder $$
}
}
";
await VerifyItemExistsAsync(markup, "stringBuilder");
await VerifyItemExistsAsync(markup, "@string");
await VerifyItemExistsAsync(markup, "builder");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async void NoSuggestionsForInt()
{
......
......@@ -177,7 +177,7 @@ private ITypeSymbol UnwrapType(ITypeSymbol type, Compilation compilation)
{
foreach (var baseName in baseNames)
{
var name = rule.NamingStyle.CreateName(baseName);
var name = EscapeIdentifier(rule.NamingStyle.CreateName(baseName));
if (name.Length > 1 && !result.ContainsKey(name)) // Don't add multiple items for the same name
{
result.Add(name, symbolKind);
......@@ -190,6 +190,14 @@ private ITypeSymbol UnwrapType(ITypeSymbol type, Compilation compilation)
return result.Select(kvp => (kvp.Key, kvp.Value)).ToImmutableArray();
}
private static string EscapeIdentifier(string identifier)
{
var kind = SyntaxFacts.GetKeywordKind(identifier);
return kind == SyntaxKind.None
? identifier
: $"@{identifier}";
}
CompletionItem CreateCompletionItem(string name, Glyph glyph, string sortText)
{
return CommonCompletionItem.Create(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册