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

Could lang=regex syntax handling apply to consts that are later used in a recognized location? #77189

Closed
stephentoub opened this issue Feb 12, 2025 · 3 comments · Fixed by #77199
Assignees
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@stephentoub
Copy link
Member

Today if I have:

new Regex("someRegex")

I get nice syntax coloring / IntelliSense support for that "someRegex" string. Same applies anywhere [StringSyntax("Regex")] is used, or if /* lang=regex */ is applied.

Frequently, though, I'll see code that has:

private const string SomePattern = "someRegex";
...
... = new Regex(SomePattern);

and that "someRegex" doesn't get the nice support.

Could Roslyn see that SomePattern is passed somewhere that accepts [StringSyntax("Regex")] and implicitly treat it as if it had /* lang=regex */ applied?

cc: @CyrusNajmabadi

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 12, 2025
@CyrusNajmabadi
Copy link
Member

Yes, it could. We already do this for locals. It would not be out of bounds to do this.

Question: in your cases, is the constant and the regex usage located in the file? or do you sometimes put them in different partial parts. I'm wary about the expense of looking into different parts during the classification pass. So it would be nice if this only applied to one part at a time.

If your pattern is to have them in distinct parts, i'll def look into supporting that, but it's more complex :)

@CyrusNajmabadi CyrusNajmabadi added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 12, 2025
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Feb 12, 2025
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Feb 12, 2025
@stephentoub
Copy link
Member Author

Question: in your cases, is the constant and the regex usage located in the file?

The 90% case is they're in the same file.

@CyrusNajmabadi
Copy link
Member

Ok. We can start with that and see if that's sufficient :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Completed
2 participants