public static void DoTriggerCompletion(IntellisenseController controller, CompletionInfoType infoType, bool signatureHelpOnly, IntellisenseInvocationType invocationType)
        {
            Contract.Requires<ArgumentNullException>(controller != null, "controller");

            var completionInfo = controller.CompletionInfo;
            ITextView textView = controller.TextView;
            SnapshotPoint? point = textView.Caret.Position.Point.GetPoint(textView.TextBuffer, PositionAffinity.Predecessor);
            if (point.HasValue)
            {
                ITrackingPoint trackingPoint = textView.TextBuffer.CurrentSnapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
                if (!signatureHelpOnly)
                {
                    controller.TriggerCompletion(trackingPoint, infoType, invocationType);
                    DoCallMatch(controller);
                }

                if (signatureHelpOnly /*|| (completionInfo.CompletionFlags & CompletionFlags.HasParameterInfo) != 0*/)
                {
                    controller.TriggerSignatureHelp(trackingPoint);
                }

                if (controller.CompletionSession != null)
                {
                    controller.IntellisenseSessionStack.MoveSessionToTop(controller.CompletionSession);
                }
            }
        }
        public virtual void TriggerCompletion(ITrackingPoint triggerPoint, CompletionInfoType completionInfoType, IntellisenseInvocationType intellisenseInvocationType)
        {
            DismissCompletion();
            CompletionInfo.InfoType       = completionInfoType;
            CompletionInfo.InvocationType = intellisenseInvocationType;
            ICompletionSession session = Provider.CompletionBroker.TriggerCompletion(TextView, triggerPoint, true);

            if (session != null)
            {
                session.Committed += HandleCompletionCommitted;
                session.Dismissed += HandleCompletionDismissed;
                CompletionSession  = session;

                if (completionInfoType == CompletionInfoType.GlobalInfo &&
                    !session.IsDismissed &&
                    session.SelectedCompletionSet.SelectionStatus.IsSelected &&
                    session.SelectedCompletionSet.SelectionStatus.IsUnique)
                {
                    session.Commit();
                }
            }
        }
