public static LocationInfo GetLocation(this Node node, IPythonModule module) { if (node == null || node.StartIndex >= node.EndIndex) { return(LocationInfo.Empty); } var start = node.GetStart(module.GetAst()); var end = node.GetEnd(module.GetAst()); return(new LocationInfo(module.FilePath, module.Uri, start.Line, start.Column, end.Line, end.Column)); }
private void AnalyzeEntry(PythonAnalyzerEntry entry, IPythonModule module, int version, bool isFinalPass) { if (entry.PreviousAnalysis is LibraryAnalysis) { _log?.Log(TraceEventType.Verbose, $"Request to re-analyze finalized {module.Name}."); } // Now run the analysis. var analyzable = module as IAnalyzable; analyzable?.NotifyAnalysisBegins(); var ast = module.GetAst(); var walker = new ModuleWalker(_services, module); ast.Walk(walker); _analyzerCancellationToken.ThrowIfCancellationRequested(); walker.Complete(); _analyzerCancellationToken.ThrowIfCancellationRequested(); analyzable?.NotifyAnalysisComplete(version, walker, isFinalPass); entry.TrySetAnalysis(module.Analysis, version); if (module.ModuleType == ModuleType.User) { var linterDiagnostics = _analyzer.LintModule(module); _diagnosticsService?.Replace(entry.Module.Uri, linterDiagnostics, DiagnosticSource.Linter); } }
public ExpressionEval(IServiceContainer services, IPythonModule module, GlobalScope gs) { Services = services ?? throw new ArgumentNullException(nameof(services)); Module = module ?? throw new ArgumentNullException(nameof(module)); Ast = module.GetAst(); GlobalScope = gs; CurrentScope = GlobalScope; DefaultLocation = new Location(module); //Log = services.GetService<ILogger>(); }
public bool IsValidVersion(int version, out IPythonModule module, out PythonAst ast) { lock (_syncObj) { module = _module; ast = module.GetAst(); if (ast == null || module == null) { return(false); } return(_previousAnalysis is EmptyAnalysis || _isUserModule || _analysisVersion <= version); } }
private HashSet <AnalysisModuleKey> FindDependencies(IPythonModule module, int bufferVersion) { if (_bufferVersion > bufferVersion) { return(new HashSet <AnalysisModuleKey>()); } var walker = new DependencyWalker(module); module.GetAst().Walk(walker); var dependencies = walker.Dependencies; dependencies.Remove(new AnalysisModuleKey(module)); return(dependencies); }
/// <summary> /// Returns the string line corresponding to the given line number /// </summary> /// <param name="lineNum">The line number</param> internal static string GetLine(this IPythonModule module, int lineNum) { string content = module.Analysis?.Document?.Content; if (string.IsNullOrEmpty(content)) { return(string.Empty); } SourceLocation source = new SourceLocation(lineNum, 1); var start = module.GetAst().LocationToIndex(source); var end = start; for (; end < content.Length && content[end] != '\n' && content[end] != '\r'; end++) { ; } return(content.Substring(start, end - start).Trim('\t', ' ')); }
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); }
public DependencyWalker(IPythonModule module, PythonAst ast = null) { _dependencyCollector = new DependencyCollector(module); ast = ast ?? module.GetAst(); ast.Walk(this); }