public override async Task DidChangeConfiguration(DidChangeConfigurationParams @params) { if (_analyzer == null) { LogMessage(MessageType.Error, "change configuration notification sent to uninitialized server"); return; } await _analyzer.ReloadModulesAsync(); // re-analyze all of the modules when we get a new set of modules loaded... foreach (var entry in _analyzer.ModulesByFilename) { _queue.Enqueue(entry.Value.ProjectEntry, AnalysisPriority.Normal); } }
public void Analyze(CancellationToken cancel) { if (cancel.IsCancellationRequested) { return; } var currentTcs = Interlocked.Exchange(ref _tcs, new TaskCompletionSource <bool>()); try { _analyzer.ReloadModulesAsync(cancel).WaitAndUnwrapExceptions(); currentTcs.TrySetResult(true); } catch (OperationCanceledException oce) { currentTcs.TrySetCanceled(oce.CancellationToken); } catch (Exception ex) { currentTcs.TrySetException(ex); } }
private SaveLoadResult SaveLoad(PythonLanguageVersion version, params AnalysisModule[] modules) { IPythonProjectEntry[] entries = new IPythonProjectEntry[modules.Length]; var fact = InterpreterFactory; var interp = Interpreter; if (version != fact.GetLanguageVersion()) { fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()); interp = fact.CreateInterpreter(); } var state = new PythonAnalyzer(fact, interp, SharedDatabaseState.BuiltinName2x); state.ReloadModulesAsync().WaitAndUnwrapExceptions(); for (int i = 0; i < modules.Length; i++) { entries[i] = state.AddModule(modules[i].ModuleName, modules[i].Filename); Prepare(entries[i], new StringReader(modules[i].Code), version); } for (int i = 0; i < modules.Length; i++) { entries[i].Analyze(CancellationToken.None); } string tmpFolder = TestData.GetTempPath("6666d700-a6d8-4e11-8b73-3ba99a61e27b"); Directory.CreateDirectory(tmpFolder); new SaveAnalysis().Save(state, tmpFolder); File.Copy(Path.Combine(PythonTypeDatabase.BaselineDatabasePath, "__builtin__.idb"), Path.Combine(tmpFolder, "__builtin__.idb"), true); return(new SaveLoadResult( PythonAnalyzer.CreateSynchronously(InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion(), null, tmpFolder)), tmpFolder )); }
internal PythonAnalyzer AnalyzeDir(string dir, PythonLanguageVersion version = PythonLanguageVersion.V27, IEnumerable <string> excludeDirectories = null, CancellationToken?cancel = null) { List <string> files = new List <string>(); try { ISet <string> excluded = null; if (excludeDirectories != null) { excluded = new HashSet <string>(excludeDirectories, StringComparer.InvariantCultureIgnoreCase); } CollectFiles(dir, files, excluded); } catch (DirectoryNotFoundException) { return(null); } List <FileStreamReader> sourceUnits = new List <FileStreamReader>(); foreach (string file in files) { sourceUnits.Add( new FileStreamReader(file) ); } Stopwatch sw = new Stopwatch(); sw.Start(); long start0 = sw.ElapsedMilliseconds; var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()); var projectState = new PythonAnalyzer(fact, fact.CreateInterpreter()); projectState.ReloadModulesAsync().WaitAndUnwrapExceptions(); projectState.Limits = AnalysisLimits.GetStandardLibraryLimits(); var modules = new List <IPythonProjectEntry>(); foreach (var sourceUnit in sourceUnits) { try { modules.Add(projectState.AddModule( ModulePath.FromFullPath(sourceUnit.Path).ModuleName, sourceUnit.Path, null )); } catch (ArgumentException) { // Invalid module name, so skip the module } } long start1 = sw.ElapsedMilliseconds; Trace.TraceInformation("AddSourceUnit: {0} ms", start1 - start0); var nodes = new List <Microsoft.PythonTools.Parsing.Ast.PythonAst>(); for (int i = 0; i < modules.Count; i++) { PythonAst ast = null; try { var sourceUnit = sourceUnits[i]; ast = Parser.CreateParser(sourceUnit, version).ParseFile(); } catch (Exception) { } nodes.Add(ast); } long start2 = sw.ElapsedMilliseconds; Trace.TraceInformation("Parse: {0} ms", start2 - start1); for (int i = 0; i < modules.Count; i++) { var ast = nodes[i]; if (ast != null) { using (var p = modules[i].BeginParse()) { p.Tree = ast; p.Complete(); } } } long start3 = sw.ElapsedMilliseconds; for (int i = 0; i < modules.Count; i++) { Trace.TraceInformation("Analyzing {1}: {0} ms", sw.ElapsedMilliseconds - start3, sourceUnits[i].Path); var ast = nodes[i]; if (ast != null) { modules[i].Analyze(cancel ?? CancellationToken.None, true); } } if (modules.Count > 0) { Trace.TraceInformation("Analyzing queue"); modules[0].AnalysisGroup.AnalyzeQueuedEntries(cancel ?? CancellationToken.None); } long start4 = sw.ElapsedMilliseconds; Trace.TraceInformation("Analyze: {0} ms", start4 - start3); return(projectState); }