Skip to content
Merged
Show file tree
Hide file tree
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 @@ -115,30 +115,26 @@ public SourceText GetText(CancellationToken cancellationToken)
return text;
}

public static ValueTask<SerializableSourceText> FromTextDocumentStateAsync(
public static async ValueTask<SerializableSourceText> FromTextDocumentStateAsync(
TextDocumentState state, CancellationToken cancellationToken)
{
if (state.TextAndVersionSource.TextLoader is SerializableSourceTextLoader serializableLoader)
{
// If we're already pointing at a serializable loader, we can just use that directly.
return new(serializableLoader.SerializableSourceText);
return serializableLoader.SerializableSourceText;
}
else if (state.StorageHandle is TemporaryStorageTextHandle storageHandle)
{
// Otherwise, if we're pointing at a memory mapped storage location, we can create the source text that directly wraps that.
return new(new SerializableSourceText(storageHandle));
return new SerializableSourceText(storageHandle);
}
else
{
// Otherwise, the state object has reified the text into some other form, and dumped any original
// information on how it got it. In that case, we create a new text instance to represent the serializable
// source text out of.

return SpecializedTasks.TransformWithoutIntermediateCancellationExceptionAsync(
static (state, cancellationToken) => state.GetTextAsync(cancellationToken),
static (text, _) => new SerializableSourceText(text, text.GetContentHash()),
state,
cancellationToken);
var text = await state.GetTextAsync(cancellationToken).ConfigureAwait(false);
return new SerializableSourceText(text, text.GetContentHash());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ public bool TryGetStateChecksums([NotNullWhen(true)] out ProjectStateChecksums?
public Task<ProjectStateChecksums> GetStateChecksumsAsync(CancellationToken cancellationToken)
=> LazyChecksums.GetValueAsync(cancellationToken);

public Task<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
public async ValueTask<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
{
return SpecializedTasks.TransformWithoutIntermediateCancellationExceptionAsync(
static (lazyChecksums, cancellationToken) => new ValueTask<ProjectStateChecksums>(lazyChecksums.GetValueAsync(cancellationToken)),
static (projectStateChecksums, _) => projectStateChecksums.Checksum,
LazyChecksums,
cancellationToken).AsTask();
var projectStateChecksums = await this.LazyChecksums.GetValueAsync(cancellationToken).ConfigureAwait(false);
return projectStateChecksums.Checksum;
}

public Checksum GetParseOptionsChecksum()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,13 @@ public bool TryGetTextVersion(out VersionStamp version)
public bool TryGetTextAndVersion([NotNullWhen(true)] out TextAndVersion? textAndVersion)
=> TextAndVersionSource.TryGetValue(LoadTextOptions, out textAndVersion);

public ValueTask<SourceText> GetTextAsync(CancellationToken cancellationToken)
public async ValueTask<SourceText> GetTextAsync(CancellationToken cancellationToken)
{
if (TryGetText(out var text))
{
return new ValueTask<SourceText>(text);
}
return text;

return SpecializedTasks.TransformWithoutIntermediateCancellationExceptionAsync(
static (self, cancellationToken) => self.GetTextAndVersionAsync(cancellationToken),
static (textAndVersion, _) => textAndVersion.Text,
this,
cancellationToken);
var textAndVersion = await GetTextAndVersionAsync(cancellationToken).ConfigureAwait(false);
return textAndVersion.Text;
}

public SourceText GetTextSynchronously(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ public bool TryGetStateChecksums([NotNullWhen(returnValue: true)] out DocumentSt
public Task<DocumentStateChecksums> GetStateChecksumsAsync(CancellationToken cancellationToken)
=> _lazyChecksums.GetValueAsync(cancellationToken);

public Task<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
public async ValueTask<Checksum> GetChecksumAsync(CancellationToken cancellationToken)
{
return SpecializedTasks.TransformWithoutIntermediateCancellationExceptionAsync(
static (lazyChecksums, cancellationToken) => new ValueTask<DocumentStateChecksums>(lazyChecksums.GetValueAsync(cancellationToken)),
static (documentStateChecksums, _) => documentStateChecksums.Checksum,
_lazyChecksums,
cancellationToken).AsTask();
var documentStateChecksums = await _lazyChecksums.GetValueAsync(cancellationToken).ConfigureAwait(false);
return documentStateChecksums.Checksum;
}

private async Task<DocumentStateChecksums> ComputeChecksumsAsync(CancellationToken cancellationToken)
Expand Down
Loading
Loading