예제 #1
0
        private static TreeAndVersion CreateTreeAndVersion(
            ValueSource <TextAndVersion> newTextSource,
            ProjectId cacheKey,
            string filePath,
            ParseOptions options,
            AnalyzerConfigSet analyzerConfigSet,
            HostLanguageServices languageServices,
            PreservationMode mode,
            TextAndVersion textAndVersion,
            CancellationToken cancellationToken)
        {
            var text = textAndVersion.Text;

            var treeFactory = languageServices.GetService <ISyntaxTreeFactoryService>();

            var treeDiagnosticOptions = filePath != null?analyzerConfigSet.GetOptionsForSourcePath(filePath).TreeOptions : null;

            var tree = treeFactory.ParseSyntaxTree(filePath, options, text, treeDiagnosticOptions, cancellationToken);

            var root = tree.GetRoot(cancellationToken);

            if (mode == PreservationMode.PreserveValue && treeFactory.CanCreateRecoverableTree(root))
            {
                tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, text.Encoding, root);
            }

            Contract.ThrowIfNull(tree);
            CheckTree(tree, text);

            // text version for this document should be unique. use it as a starting point.
            return(TreeAndVersion.Create(tree, textAndVersion.Version));
        }
예제 #2
0
        private static ValueSource <AnalyzerConfigSet> ComputeAnalyzerConfigSetValueSource(IEnumerable <AnalyzerConfigDocumentState> analyzerConfigDocumentStates)
        {
            return(new AsyncLazy <AnalyzerConfigSet>(
                       asynchronousComputeFunction: async cancellationToken =>
            {
                var tasks = analyzerConfigDocumentStates.Select(a => a.GetAnalyzerConfigAsync(cancellationToken));
                var analyzerConfigs = await Task.WhenAll(tasks).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();

                return AnalyzerConfigSet.Create(analyzerConfigs);
            },
                       synchronousComputeFunction: cancellationToken =>
            {
                var analyzerConfigs = analyzerConfigDocumentStates.SelectAsArray(a => a.GetAnalyzerConfig(cancellationToken));
                return AnalyzerConfigSet.Create(analyzerConfigs);
            },
                       cacheResult: true));
        }
예제 #3
0
 public CachingAnalyzerConfigSet(AnalyzerConfigSet underlyingSet)
 {
     _underlyingSet   = underlyingSet;
     _computeFunction = _underlyingSet.GetOptionsForSourcePath;
 }