private IDocumentAnalysis TryRestoreCachedAnalysis(IDependencyChainNode <PythonAnalyzerEntry> node, IPythonModule module)
        {
            var moduleType = module.ModuleType;

            if (moduleType.CanBeCached() && _moduleDatabaseService?.ModuleExistsInStorage(module.Name, module.FilePath) == true)
            {
                if (_moduleDatabaseService.TryRestoreGlobalScope(module, out var gs))
                {
                    if (_log != null)
                    {
                        _log.Log(TraceEventType.Verbose, "Restored from database: ", module.Name);
                    }
                    var analysis = new DocumentAnalysis((IDocument)module, 1, gs, new ExpressionEval(_services, module, module.GetAst()), Array.Empty <string>());
                    gs.ReconstructVariables();
                    MarkNodeWalked(node);
                    return(analysis);
                }
                else
                {
                    if (_log != null)
                    {
                        _log.Log(TraceEventType.Verbose, "Restore from database failed for module ", module.Name);
                    }
                }
            }
            return(null);
        }
        private void AnalyzeEntry(PythonAnalyzerEntry entry, IPythonModule module, PythonAst ast, int version)
        {
            // Now run the analysis.
            var analyzable = module as IAnalyzable;

            analyzable?.NotifyAnalysisBegins();

            var walker = new ModuleWalker(_services, module, ast);

            ast.Walk(walker);

            _analyzerCancellationToken.ThrowIfCancellationRequested();

            walker.Complete();
            _analyzerCancellationToken.ThrowIfCancellationRequested();
            var analysis = new DocumentAnalysis((IDocument)module, version, walker.GlobalScope, walker.Eval, walker.StarImportMemberNames);

            analyzable?.NotifyAnalysisComplete(analysis);
            entry.TrySetAnalysis(analysis, version);

            if (module.ModuleType == ModuleType.User)
            {
                var linterDiagnostics = _analyzer.LintModule(module);
                _diagnosticsService?.Replace(entry.Module.Uri, linterDiagnostics, DiagnosticSource.Linter);
            }
        }