Skip to content
Merged
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 @@ -36,20 +36,32 @@ private sealed class LspTextChangesTextLoader(

public override async Task<TextAndVersion> LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken)
{
if (_document is null)
try
{
var text = ApplyChanges(_emptySourceText.Value, _changes);
return TextAndVersion.Create(text, VersionStamp.Default.GetNewerVersion());
}
if (_document is null)
{
var text = ApplyChanges(_emptySourceText.Value, _changes);
return TextAndVersion.Create(text, VersionStamp.Default.GetNewerVersion());
}

var sourceText = await _document.GetTextAsync(cancellationToken).ConfigureAwait(false);

var sourceText = await _document.GetTextAsync(cancellationToken).ConfigureAwait(false);
// Validate the checksum information so the edits are known to be correct

// Validate the checksum information so the edits are known to be correct
if (IsSourceTextMatching(sourceText))
if (IsSourceTextMatching(sourceText))
{
var version = await _document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
var newText = ApplyChanges(sourceText, _changes);
return TextAndVersion.Create(newText, version.GetNewerVersion());
}
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
var version = await _document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
var newText = ApplyChanges(sourceText, _changes);
return TextAndVersion.Create(newText, version.GetNewerVersion());
// This happens if ApplyChanges tries to apply an invalid TextChange.
// This is recoverable but incurs a perf hit for getting the full text below.

// TODO: Add ability to capture a fault here in EA. There's something wrong if
// the Checksum matches but the text changes can't be applied.
}

return await GetFullDocumentFromServerAsync(cancellationToken).ConfigureAwait(false);
Expand Down