Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into cake-unit-tests
Browse files Browse the repository at this point in the history
* upstream/master:
  Make the regex tests windows only.
  Correct regex completion
  • Loading branch information
333fred committed Sep 20, 2020
2 parents 6c2a86f + 4346937 commit a44adb4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,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 @@ -1402,6 +1402,48 @@ protected override void on$$
Assert.Equal("OnEnable()\n {\n base.OnEnable();$0\n \\}", onEnable.TextEdit.NewText);
}

[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

0 comments on commit a44adb4

Please sign in to comment.