public async Task FindAsync( TextDocumentState state, HashSet <Checksum> searchingChecksumsLeft, Dictionary <Checksum, object> result, CancellationToken cancellationToken) { Debug.Assert(state.TryGetStateChecksums(out var stateChecksum) && this == stateChecksum); cancellationToken.ThrowIfCancellationRequested(); if (searchingChecksumsLeft.Remove(Checksum)) { result[Checksum] = this; } if (searchingChecksumsLeft.Remove(Info)) { result[Info] = state.Attributes; } if (searchingChecksumsLeft.Remove(Text)) { result[Text] = await SerializableSourceText.FromTextDocumentStateAsync(state, cancellationToken).ConfigureAwait(false); } }
public void Find( TextDocumentState state, HashSet <Checksum> searchingChecksumsLeft, Dictionary <Checksum, object> result, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // verify input DocumentStateChecksums stateChecksum; Contract.ThrowIfFalse(state.TryGetStateChecksums(out stateChecksum)); Contract.ThrowIfFalse(this == stateChecksum); if (searchingChecksumsLeft.Remove(Checksum)) { result[Checksum] = this; } if (searchingChecksumsLeft.Remove(Info)) { result[Info] = new SerializedDocumentInfo(state.Id, state.Name, state.Folders, state.GetSourceCodeKind(), state.FilePath, state.IsGenerated()); } if (searchingChecksumsLeft.Remove(Text)) { // why I can't get text synchronously when async lazy support synchronous callback? result[Text] = state; } }
public void Find( TextDocumentState state, HashSet <Checksum> searchingChecksumsLeft, Dictionary <Checksum, object> result, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // verify input Contract.ThrowIfFalse(state.TryGetStateChecksums(out var stateChecksum)); Contract.ThrowIfFalse(this == stateChecksum); if (searchingChecksumsLeft.Remove(Checksum)) { result[Checksum] = this; } if (searchingChecksumsLeft.Remove(Info)) { result[Info] = state.Attributes; } if (searchingChecksumsLeft.Remove(Text)) { // why I can't get text synchronously when async lazy support synchronous callback? result[Text] = state; } }
public async Task FindAsync( TextDocumentState state, HashSet <Checksum> searchingChecksumsLeft, Dictionary <Checksum, object> result, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // verify input Contract.ThrowIfFalse(state.TryGetStateChecksums(out var stateChecksum)); Contract.ThrowIfFalse(this == stateChecksum); if (searchingChecksumsLeft.Remove(Checksum)) { result[Checksum] = this; } if (searchingChecksumsLeft.Remove(Info)) { result[Info] = state.Attributes; } if (searchingChecksumsLeft.Remove(Text)) { result[Text] = await state.GetTextAsync(cancellationToken).ConfigureAwait(false); } }
private static TextDocumentState CreateTextState(Solution solution, SourceText text) { // we just need a fake state to call GetTextAsync that return given sourcetext return(TextDocumentState.Create( DocumentInfo.Create( DocumentId.CreateNewId(ProjectId.CreateNewId()), "unused", loader: TextLoader.From(TextAndVersion.Create(text, VersionStamp.Default))), solution.Services)); }
public SourceTextAsset(Serializer serializer, TextDocumentState state, Checksum checksum, string kind) : base(checksum, WellKnownChecksumObjects.SourceText) { Contract.Requires(kind == WellKnownChecksumObjects.SourceText); _serializer = serializer; _state = state; }
/// <summary> /// Create a <see cref="SourceText"/> from a <see cref="TextDocumentState"/>. <paramref name="document"/> should be non-null. /// </summary> public AdditionalTextDocument(TextDocumentState document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } _document = document; }
/// <summary> /// Create a stream from a <see cref="Document"/>. <paramref name="document"/> should be non-null. /// </summary> public AdditionalDocumentStream(TextDocumentState document) { if (document == null) { throw new ArgumentNullException("document"); } this.document = document; }
public static ValueTask <SerializableSourceText> FromTextDocumentStateAsync(TextDocumentState state, CancellationToken cancellationToken) { if (state.Storage is ITemporaryTextStorageWithName storage) { return(new ValueTask <SerializableSourceText>(new SerializableSourceText(storage))); } else { return(SpecializedTasks.TransformWithoutIntermediateCancellationExceptionAsync(
public Asset Build(TextDocumentState state, SourceText text, CancellationToken cancellationToken) { // TODO: currently this is a bit wierd not to hold onto source text. // it would be nice if SourceText is changed like how recoverable syntax tree work. var asset = _checksumTree.GetOrCreateAsset(state, state, WellKnownChecksumObjects.SourceText, CreateSourceText, cancellationToken); // make sure we keep text alive. this is to make sure we don't do any async call in asset builder GC.KeepAlive(text); return(asset); }
private async Task <Asset> CreateSourceTextAsync(TextDocumentState state, string kind, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var text = await state.GetTextAsync(cancellationToken).ConfigureAwait(false); var checksum = new Checksum(text.GetChecksum()); return(new SourceTextAsset(_serializer, state, checksum, kind)); }
private SourceCodeKind GetSourceCodeKind(TextDocumentState documentState) { var source = documentState as DocumentState; if (source != null) { return(source.SourceCodeKind); } // no source return(SourceCodeKind.Regular); }
private bool IsGenerated(TextDocumentState documentState) { var source = documentState as DocumentState; if (source != null) { return(source.IsGenerated); } // no source return(false); }
private Asset CreateSourceText(TextDocumentState state, string kind, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); SourceText text; Contract.ThrowIfFalse(state.TryGetText(out text)); var checksum = new Checksum(text.GetChecksum()); return(new SourceTextAsset(_serializer, state, checksum, kind)); }
public static async ValueTask <SerializableSourceText> FromTextDocumentStateAsync( TextDocumentState state, CancellationToken cancellationToken ) { if (state.Storage is ITemporaryTextStorageWithName storage) { return(new SerializableSourceText(storage)); } else { return(new SerializableSourceText( await state.GetTextAsync(cancellationToken).ConfigureAwait(false) )); } }
public SourceTextAsset(Checksum checksum, TextDocumentState state, Serializer serializer) : base(checksum, WellKnownSynchronizationKind.SourceText) { _state = state; _serializer = serializer; }
public static bool SupportsDiagnostics(this TextDocumentState document) { return(document?.Services.GetService <IDocumentOperationService>().SupportDiagnostics ?? false); }
public static bool CanApplyChange(this TextDocumentState document) { return(document?.Services.GetService <IDocumentOperationService>().CanApplyChange ?? false); }
private Task <DocumentChecksumObject> BuildAsync(TextDocumentState documentState, CancellationToken cancellationToken) { return(_checksumTree.GetOrCreateChecksumObjectWithChildrenAsync(documentState, documentState, DocumentChecksumObject.Name, CreateDocumentChecksumObjectAsync, cancellationToken)); }
private async Task <DocumentChecksumObject> CreateDocumentChecksumObjectAsync(TextDocumentState key, TextDocumentState documentState, string kind, CancellationToken cancellationToken) { var assetBuilder = new AssetBuilder(_checksumTree); var info = assetBuilder.Build(documentState, cancellationToken); // TODO: think of a way to skip getting text var sourceText = await key.GetTextAsync(cancellationToken).ConfigureAwait(false); var text = assetBuilder.Build(key, sourceText, cancellationToken); return(new DocumentChecksumObject(_serializer, info.Checksum, text.Checksum)); }
public Task <Asset> BuildAsync(TextDocumentState state, SourceText unused, CancellationToken cancellationToken) { // TODO: currently this is a bit wierd not to hold onto source text. // it would be nice if SourceText is changed like how recoverable syntax tree work. return(_checksumTree.GetOrCreateAssetAsync(state, state, WellKnownChecksumObjects.SourceText, CreateSourceTextAsync, cancellationToken)); }
internal AdditionalDocument(Project project, TextDocumentState state) : base(project, state, TextDocumentKind.AdditionalDocument) { }
/// <summary> /// Create a <see cref="SourceText"/> from a <see cref="TextDocumentState"/>. /// </summary> public AdditionalTextWithState(TextDocumentState documentState) =>
private DocumentChecksumObjectInfo GetInfo(TextDocumentState documentState) { // we might just split it to TextDocument and Document. return(new DocumentChecksumObjectInfo(documentState.Id, documentState.Name, documentState.Folders, GetSourceCodeKind(documentState), documentState.FilePath, IsGenerated(documentState))); }
public Task <Asset> BuildAsync(TextDocumentState document, CancellationToken cancellationToken) { return(_checksumTree.GetOrCreateAssetAsync(document, GetInfo(document), WellKnownChecksumObjects.DocumentChecksumObjectInfo, CreateDocumentChecksumObjectInfoAsync, cancellationToken)); }
/// <summary> /// Create a <see cref="SourceText"/> from a <see cref="TextDocumentState"/>. <paramref name="document"/> should be non-null. /// </summary> public AdditionalTextDocument(TextDocumentState document) { _document = document ?? throw new ArgumentNullException(nameof(document)); }
public static DocumentKey ToDocumentKey(ProjectKey projectKey, TextDocumentState state) => new(projectKey, state.Id, state.FilePath, state.Name);
public Asset Build(TextDocumentState document, CancellationToken cancellationToken) { return(_checksumTree.GetOrCreateAsset(document, GetInfo(document), WellKnownChecksumObjects.DocumentChecksumObjectInfo, CreateDocumentChecksumObjectInfo, cancellationToken)); }
/// <summary> /// Create a <see cref="SourceText"/> from a <see cref="TextDocumentState"/>. <paramref name="documentState"/> should be non-null. /// </summary> public AdditionalTextWithState(TextDocumentState documentState) { _documentState = documentState ?? throw new ArgumentNullException(nameof(documentState)); }
public SourceTextAsset(Checksum checksum, TextDocumentState state, Serializer serializer) : base(checksum, WellKnownSynchronizationKinds.SourceText) { _state = state; _serializer = serializer; }
public static bool IsRazorDocument(this TextDocumentState documentState) => documentState.Services.GetService <DocumentPropertiesService>()?.DiagnosticsLspClientName == RazorCSharpLspClientName;