Skip to content
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 @@ -1289,5 +1289,28 @@ void Goo()
Regex.OtherEscape("a"),
Regex.Comment("(?#comment)"));
}

[Theory, CombinatorialData]
public async Task TestRegexNotOnBinaryExpression(TestHost testHost)
{
await TestAsync(
"""
using System.Text.RegularExpressions;

class Program
{
void Goo()
{
// language=regex
var r = @"[a-" + @"z]";
}
}
""",
testHost,
Namespace("System"),
Namespace("Text"),
Namespace("RegularExpressions"),
Keyword("var"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ private bool HasLanguageComment(
if (HasLanguageComment(token.GetPreviousToken().TrailingTrivia, syntaxFacts, out identifier, out options))
return true;

// Check for the common case of a string literal in a large binary expression. For example `"..." + "..." +
// "..."` We never want to consider these as regex/json tokens as processing them would require knowing the
// contents of every string literal, and having our lexers/parsers somehow stitch them all together. This is
// beyond what those systems support (and would only work for constant strings anyways). This prevents both
// incorrect results *and* avoids heavy perf hits walking up large binary expressions (often while a caller is
// themselves walking down such a large expression).
if (syntaxFacts.IsLiteralExpression(token.Parent) &&
syntaxFacts.IsBinaryExpression(token.Parent.Parent) &&
syntaxFacts.SyntaxKinds.AddExpression == token.Parent.Parent.RawKind)
{
return false;
}

for (var node = token.Parent; node != null; node = node.Parent)
{
if (HasLanguageComment(node.GetLeadingTrivia(), syntaxFacts, out identifier, out options))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.TestSourceGenerator;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.LanguageServices;
using Microsoft.VisualStudio.Shell.TableControl;
Expand Down Expand Up @@ -162,7 +161,7 @@ public static void Main()
Assert.Equal(isPreview, await TestServices.Shell.IsActiveTabProvisionalAsync(HangMitigatingCancellationToken));
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/72627")]
public async Task InvokeNavigateToForGeneratedFile()
{
await TestServices.Shell.ShowNavigateToDialogAsync(HangMitigatingCancellationToken);
Expand All @@ -174,7 +173,7 @@ public async Task InvokeNavigateToForGeneratedFile()
Assert.Equal(HelloWorldGenerator.GeneratedEnglishClassName, await TestServices.Editor.GetSelectedTextAsync(HangMitigatingCancellationToken));
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/72627")]
public async Task InvokeNavigateToForGeneratedFile_InFolder()
{
await TestServices.Shell.ShowNavigateToDialogAsync(HangMitigatingCancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public int Convert<TSyntaxKind>(TSyntaxKind kind) where TSyntaxKind : struct
public int StringLiteralExpression => (int)SyntaxKind.StringLiteralExpression;
public int TrueLiteralExpression => (int)SyntaxKind.TrueLiteralExpression;

public int AddExpression => (int)SyntaxKind.AddExpression;
public int AddressOfExpression => (int)SyntaxKind.AddressOfExpression;
public int AnonymousObjectCreationExpression => (int)SyntaxKind.AnonymousObjectCreationExpression;
public int ArrayCreationExpression => (int)SyntaxKind.ArrayCreationExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ internal interface ISyntaxKinds

#region expressions

int AddExpression { get; }
int AddressOfExpression { get; }
int AnonymousObjectCreationExpression { get; }
int ArrayCreationExpression { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.LanguageService
Public ReadOnly Property StringLiteralExpression As Integer = SyntaxKind.StringLiteralExpression Implements ISyntaxKinds.StringLiteralExpression
Public ReadOnly Property TrueLiteralExpression As Integer = SyntaxKind.TrueLiteralExpression Implements ISyntaxKinds.TrueLiteralExpression

Public ReadOnly Property AddExpression As Integer = SyntaxKind.AddExpression Implements ISyntaxKinds.AddExpression
Public ReadOnly Property AddressOfExpression As Integer = SyntaxKind.AddressOfExpression Implements ISyntaxKinds.AddressOfExpression
Public ReadOnly Property AnonymousObjectCreationExpression As Integer = SyntaxKind.AnonymousObjectCreationExpression Implements ISyntaxKinds.AnonymousObjectCreationExpression
Public ReadOnly Property ArrayCreationExpression As Integer = SyntaxKind.ArrayCreationExpression Implements ISyntaxKinds.ArrayCreationExpression
Expand Down