Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
        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));
 }
Esempio n. 6
0
        public SourceTextAsset(Serializer serializer, TextDocumentState state, Checksum checksum, string kind) :
            base(checksum, WellKnownChecksumObjects.SourceText)
        {
            Contract.Requires(kind == WellKnownChecksumObjects.SourceText);

            _serializer = serializer;
            _state      = state;
        }
Esempio n. 7
0
        /// <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;
        }
Esempio n. 8
0
        /// <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;
        }
Esempio n. 9
0
        /// <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;
        }
        /// <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(
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
        private SourceCodeKind GetSourceCodeKind(TextDocumentState documentState)
        {
            var source = documentState as DocumentState;

            if (source != null)
            {
                return(source.SourceCodeKind);
            }

            // no source
            return(SourceCodeKind.Regular);
        }
Esempio n. 15
0
        private bool IsGenerated(TextDocumentState documentState)
        {
            var source = documentState as DocumentState;

            if (source != null)
            {
                return(source.IsGenerated);
            }

            // no source
            return(false);
        }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
 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)
                    ));
     }
 }
Esempio n. 18
0
 public SourceTextAsset(Checksum checksum, TextDocumentState state, Serializer serializer) :
     base(checksum, WellKnownSynchronizationKind.SourceText)
 {
     _state      = state;
     _serializer = serializer;
 }
Esempio n. 19
0
 public static bool SupportsDiagnostics(this TextDocumentState document)
 {
     return(document?.Services.GetService <IDocumentOperationService>().SupportDiagnostics ?? false);
 }
Esempio n. 20
0
 public static bool CanApplyChange(this TextDocumentState document)
 {
     return(document?.Services.GetService <IDocumentOperationService>().CanApplyChange ?? false);
 }
Esempio n. 21
0
 private Task <DocumentChecksumObject> BuildAsync(TextDocumentState documentState, CancellationToken cancellationToken)
 {
     return(_checksumTree.GetOrCreateChecksumObjectWithChildrenAsync(documentState, documentState, DocumentChecksumObject.Name, CreateDocumentChecksumObjectAsync, cancellationToken));
 }
Esempio n. 22
0
        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));
        }
Esempio n. 23
0
 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));
 }
Esempio n. 24
0
 internal AdditionalDocument(Project project, TextDocumentState state)
     : base(project, state, TextDocumentKind.AdditionalDocument)
 {
 }
Esempio n. 25
0
 /// <summary>
 /// Create a <see cref="SourceText"/> from a <see cref="TextDocumentState"/>.
 /// </summary>
 public AdditionalTextWithState(TextDocumentState documentState) =>
Esempio n. 26
0
 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)));
 }
Esempio n. 27
0
 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));
 }
Esempio n. 29
0
 public static DocumentKey ToDocumentKey(ProjectKey projectKey, TextDocumentState state)
 => new(projectKey, state.Id, state.FilePath, state.Name);
Esempio n. 30
0
 public Asset Build(TextDocumentState document, CancellationToken cancellationToken)
 {
     return(_checksumTree.GetOrCreateAsset(document, GetInfo(document), WellKnownChecksumObjects.DocumentChecksumObjectInfo, CreateDocumentChecksumObjectInfo, cancellationToken));
 }
Esempio n. 31
0
 /// <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));
 }
Esempio n. 32
0
 /// <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));
 }
Esempio n. 33
0
 public SourceTextAsset(Checksum checksum, TextDocumentState state, Serializer serializer) :
     base(checksum, WellKnownSynchronizationKinds.SourceText)
 {
     _state = state;
     _serializer = serializer;
 }
Esempio n. 34
0
 public static bool IsRazorDocument(this TextDocumentState documentState)
 => documentState.Services.GetService <DocumentPropertiesService>()?.DiagnosticsLspClientName == RazorCSharpLspClientName;