Exemple #3
0
        public override void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (session == null || completionSets == null)
            {
                return;
            }

            ITrackingPoint triggerPoint = session.GetTriggerPoint(TextBuffer);

            if (triggerPoint != null)
            {
                IntellisenseController controller     = GetControllerForView(session.TextView);
                CompletionInfo         completionInfo = controller.CompletionInfo;
                ITextSnapshot          snapshot       = triggerPoint.TextBuffer.CurrentSnapshot;
                SnapshotPoint          point          = triggerPoint.GetPoint(snapshot);
                bool extendLeft = false;
                bool extend     = true;

                // labels includes both implicit and explicit labels
                var labels = FindLabelsInScope(point);

                IntellisenseInvocationType invocationType = completionInfo.InvocationType;
                CompletionInfoType         infoType       = completionInfo.InfoType;

                switch (invocationType)
                {
                case IntellisenseInvocationType.Default:
                    extend = infoType == CompletionInfoType.GlobalInfo;
                    break;

                case IntellisenseInvocationType.BackspaceDeleteOrBackTab:
                case IntellisenseInvocationType.IdentifierChar:
                case IntellisenseInvocationType.Sharp:
                case IntellisenseInvocationType.Space:
                case IntellisenseInvocationType.ShowMemberList:
                    break;

                default:
                    extendLeft = true;
                    break;
                }

                TextExtent extentOfWord = default(TextExtent);
                if (extend)
                {
                    ITextBuffer             textBuffer      = TextBuffer;
                    ITextStructureNavigator navigator       = TextStructureNavigatorSelectorService.CreateTextStructureNavigator(textBuffer, textBuffer.ContentType);
                    SnapshotPoint           currentPosition = new SnapshotPoint(snapshot, triggerPoint.GetPosition(snapshot));
                    extentOfWord = navigator.GetExtentOfWord(currentPosition);
                    if (extentOfWord.Span.Start == point)
                    {
                        TextExtent extentOfPreviousWord = navigator.GetExtentOfWord(currentPosition - 1);
                        if (extentOfPreviousWord.IsSignificant && extentOfPreviousWord.Span.End == point && IsCompletionPrefix(extentOfPreviousWord))
                        {
                            extentOfWord = extentOfPreviousWord;
                        }
                        else
                        {
                            extend = false;
                        }
                    }
                }

                if (!extend || !extentOfWord.IsSignificant)
                {
                    SnapshotSpan span = new SnapshotSpan(point, 0);
                    extentOfWord = new TextExtent(span, false);
                }

                if (invocationType == IntellisenseInvocationType.BackspaceDeleteOrBackTab && extentOfWord.Span.Length > 0)
                {
                    string str3 = snapshot.GetText(extentOfWord.Span);
                    if (!string.IsNullOrWhiteSpace(str3))
                    {
                        while (CommitCharacters.IndexOf(str3[0]) > 0)
                        {
                            SnapshotSpan span2 = extentOfWord.Span;
                            SnapshotSpan span3 = new SnapshotSpan(snapshot, span2.Start + 1, span2.Length - 1);
                            extentOfWord = new TextExtent(span3, false);
                            str3         = snapshot.GetText(extentOfWord.Span);
                            if (string.IsNullOrEmpty(str3))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        SnapshotSpan span4 = new SnapshotSpan(snapshot, extentOfWord.Span.End, 0);
                        extentOfWord = new TextExtent(span4, false);
                        completionInfo.InvocationType = IntellisenseInvocationType.Default;
                    }
                }

                if (completionInfo.InfoType == CompletionInfoType.AutoListMemberInfo && extentOfWord.Span.GetText().StartsWith("$") && labels.Count == 0)
                {
                    session.Dismiss();
                    return;
                }

                ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extentOfWord.Span, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
                if (extendLeft)
                {
                    SnapshotSpan textSoFarSpan = new SnapshotSpan(snapshot, extentOfWord.Span.Start, triggerPoint.GetPoint(snapshot));
                    string       textSoFar     = textSoFarSpan.GetText();
                    applicableTo = snapshot.CreateTrackingSpan(point.Position - textSoFar.Length, textSoFar.Length, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
                }

                IEnumerable <Completion> context          = GetContextCompletions(triggerPoint.GetPoint(snapshot), (AntlrIntellisenseController)controller, session);
                IEnumerable <Completion> keywords         = GetKeywordCompletions();
                IEnumerable <Completion> snippets         = GetSnippetCompletions();
                IEnumerable <Completion> labelCompletions = GetLabelCompletions(labels);
                //SnapshotSpan? Provider.IntellisenseCache.GetExpressionSpan(triggerPoint.GetPoint(snapshot));

                IEnumerable <Completion> completions        = context.Concat(keywords).Concat(snippets).Concat(labelCompletions);
                IEnumerable <Completion> orderedCompletions = completions.Distinct(CompletionDisplayNameComparer.CurrentCulture).OrderBy(i => i.DisplayText, StringComparer.CurrentCultureIgnoreCase);

                CompletionSet completionSet = new CompletionSet("AntlrCompletions", "Antlr Completions", applicableTo, orderedCompletions, EmptyCompletions);
                completionSets.Add(completionSet);
            }
        }
Exemple #4
0
 void ITvlIntellisenseController.TriggerCompletion(ITrackingPoint triggerPoint, CompletionInfoType completionInfoType, IntellisenseInvocationType intellisenseInvocationType)
 {
     Contract.Requires <ArgumentNullException>(triggerPoint != null, "triggerPoint");
     throw new NotImplementedException();
 }
        public virtual void TriggerCompletion(ITrackingPoint triggerPoint, CompletionInfoType completionInfoType, IntellisenseInvocationType intellisenseInvocationType)
        {
            DismissCompletion();
            CompletionInfo.InfoType = completionInfoType;
            CompletionInfo.InvocationType = intellisenseInvocationType;
            ICompletionSession session = Provider.CompletionBroker.TriggerCompletion(TextView, triggerPoint, true);
            if (session != null)
            {
                session.Committed += HandleCompletionCommitted;
                session.Dismissed += HandleCompletionDismissed;
                CompletionSession = session;

                if (completionInfoType == CompletionInfoType.GlobalInfo
                    && !session.IsDismissed
                    && session.SelectedCompletionSet.SelectionStatus.IsSelected
                    && session.SelectedCompletionSet.SelectionStatus.IsUnique)
                {
                    session.Commit();
                }
            }
        }
 void ITvlIntellisenseController.TriggerCompletion(ITrackingPoint triggerPoint, CompletionInfoType completionInfoType, IntellisenseInvocationType intellisenseInvocationType)
 {
     Contract.Requires<ArgumentNullException>(triggerPoint != null, "triggerPoint");
     throw new NotImplementedException();
 }
        public static void DoTriggerCompletion(IntellisenseController controller, CompletionInfoType infoType, bool signatureHelpOnly, IntellisenseInvocationType invocationType)
        {
            Contract.Requires <ArgumentNullException>(controller != null, "controller");

            var           completionInfo = controller.CompletionInfo;
            ITextView     textView       = controller.TextView;
            SnapshotPoint?point          = textView.Caret.Position.Point.GetPoint(textView.TextBuffer, PositionAffinity.Predecessor);

            if (point.HasValue)
            {
                ITrackingPoint trackingPoint = textView.TextBuffer.CurrentSnapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
                if (!signatureHelpOnly)
                {
                    controller.TriggerCompletion(trackingPoint, infoType, invocationType);
                    DoCallMatch(controller);
                }

                if (signatureHelpOnly /*|| (completionInfo.CompletionFlags & CompletionFlags.HasParameterInfo) != 0*/)
                {
                    controller.TriggerSignatureHelp(trackingPoint);
                }

                if (controller.CompletionSession != null)
                {
                    controller.IntellisenseSessionStack.MoveSessionToTop(controller.CompletionSession);
                }
            }
        }