Beispiel #1
0
        internal static async Task <ImmutableArray <SyntaxToken> > GetIdentifierOrGlobalNamespaceTokensWithTextAsync(
            this Document document, SemanticModel model, string identifier, CancellationToken cancellationToken)
        {
            // It's very costly to walk an entire tree.  So if the tree is simple and doesn't contain
            // any unicode escapes in it, then we do simple string matching to find the tokens.
            var info = await SyntaxTreeIndex.GetIndexAsync(document, cancellationToken).ConfigureAwait(false);

            if (!info.ProbablyContainsIdentifier(identifier))
            {
                return(ImmutableArray <SyntaxToken> .Empty);
            }

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            if (syntaxFacts == null)
            {
                return(ImmutableArray <SyntaxToken> .Empty);
            }

            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var version = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);

            SourceText text = null;

            if (!info.ProbablyContainsEscapedIdentifier(identifier))
            {
                text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
            }

            return(FindReferenceCache.GetIdentifierOrGlobalNamespaceTokensWithText(syntaxFacts, document, version, model, root, text, identifier, cancellationToken));
        }
        private static async Task<bool> SaveAsync(
            Document document, string persistenceName, string formatVersion, SyntaxTreeIndex data, CancellationToken cancellationToken)
        {
            Contract.Requires(!await document.IsForkedDocumentWithSyntaxChangesAsync(cancellationToken).ConfigureAwait(false));

            var persistentStorageService = document.Project.Solution.Workspace.Services.GetService<IPersistentStorageService>();

            try
            {
                using (var storage = persistentStorageService.GetStorage(document.Project.Solution))
                using (var stream = SerializableBytes.CreateWritableStream())
                using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
                {
                    data.WriteVersion(writer, formatVersion);
                    data.WriteTo(writer);

                    stream.Position = 0;
                    return await storage.WriteStreamAsync(document, persistenceName, stream, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception e) when (IOUtilities.IsNormalIOException(e))
            {
                // Storage APIs can throw arbitrary exceptions.
            }

            return false;
        }
Beispiel #3
0
        private static async Task <bool> SaveAsync(
            Document document, string persistenceName, string formatVersion, SyntaxTreeIndex data, CancellationToken cancellationToken)
        {
            Contract.Requires(!await document.IsForkedDocumentWithSyntaxChangesAsync(cancellationToken).ConfigureAwait(false));

            var persistentStorageService = document.Project.Solution.Workspace.Services.GetService <IPersistentStorageService>();

            try
            {
                using (var storage = persistentStorageService.GetStorage(document.Project.Solution))
                    using (var stream = SerializableBytes.CreateWritableStream())
                        using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
                        {
                            data.WriteVersion(writer, formatVersion);
                            data.WriteTo(writer);

                            stream.Position = 0;
                            return(await storage.WriteStreamAsync(document, persistenceName, stream, cancellationToken).ConfigureAwait(false));
                        }
            }
            catch (Exception e) when(IOUtilities.IsNormalIOException(e))
            {
                // Storage APIs can throw arbitrary exceptions.
            }

            return(false);
        }
Beispiel #4
0
        private async Task ProcessDocumentWorkerAsync(Document document)
        {
            var index = await SyntaxTreeIndex.GetIndexAsync(
                document, _cancellationToken).ConfigureAwait(false);

            if (_searchKind == SearchKind.StringLiterals)
            {
                if (index.ProbablyContainsStringValue(_stringValue))
                {
                    await SearchDocumentAsync(document).ConfigureAwait(false);
                }
            }
            else if (index.ProbablyContainsInt64Value(_longValue))
            {
                await SearchDocumentAsync(document).ConfigureAwait(false);
            }
        }
        protected static Task <TIndex?> LoadAsync(
            Document document,
            Checksum checksum,
            IndexReader read,
            CancellationToken cancellationToken)
        {
            var storageService = document.Project.Solution.Workspace.Services.GetPersistentStorageService();

            return(LoadAsync(storageService, DocumentKey.ToDocumentKey(document), checksum, SyntaxTreeIndex.GetStringTable(document.Project), read, cancellationToken));
        }