public void SetSearchPaths(IEnumerable <string> searchPaths) => _analyzer.SetSearchPaths(searchPaths.MaybeEnumerate());
public void SetSearchPaths(params string[] paths) { _analyzer.SetSearchPaths(paths); }
private IEnumerable <Task> StartCrossThreadAnalysisCalls(PythonAnalyzer state, CancellationToken cancel) { const string testCode = @"from mod{0:000} import test_func as other_test_func, MyClass as other_mc c = None def test_func(a, b={1}()): '''My test function''' globals c a = b a = {1}(a) b = other_test_func(a) c = other_mc.fn(b) return b class MyClass: fn = test_func my_test_func = test_func my_test_func = other_test_func my_test_func('abc') mc = MyClass() mc.fn([]) "; state.SetSearchPaths(new [] { TestData.GetTestSpecificRootUri().ToAbsolutePath() }); var entries = Enumerable.Range(0, 100) .Select(i => { var entry = (ProjectEntry)state.AddModule(string.Format("mod{0:000}", i), TestData.GetTestSpecificPath(string.Format("mod{0:000}.py", i))); var parser = Parser.CreateParser(new StringReader(testCode.FormatInvariant(i + 1, PythonTypes[i % PythonTypes.Count])), PythonLanguageVersion.V34); using (var p = entry.BeginParse()) { p.Tree = parser.ParseFile(); p.Complete(); } return(entry); }) .ToList(); // One analysis before we start foreach (var e in entries) { e.Analyze(cancel, true); } state.AnalyzeQueuedEntries(cancel); // Repeatedly re-analyse the code yield return(Task.Run(() => { var rnd = new Random(); while (!cancel.IsCancellationRequested) { var shufEntries = entries .Select(e => Tuple.Create(rnd.Next(), e)) .OrderBy(t => t.Item1) .Take(entries.Count / 2) .Select(t => t.Item2) .ToList(); foreach (var e in shufEntries) { e.Analyze(cancel, true); } state.AnalyzeQueuedEntries(cancel); Console.WriteLine("Analysis complete"); Thread.Sleep(1000); } }, cancel)); // Repeatedly re-parse the code yield return(Task.Run(() => { var rnd = new Random(); while (!cancel.IsCancellationRequested) { var shufEntries = entries .Select((e, i) => Tuple.Create(rnd.Next(), e, i)) .OrderBy(t => t.Item1) .Take(entries.Count / 4) .ToList(); foreach (var t in shufEntries) { var i = t.Item3; var parser = Parser.CreateParser(new StringReader(testCode.FormatInvariant(i + 1, PythonTypes[i % PythonTypes.Count])), PythonLanguageVersion.V34); using (var p = t.Item2.BeginParse()) { p.Tree = parser.ParseFile(); p.Complete(); } } Thread.Sleep(1000); } }, cancel)); // Repeatedly request signatures yield return(Task.Run(() => { var entry = entries[1]; while (!cancel.IsCancellationRequested) { var sigs = entry.Analysis.GetSignaturesByIndex("my_test_func", 0).ToList(); if (sigs.Any()) { foreach (var s in sigs) { s.Name.Should().Be("test_func"); s.Parameters.Select(p => p.Name).Should().BeEquivalentTo("a", "b"); } } } }, cancel)); // Repeated request variables and descriptions yield return(Task.Run(() => { var entry = entries[1]; while (!cancel.IsCancellationRequested) { var descriptions = entry.Analysis.GetDescriptionsByIndex("my_test_func", 0).ToList(); descriptions = entry.Analysis.GetDescriptionsByIndex("c", 0).ToList(); } }, cancel)); // Repeated request members and documentation yield return(Task.Run(() => { var entry = entries[1]; while (!cancel.IsCancellationRequested) { var descriptions = entry.Analysis.GetCompletionDocumentationByIndex("mc", "fn", 0).ToList(); } }, cancel)); }