/// <summary>
        /// Requests that an <see cref="IParameterInfoSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        public override bool RequestSession(IEditorView view)
        {
            if (view == null)
            {
                return(false);
            }

            // Get the context
            var context = new SimpleContextFactory().CreateContext(view.Selection.EndSnapshotOffset, true);

            if ((context == null) || (context.TargetFunction == null) || (!context.ArgumentListSnapshotOffset.HasValue))
            {
                return(false);
            }

            // Create a session
            var session = new ParameterInfoSession();

            // NOTE: Normally you'd add any possible overloads here as well (the parameter info UI will handle the display of
            //   multiple overloads), but for this language we'll assume that overloads are not allowed

            // Add item for the target function
            session.Items.Add(new SignatureItem(new FunctionContentProvider(view.HighlightingStyleRegistry, context.TargetFunction, true, view.DefaultBackgroundColor), context.TargetFunction));

            // Update the current parameter
            UpdateCurrentParameter(session, context);

            // Ensure the caret is visible
            view.Scroller.ScrollToCaret();

            // Open the session
            session.Open(view, new TextRange(context.ArgumentListSnapshotOffset.Value));
            return(true);
        }
        /// <summary>
        /// Returns an object describing the quick info context for the specified text offset, if any.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> in which the offset is located.</param>
        /// <param name="offset">The text offset to examine.</param>
        /// <returns>
        /// An object describing the quick info context for the specified text offset, if any.
        /// A <see langword="null"/> value indicates that no context is available.
        /// </returns>
        /// <remarks>
        /// This method is called in response to keyboard events.
        /// </remarks>
        public override object GetContext(IEditorView view, int offset)
        {
            // Get the context factory service
            SimpleContextFactory contextFactory = view.SyntaxEditor.Document.Language.GetService <SimpleContextFactory>();

            if (contextFactory != null)
            {
                // Get a context
                return(contextFactory.CreateContext(new TextSnapshotOffset(view.CurrentSnapshot, offset), false));
            }
            return(null);
        }
        /// <summary>
        /// Occurs when the selection is changed in the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that received the event.</param>
        /// <param name="e">The <c>EditorViewSelectionEventArgs</c> that contains the event data.</param>
        protected virtual void OnViewSelectionChanged(IEditorView view, EditorViewSelectionEventArgs e)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            // Look for an existing session
            var session = view.SyntaxEditor.IntelliPrompt.Sessions[IntelliPromptSessionTypes.ParameterInfo] as IParameterInfoSession;

            if ((session != null) && (session.IsOpen))
            {
                // Quit if for a different view
                if (view != session.View)
                {
                    return;
                }

                // Get the context
                var requestNewSession = false;
                var context           = new SimpleContextFactory().CreateContext(view.Selection.EndSnapshotOffset, true);
                if ((context != null) && (context.ArgumentListSnapshotOffset.HasValue))
                {
                    // If the current session is still valid...
                    if (context.ArgumentListSnapshotOffset.Value.Offset == session.SnapshotRange.StartOffset)
                    {
                        // If the current parameter was updated...
                        if (UpdateCurrentParameter(session, context))
                        {
                            // Refresh content
                            session.Refresh();
                        }
                        return;
                    }
                    else
                    {
                        // Flag to request a new session
                        requestNewSession = true;
                    }
                }

                // Close the session
                session.Close(true);

                // If a new session should be requested...
                if (requestNewSession)
                {
                    this.RequestSession(view);
                }
            }
        }
示例#4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Requests that an <see cref="ICompletionSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <param name="canCommitWithoutPopup">Whether the session can immediately commit if a single match is made when the session is opened, commonly known as "complete word" functionality.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        public override bool RequestSession(IEditorView view, bool canCommitWithoutPopup)
        {
            // Get the context factory service
            SimpleContextFactory contextFactory = view.SyntaxEditor.Document.Language.GetService <SimpleContextFactory>();

            if (contextFactory != null)
            {
                // Get a context
                SimpleContext context = contextFactory.CreateContext(view.Selection.EndSnapshotOffset, false);

                // Create a session
                CompletionSession session = new CompletionSession();
                session.CanCommitWithoutPopup = canCommitWithoutPopup;

                switch (context.Type)
                {
                case SimpleContextType.Default:
                    // Add items for keywords
                    session.Items.Add(new CompletionItem("function", new CommonImageSourceProvider(CommonImageKind.Keyword),
                                                         new PlainTextContentProvider("Declares a function.")));
                    break;

                case SimpleContextType.FunctionDeclarationBlock:
                case SimpleContextType.FunctionReference: {
                    // Add items for keywords
                    session.Items.Add(new CompletionItem("var", new CommonImageSourceProvider(CommonImageKind.Keyword),
                                                         new PlainTextContentProvider("Declares a variable.")));
                    session.Items.Add(new CompletionItem("return", new CommonImageSourceProvider(CommonImageKind.Keyword),
                                                         new PlainTextContentProvider("Returns a value.")));

                    // Add items (one for each function name)
                    ILLParseData parseData = view.SyntaxEditor.Document.ParseData as ILLParseData;
                    if (parseData != null)
                    {
                        CompilationUnit compilationUnit = parseData.Ast as CompilationUnit;
                        if ((compilationUnit != null) && (compilationUnit.HasMembers))
                        {
                            // Loop through the AST nodes
                            foreach (FunctionDeclaration functionAstNode in compilationUnit.Members)
                            {
                                session.Items.Add(new CompletionItem(functionAstNode.Name, new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                                     new FunctionContentProvider(view.HighlightingStyleRegistry, functionAstNode, false, view.DefaultBackgroundColor)));
                            }
                        }
                    }
                    break;
                }
                }

                if (session.Items.Count > 0)
                {
                    // Ensure the caret is visible
                    view.Scroller.ScrollToCaret();

                    // Ensure the items are sorted and open the session
                    session.SortItems();
                    session.Open(view);
                    return(true);
                }
            }
            return(false);
        }