protected IEnumerable <MemberResult> GetModules(string[] package, bool modulesOnly = true) { var analysis = GetAnalysisEntry(); if (analysis == null) { return(Enumerable.Empty <MemberResult>()); } IPythonReplIntellisense pyReplEval = null; IReplEvaluator eval; if (TextBuffer.Properties.TryGetProperty <IReplEvaluator>(typeof(IReplEvaluator), out eval)) { pyReplEval = eval as IPythonReplIntellisense; } IEnumerable <KeyValuePair <string, bool> > replScopes = null; if (pyReplEval != null) { replScopes = pyReplEval.GetAvailableScopesAndKind(); } if (package == null) { package = new string[0]; } var modules = Enumerable.Empty <MemberResult>(); if (analysis != null && (pyReplEval == null || !pyReplEval.LiveCompletionsOnly)) { modules = modules.Concat(package.Length > 0 ? analysis.GetModuleMembers(package, !modulesOnly) : analysis.GetModules(true).Distinct(CompletionComparer.MemberEquality) ); } if (replScopes != null) { modules = GetModulesFromReplScope(replScopes, package) .Concat(modules) .Distinct(CompletionComparer.MemberEquality); } return(modules); }
public override CompletionSet GetCompletions(IGlyphService glyphService) { var start1 = _stopwatch.ElapsedMilliseconds; IEnumerable <CompletionResult> members = null; IEnumerable <CompletionResult> replMembers = null; IInteractiveEvaluator eval; IPythonReplIntellisense pyReplEval = null; if (_snapshot.TextBuffer.Properties.TryGetProperty(typeof(IInteractiveEvaluator), out eval)) { pyReplEval = eval as IPythonReplIntellisense; } var analysis = GetAnalysisEntry(); string text; SnapshotSpan statementRange; if (!GetPrecedingExpression(out text, out statementRange)) { return(null); } else if (string.IsNullOrEmpty(text)) { if (analysis != null) { lock (_analyzer) { var location = VsProjectAnalyzer.TranslateIndex( statementRange.Start.Position, statementRange.Snapshot, analysis ); var parameters = Enumerable.Empty <CompletionResult>(); var sigs = VsProjectAnalyzer.GetSignaturesAsync(_serviceProvider, _snapshot, Span).WaitOrDefault(1000); if (sigs != null && sigs.Signatures.Any()) { parameters = sigs.Signatures .SelectMany(s => s.Parameters) .Select(p => p.Name) .Distinct() .Select(n => new CompletionResult(n, PythonMemberType.Field)); } members = (analysis.Analyzer.GetAllAvailableMembersAsync(analysis, location, _options.MemberOptions).WaitOrDefault(1000) ?? new CompletionResult[0]) .Union(parameters, CompletionComparer.MemberEquality); } } if (pyReplEval != null) { replMembers = pyReplEval.GetMemberNames(string.Empty); } } else { if (analysis != null && (pyReplEval == null || !pyReplEval.LiveCompletionsOnly)) { lock (_analyzer) { var location = VsProjectAnalyzer.TranslateIndex( statementRange.Start.Position, statementRange.Snapshot, analysis ); members = analysis.Analyzer.GetMembersAsync(analysis, text, location, _options.MemberOptions).WaitOrDefault(1000); } } if (pyReplEval != null && _snapshot.TextBuffer.GetAnalyzer(_serviceProvider).ShouldEvaluateForCompletion(text)) { replMembers = pyReplEval.GetMemberNames(text); } } if (replMembers != null) { if (members != null) { members = members.Union(replMembers, CompletionComparer.MemberEquality); } else { members = replMembers; } } var end = _stopwatch.ElapsedMilliseconds; if (/*Logging &&*/ (end - start1) > TooMuchTime) { if (members != null) { var memberArray = members.ToArray(); members = memberArray; Trace.WriteLine(String.Format("{0} lookup time {1} for {2} members", this, end - start1, members.Count())); } else { Trace.WriteLine(String.Format("{0} lookup time {1} for zero members", this, end - start1)); } } if (members == null) { // The expression is invalid so we shouldn't provide // a completion set at all. return(null); } var start = _stopwatch.ElapsedMilliseconds; var result = new FuzzyCompletionSet( "Python", "Python", Span, members.Select(m => PythonCompletion(glyphService, m)), _options, CompletionComparer.UnderscoresLast, matchInsertionText: true ); end = _stopwatch.ElapsedMilliseconds; if (/*Logging &&*/ (end - start1) > TooMuchTime) { Trace.WriteLine(String.Format("{0} completion set time {1} total time {2}", this, end - start, end - start1)); } return(result); }