Пример #1
0
        /// <summary>
        /// Triggers Statement completion when appropriate keys are pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void VisualElement_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            // Make sure that this event happened on the same text view to which we're attached.
            ITextView textView = sender as ITextView;

            if (this.textView != textView)
            {
                return;
            }

            // if there is a session already leave it be
            if (activeSession != null)
            {
                return;
            }

            // determine which subject buffer is affected by looking at the caret position
            SnapshotPoint?caret = textView.Caret.Position.Point.GetPoint
                                      (textBuffer => buffer == textBuffer, PositionAffinity.Predecessor);

            // return if no suitable buffer found
            if (!caret.HasValue)
            {
                return;
            }

            SnapshotPoint caretPoint = caret.Value;

            var subjectBuffer = caretPoint.Snapshot.TextBuffer;

            CompletionContext completionContext =
                AbstractCompletionSet.GetCompletionContext(e.Key, subjectBuffer, caretPoint.Position);

            // the invocation occurred in a subject buffer of interest to us
            triggerPosition = caretPoint.Position;
            ITrackingPoint triggerPoint = caretPoint.Snapshot.CreateTrackingPoint(triggerPosition, PointTrackingMode.Negative);

            completionSpan = caretPoint.Snapshot.CreateTrackingSpan(caretPoint.Position, 0, SpanTrackingMode.EdgeInclusive);

            // attach filter to intercept the Enter key
            attachKeyboardFilter();

            // Create a completion session
            activeSession = provider.CompletionBroker.CreateCompletionSession(textView, triggerPoint, true);

            // Put the completion context and original (empty) completion span
            // on the session so that it can be used by the completion source
            activeSession.Properties.AddProperty(typeof(CompletionContext), completionContext);
            activeSession.Properties.AddProperty(typeof(Controller), completionSpan);

            // Attach to the session events
            activeSession.Dismissed += new System.EventHandler(OnActiveSessionDismissed);
            activeSession.Committed += new System.EventHandler(OnActiveSessionCommitted);

            // Start the completion session. The intellisense will be triggered.
            activeSession.Start();
        }
Пример #2
0
        private CompletionSet CreateCompletionSet(CompletionContext context, SnapshotPoint point)
        {
            switch (context)
            {
            case CompletionContext.Tag:
                return(AbstractCompletionSet.Create <TagCompletionSet>(
                           nodeProvider, point,
                           n => n.NodeType == NodeType.ParsingContext
                           ));

            case CompletionContext.Variable:
                return(AbstractCompletionSet.Create <VariableCompletionSet>(
                           nodeProvider, point,
                           n => n.NodeType == NodeType.ParsingContext
                           ));

            case CompletionContext.FilterName:
                return(AbstractCompletionSet.Create <FilterCompletionSet>(
                           nodeProvider, point,
                           n => n.NodeType == NodeType.ParsingContext
                           ));

            case CompletionContext.Word:
                // Get the list of all nodes with non-empty value lists
                List <DesignerNode> nodes = nodeProvider.GetNodes(point, n => n.Values.GetEnumerator().MoveNext());
                // out of the list get the last node which is not a parsing context
                DesignerNode node = nodes.FindLast(n => n.NodeType != NodeType.ParsingContext);
                if (node == null)
                {
                    break;
                }
                if (node.NodeType == NodeType.TagName)
                {
                    return(new TagNameCompletionSet(node, point));
                }
                return(new ValueCompletionSet(node, point));

            default:
                break;
            }

            return(null);
            // for now let us leave the template names alone
            //return AbstractCompletionSet.Create<TemplateNameCompletionSet>(
            //    nodeProvider, point,
            //    n =>
            //        n.NodeType == NodeType.TemplateName
            //        && string_delimiters.Contains(n.SnapshotSpan.GetText()[0])
            //        );
        }
Пример #3
0
        private CompletionSet CreateCompletionSet(SnapshotPoint point)
        {
            switch (Context)
            {
            case CompletionContext.Tag:
                return(AbstractCompletionSet.Create <TagCompletionSet>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.ParsingContext).FindLast(n => true)
                           ));

            case CompletionContext.Variable:
                return(AbstractCompletionSet.Create <VariableCompletionSet>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.ParsingContext).FindLast(n => true)
                           ));

            case CompletionContext.FilterName:
                return(AbstractCompletionSet.Create <FilterName>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.ParsingContext).FindLast(n => true)
                           ));

            case CompletionContext.FilterArgument:
                return(AbstractCompletionSet.Create <FilterArgument>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.Filter).FindLast(n => true)));

            case CompletionContext.Word:
                // Get the list of all nodes with non-empty value lists
                List <DesignerNode> nodes = nodeProvider.GetNodes(point, n => n.IsCompletionProvider);
                // out of the list get the last node which is not a parsing context
                DesignerNode node = nodes.FindLast(n => n.NodeType != NodeType.ParsingContext);
                if (node == null)
                {
                    return(null);
                }
                switch (node.NodeType)
                {
                case NodeType.Reference:
                    return(AbstractCompletionSet.Create <Member>(this, point, node));

                case NodeType.TagName:
                    return(new TagName(this, node, point));

                case NodeType.TypeName:
                    return(new TypeName(this, node, point));

                default:
                    break;
                }
                return(new ValueCompletionSet(this, node, point));

            case CompletionContext.NewMemberReference:
                return(AbstractCompletionSet.Create <NewMember>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.Reference).FindLast(n => true)));

            case CompletionContext.AposString:
            case CompletionContext.QuotedString:
                return(AbstractCompletionSet.Create <TemplateName>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.TemplateName).FindLast(n => true)));

            default:
                return(null);
            }
        }