/// <summary>
        /// This method is called just once at the beginning when function
        /// tool-tip is about to be displayed. It generates the necessary data
        /// ready for queries by the function tool-tip control. This data stays
        /// for as long as the tool-tip stays visible, user can go from one
        /// function to the next with arrow keys, the function signature tool-
        /// tip will highlight the corresponding argument, or be refreshed with
        /// information of a new function (e.g. when user moves the cursor from
        /// one function to the next in a nested function call). Due to this
        /// reason, this method is not function-specific, it compiles the entire
        /// source code.
        /// </summary>
        private bool GenerateCompletionDataForCallContext()
        {
            if (AutoCompletionHelper.IsHelperReset == false)
            {
                return(true); // There's no need to recompute.
            }
            int[]       linesToExclude = new int[] { textCore.CursorPosition.Y };
            ITextBuffer textBuffer     = textCore.CurrentTextBuffer;
            string      partialContent = textBuffer.GetPartialContent(linesToExclude, " \n");

            if (null == AutoCompletionHelper.MessageHandler)
            {
                AutoCompletionHelper.MessageHandler = new AutoCompleteMessageHandler(textEditorControl);
            }

            // Clear output stream messages before attempting another compilation.
            AutoCompleteMessageHandler messageHandler = null;

            messageHandler = AutoCompletionHelper.MessageHandler as AutoCompleteMessageHandler;
            messageHandler.ClearMessages();

            IScriptObject activeScript = Solution.Current.ActiveScript;
            string        filePath     = activeScript.GetParsedScript().GetScriptPath();

            if (string.IsNullOrEmpty(filePath))
            {
                filePath = null;
            }

            if (AutoCompletionHelper.Compile(partialContent, filePath) == false)
            {
                return(false);
            }

            messageHandler.DisplayPossibleErrors();
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to retrieve AutoComplete list and bind it to visual element
        /// </summary>
        private void DoAutoComplete(string variable)
        {
            Logger.LogInfo("DoAutoComplete", variable);


            EnsureAutoCompleteListCreated();

            IScriptObject activeScript = Solution.Current.ActiveScript;
            string        filePath     = activeScript.GetParsedScript().GetScriptPath();

            if (filePath == string.Empty)
            {
                filePath = null;
            }

            int[]       linesToExclude = new int[] { textCore.CursorPosition.Y };
            ITextBuffer textBuffer     = textCore.CurrentTextBuffer;
            string      partialContent = textBuffer.GetPartialContent(linesToExclude, " \n");

            if (null == AutoCompletionHelper.MessageHandler)
            {
                AutoCompletionHelper.MessageHandler = new AutoCompleteMessageHandler(textEditorControl);
            }

            // Clear output stream messages before attempting another compilation.
            AutoCompleteMessageHandler messageHandler = null;

            messageHandler = AutoCompletionHelper.MessageHandler as AutoCompleteMessageHandler;
            messageHandler.ClearMessages();

            AutoCompletionHelper.SetSearchPaths(ExtensionFactory.GetSearchPaths());

            // Method to contact IDECodeGen.dll to retrieve the list for AutoComplete items
            List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list =
                AutoCompletionHelper.GetList(textCore.CursorPosition.Y,
                                             textCore.CursorPosition.X, partialContent, variable, filePath);

            messageHandler.DisplayPossibleErrors();
            if (list.Count == 0)
            {
                return;
            }

            CharPosition position = activeScript.CreateCharPosition();

            position.SetCharacterPosition(textCore.CursorPosition.X, textCore.CursorPosition.Y);

            // Add each AutoComplete Item one at a time
            Keyboard.Focus(textEditorCanvas);
            autoCompleteList.ClearList();
            autoCompleteList.AddItemsToList(list);

            autoCompletePopup.Placement       = PlacementMode.Custom;
            autoCompletePopup.PlacementTarget = textEditorCanvas;
            autoCompletePopup.CursorPosition  = textCore.CursorPosition;
            autoCompletePopup.IsOpen          = true;

            // The focus shift is important as the AutoCompleteList will
            // be re-routing events back to the main control now.
            autoCompleteList.DoFocusOnFirstItem();
            autoCompletePopup.Width  = autoCompleteList.Width;
            autoCompletePopup.Height = autoCompleteList.Height;
        }