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

RegexDocumentHighlighter.GetReferences throws when editing regex inside a raw string #65836

Closed
vsfeedback opened this issue Dec 7, 2022 · 2 comments · Fixed by #65838
Closed
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
I'm running into this repeatedly when editing a regex within a multiline raw string. Seems to repro consistently when I place the caret at the start of a line within the string (e.g. before the `(?[^:]+)? # Header name. Optional in case it's missing (e.g. if deleted and line starts with :Value)
(?:)? # Colon separator. No whitespace is allowed between name and colon.
([\s]*) # Whitespace is allowed after the colon before the value
(?.+)?
""", RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);


Log message:

StreamJsonRpc.RemoteInvocationException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at StreamJsonRpc.JsonRpc.d__1451.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection1.d__181.MoveNext() RPC server exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at Microsoft.CodeAnalysis.Collections.Internal.ThrowHelper.ThrowArgumentOutOfRange_IndexException() at Microsoft.CodeAnalysis.Collections.SegmentedList1.get_Item(Int32 index)
at Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars.VirtualCharSequence.ImmutableSegmentedListChunk.Find(Int32 position)
at Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions.LanguageServices.RegexDocumentHighlighter.GetReferences(RegexTree tree, Int32 position)
at Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions.LanguageServices.RegexDocumentHighlighter.GetHighlights(RegexTree tree, Int32 positionInDocument)
at Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions.LanguageServices.RegexDocumentHighlighter.GetDocumentHighlights(Document document, SemanticModel semanticModel, SyntaxToken token, Int32 position, HighlightingOptions options, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.TryGetEmbeddedLanguageHighlights(Document document, SemanticModel semanticModel, Int32 position, HighlightingOptions options, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Remote.RemoteDocumentHighlightsService.<>c__DisplayClass2_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_01.<g__ProcessSolutionAsync|1>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.d__71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.d__111.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.d__14`1.MoveNext()


---
### Original Comments

#### Feedback Bot on 12/6/2022, 07:01 PM: 

(private comment, text removed)
#### Feedback Bot on 12/7/2022, 07:33 AM: 

(private comment, text removed)
#### Feedback Bot on 12/7/2022, 07:33 AM: 

(private comment, text removed)

---
### Original Solutions
(no solutions)
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 7, 2022
@CyrusNajmabadi
Copy link
Member

Code is:

    private static readonly Regex s_regexHeader = new("""
        ^(?<name>[^:]+)? # Header name.  Optional in case it's missing (e.g. if deleted and line starts with :Value)
        (?<operator>:)?  # Colon separator.  No whitespace is allowed between name and colon.
        ([\s]*)          # Whitespace is allowed after the colon before the value
        (?<value>.+)?    
        """, RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);

@CyrusNajmabadi
Copy link
Member

Repros for me. Investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants