Example #1
0
        public override CompletionSet GetCompletions(IGlyphService glyphService)
        {
            var start = _stopwatch.ElapsedMilliseconds;

            var completions = GetModules(glyphService, Text);
            var res         = new PythonCompletionSet(Text, Text, Span, completions, new Completion[0]);

            var end = _stopwatch.ElapsedMilliseconds;

            if (/*Logging &&*/ end - start > TooMuchTime)
            {
                Trace.WriteLine(String.Format("{0} lookup time {1} for {2} imports", this, end - start, res.Completions.Count));
            }

            return(res);
        }
Example #2
0
        public override CompletionSet GetCompletions(IGlyphService glyphService)
        {
            var start1 = _stopwatch.ElapsedMilliseconds;

            MemberResult[] members;

            IReplEvaluator      eval;
            PythonReplEvaluator dlrEval = null;

            if (_snapshot.TextBuffer.Properties.TryGetProperty <IReplEvaluator>(typeof(IReplEvaluator), out eval))
            {
                dlrEval = eval as PythonReplEvaluator;
            }

            var analysis = GetAnalysisEntry();

            if (analysis != null)
            {
                members = analysis.GetMembers(
                    Text,
                    _snapshot.GetLineNumberFromPosition(_pos) + 1,
                    _intersectMembers).ToArray();
            }
            else
            {
                members = new MemberResult[0];
            }

            if (dlrEval != null && _snapshot.TextBuffer.GetAnalyzer().ShouldEvaluateForCompletion(Text))
            {
                string text = Text;
                if (Text.EndsWith("."))
                {
                    text = Text.Substring(0, Text.Length - 1);
                }

                if (members.Length == 0)
                {
                    members = dlrEval.GetMemberNames(TextBuffer.GetAnalyzer(), text);
                    if (members == null)
                    {
                        members = new MemberResult[0];
                    }
                }
                else
                {
                    // prefer analysis members over live members but merge the two together.
                    Dictionary <string, MemberResult> memberDict = new Dictionary <string, MemberResult>();
                    var replMembers = dlrEval.GetMemberNames(TextBuffer.GetAnalyzer(), text);
                    if (replMembers != null)
                    {
                        foreach (var member in replMembers)
                        {
                            memberDict[member.Name] = member;
                        }

                        foreach (var member in members)
                        {
                            memberDict[member.Name] = member;
                        }

                        members = memberDict.Values.ToArray();
                    }
                }
            }

            members = DoFilterCompletions(members);
            Array.Sort(members, ModuleSort);

            var end = _stopwatch.ElapsedMilliseconds;

            if (/*Logging &&*/ (end - start1) > TooMuchTime)
            {
                Trace.WriteLine(String.Format("{0} lookup time {1} for {2} members", this, end - start1, members.Length));
            }

            var start = _stopwatch.ElapsedMilliseconds;

            var result = new PythonCompletionSet(
                Text,
                Text,
                _snapshot.CreateTrackingSpan(_pos, 0, SpanTrackingMode.EdgeInclusive),
                TransformMembers(glyphService, members),
                new Completion[0]);

            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);
        }