Handle textDocument/didChange notifications that don't pass across the range#78165
Conversation
…e range Per the LSP spec, these notifications can either send over a range/text or can pass over just the text, implying a full document change. Roslyn did not previously support the latter. Fixes dotnet#77002
| ImmutableArray<(LSP.Range? Range, string Text)> changes) | ||
| { | ||
| var changeEvents = changes.Select(change => new LSP.TextDocumentContentChangeEvent | ||
| var changeEvents = new List<LSP.SumType<LSP.TextDocumentContentChangeEvent, LSP.TextDocumentContentChangeFullReplacementEvent>>(changes.Length); |
There was a problem hiding this comment.
fixed size array builder?
There was a problem hiding this comment.
I was just going the simplest route since this is test code. Went ahead and just switched directly over to use an array as it's not really any more complicated.
…rray directly in one of the tests
| /// </summary> | ||
| [JsonPropertyName("range")] | ||
| [JsonRequired] | ||
| public Range Range |
There was a problem hiding this comment.
Rather than messing with the SumTypes, could we have just made this nullable?
There was a problem hiding this comment.
The spec defines it as a union type, so we should use a union type. They do happen to share the same field names right now, but that isn't a guarantee for the futre
| return text; | ||
| } | ||
|
|
||
| private static (ImmutableArray<TextDocumentContentChangeEvent>, SourceText) GetUpdatedSouorceTextAndChangesAfterFullTextReplacementHandled(SumType<TextDocumentContentChangeEvent, TextDocumentContentChangeFullReplacementEvent>[] contentChanges, SourceText text) |
There was a problem hiding this comment.
| private static (ImmutableArray<TextDocumentContentChangeEvent>, SourceText) GetUpdatedSouorceTextAndChangesAfterFullTextReplacementHandled(SumType<TextDocumentContentChangeEvent, TextDocumentContentChangeFullReplacementEvent>[] contentChanges, SourceText text) | |
| private static (ImmutableArray<TextDocumentContentChangeEvent>, SourceText) GetUpdatedSourceTextAndChangesAfterFullTextReplacementHandled(SumType<TextDocumentContentChangeEvent, TextDocumentContentChangeFullReplacementEvent>[] contentChanges, SourceText text) |
| if (change.Value is TextDocumentContentChangeFullReplacementEvent onlyTextEvent) | ||
| { | ||
| // Found a full text replacement. Create the new text and stop processing. | ||
| text = text.WithChanges([new TextChange(new TextSpan(0, text.Length), onlyTextEvent.Text)]); |
There was a problem hiding this comment.
Why doing the WithChanges versus just creating a new text from scratch?
There was a problem hiding this comment.
I didn't want to have to duplicate the parameter knowledge involved with doing that, as done here:
…cross the range (dotnet#78165)" This reverts commit 59eae07, reversing changes made to 20e9836.
#78227) …cross the range (#78165)" This reverts commit 59eae07, reversing changes made to 20e9836. Breaks Razor ``` 04/19/2025 07:45:59.186 [9876]: 2>Warning: System.MissingMethodException: Method not found: 'Roslyn.LanguageServer.Protocol.TextDocumentContentChangeEvent[] Roslyn.LanguageServer.Protocol.DidChangeTextDocumentParams.get_ContentChanges()'. while resolving 0xa0007f6 - Roslyn.LanguageServer.Protocol.DidChangeTextDocumentParams.get_ContentChanges. 04/19/2025 07:45:59.608 [9876]: 2>Method not found: 'Roslyn.LanguageServer.Protocol.TextDocumentContentChangeEvent[] Roslyn.LanguageServer.Protocol.DidChangeTextDocumentParams.get_ContentChanges()'. while compiling method <HandleNotificationAsync>d__7.MoveNext ```
This is in anticipation of a change I made (dotnet/roslyn#78165) that was reverted and will need a coordinated Roslyn/Razor insertion. There were two recent changes to roslyn that required changes in razor as part of this update: 1) The Uri => DocumentUri change. This is the *vast* majority of changes in this PR. 2) The EditorFeatures.WPF removal.
Per the LSP specification, these notifications can either send over a range/text or can pass over just the text, implying a full document change. Roslyn did not previously support the latter.
Fixes #77002