示例#1
0
        internal static ImmutableArray <IDiagnosticAnalyzer> GetOrCreateAnalyzersFromFile(AnalyzerFileReference analyzerReference)
        {
            string fullPath = analyzerReference.FullPath;

            Debug.Assert(PathUtilities.IsAbsolute(fullPath));

            lock (Guard)
            {
                // may throw:
                FileKey key = FileKey.Create(fullPath);

                CachedAnalyzers cachedAnalyzers;
                if (analyzersFromFiles.TryGetValue(key, out cachedAnalyzers) && cachedAnalyzers.Analyzers.IsAlive)
                {
                    return((ImmutableArray <IDiagnosticAnalyzer>)cachedAnalyzers.Analyzers.Target);
                }

                // get all analyzers in the assembly:
                var builder = ImmutableArray.CreateBuilder <IDiagnosticAnalyzer>();
                analyzerReference.AddAnalyzers(builder, null, null);
                var analyzers = builder.ToImmutable();

                // refresh the timestamp (the file may have changed just before we memory-mapped it):
                key = FileKey.Create(fullPath);

                analyzersFromFiles[key] = new CachedAnalyzers(analyzers);
                analyzerAssemblyKeys.Add(key);
                EnableCompactTimer();

                return(analyzers);
            }
        }
示例#2
0
        private static void CacheAnalyzers(string langauge, string fullPath, ImmutableArray <DiagnosticAnalyzer> analyzers)
        {
            // refresh the timestamp (the file may have changed just before we memory-mapped it):
            var key = FileKey.Create(fullPath);

            s_analyzersFromFiles[key] = new CachedAnalyzers(analyzers, langauge);
            Debug.Assert(!s_analyzerAssemblyKeys.Contains(key));

            s_analyzerAssemblyKeys.Add(key);
        }
示例#3
0
        private static void CacheAnalyzers(string langauge, string fullPath, ImmutableArray<DiagnosticAnalyzer> analyzers)
        {
            // refresh the timestamp (the file may have changed just before we memory-mapped it):
            var key = FileKey.Create(fullPath);

            s_analyzersFromFiles[key] = new CachedAnalyzers(analyzers, langauge);
            Debug.Assert(!s_analyzerAssemblyKeys.Contains(key));

            s_analyzerAssemblyKeys.Add(key);
        }
示例#4
0
        internal static ImmutableArray<IDiagnosticAnalyzer> GetOrCreateAnalyzersFromFile(AnalyzerFileReference analyzerReference)
        {
            string fullPath = analyzerReference.FullPath;
            Debug.Assert(PathUtilities.IsAbsolute(fullPath));

            lock (Guard)
            {
                // may throw:
                FileKey key = FileKey.Create(fullPath);

                CachedAnalyzers cachedAnalyzers;
                if (analyzersFromFiles.TryGetValue(key, out cachedAnalyzers) && cachedAnalyzers.Analyzers.IsAlive)
                {
                    return (ImmutableArray<IDiagnosticAnalyzer>)cachedAnalyzers.Analyzers.Target;
                }

                // get all analyzers in the assembly:
                var builder = ImmutableArray.CreateBuilder<IDiagnosticAnalyzer>();
                analyzerReference.AddAnalyzers(builder, null, null);
                var analyzers = builder.ToImmutable();

                // refresh the timestamp (the file may have changed just before we memory-mapped it):
                key = FileKey.Create(fullPath);

                analyzersFromFiles[key] = new CachedAnalyzers(analyzers);
                analyzerAssemblyKeys.Add(key);
                EnableCompactTimer();

                return analyzers;
            }
        }