Skip to content

Conversation

@ToddGrun
Copy link
Contributor

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

…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
@ToddGrun ToddGrun requested a review from dibarbet April 16, 2025 00:20
@ToddGrun ToddGrun requested a review from a team as a code owner April 16, 2025 00:20
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 16, 2025
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);
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed size array builder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

/// </summary>
[JsonPropertyName("range")]
[JsonRequired]
public Range Range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than messing with the SumTypes, could we have just made this nullable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doing the WithChanges versus just creating a new text from scratch?

Copy link
Contributor Author

@ToddGrun ToddGrun Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to have to duplicate the parameter knowledge involved with doing that, as done here:

var sourceText = SourceText.From(request.TextDocument.Text, System.Text.Encoding.UTF8, SourceHashAlgorithms.OpenDocumentChecksumAlgorithm);

@arunchndr arunchndr merged commit 59eae07 into dotnet:main Apr 18, 2025
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 18, 2025
dibarbet added a commit to dibarbet/roslyn that referenced this pull request Apr 20, 2025
…cross the range (dotnet#78165)"

This reverts commit 59eae07, reversing
changes made to 20e9836.
dibarbet added a commit that referenced this pull request Apr 20, 2025
#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
```
ToddGrun added a commit to ToddGrun/razor that referenced this pull request May 30, 2025
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.
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
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 VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

textDocument/didChange incorrectly requires range to be set

6 participants