Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct regex completion #1950

Merged
merged 2 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ public async Task<CompletionResponse> Handle(CompletionRequest request)
string providerName = completion.GetProviderName();
switch (providerName)
{
case CompletionItemExtensions.EmeddedLanguageCompletionProvider:
// The Regex completion provider can change escapes based on whether
// we're in a verbatim string or not
{
CompletionChange change = await completionService.GetChangeAsync(document, completion);
Debug.Assert(typedSpan == change.TextChange.Span);
insertText = change.TextChange.NewText!;
}
break;

case CompletionItemExtensions.InternalsVisibleToCompletionProvider:
// The IVT completer doesn't add extra things before the completion
// span, only assembly keys at the end if they exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal static class CompletionItemExtensions
internal const string XmlDocCommentCompletionProvider = "Microsoft.CodeAnalysis.CSharp.Completion.Providers.XmlDocCommentCompletionProvider";
internal const string TypeImportCompletionProvider = "Microsoft.CodeAnalysis.CSharp.Completion.Providers.TypeImportCompletionProvider";
internal const string ExtensionMethodImportCompletionProvider = "Microsoft.CodeAnalysis.CSharp.Completion.Providers.ExtensionMethodImportCompletionProvider";
internal const string EmeddedLanguageCompletionProvider = "Microsoft.CodeAnalysis.CSharp.Completion.Providers.EmbeddedLanguageCompletionProvider";
private const string ProviderName = nameof(ProviderName);
private const string SymbolCompletionItem = "Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem";
private const string SymbolKind = nameof(SymbolKind);
Expand Down
42 changes: 42 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,48 @@ public async Task InternalsVisibleToCompletionSkipsMiscProject()
Assert.Equal("AssemblyNameVal", completions.Items[0].InsertText);
}

[ConditionalTheory(typeof(WindowsOnly))]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task RegexCompletionInNormalString(string filename)
{
const string input = @"
using System.Text.RegularExpressions;
class Foo
{
public void M()
{
_ = new Regex(""$$"");
}
}";

var completions = await FindCompletionsAsync(filename, input, SharedOmniSharpTestHost);
var aCompletion = completions.Items.First(c => c.Label == @"\A");
Assert.NotNull(aCompletion);
Assert.Equal(@"\\A", aCompletion.InsertText);
}

[ConditionalTheory(typeof(WindowsOnly))]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task RegexCompletionInVerbatimString(string filename)
{
const string input = @"
using System.Text.RegularExpressions;
class Foo
{
public void M()
{
_ = new Regex(@""$$"");
}
}";

var completions = await FindCompletionsAsync(filename, input, SharedOmniSharpTestHost);
var aCompletion = completions.Items.First(c => c.Label == @"\A");
Assert.NotNull(aCompletion);
Assert.Equal(@"\A", aCompletion.InsertText);
}

private CompletionService GetCompletionService(OmniSharpTestHost host)
=> host.GetRequestHandler<CompletionService>(EndpointName);

Expand Down