Exemplo n.º 1
0
        private void ShowOverloadInsightWindow(FunctionCompletionData function)
        {
            // Close all existing IntelliSense windows.
            _overloadInsightWindow?.Close();
            _completionWindow?.Close();

            // Abort if we have no info to show.
            if (function == null || function.Signatures == null || function.Signatures.Length == 0)
            {
                return;
            }

            // Create new OverloadInsightWindow with data.
            _overloadInsightWindow = new OverloadInsightWindow(_textEditor.TextArea);
            OverloadProvider provider = new OverloadProvider();

            for (int i = 0; i < function.Signatures.Length; i++)
            {
                provider.Overloads.Add(new OverloadDescription(
                                           string.Format(CultureInfo.InvariantCulture, "{0}/{1}", i + 1, function.Signatures.Length),
                                           function.Signatures[i],
                                           function.Description));
            }
            _overloadInsightWindow.Provider = provider;

            // Auto-delete instance when window is closed.
            _overloadInsightWindow.Closed += delegate { _overloadInsightWindow = null; };

            // Show window.
            _overloadInsightWindow.Show();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Requests the insight window.
        /// </summary>
        /// <param name="key">
        /// The currently pressed key which is not yet inserted in the document.
        /// </param>
        /// <remarks>
        /// This method should be called whenever the user types a new character.
        /// </remarks>
        private void RequestInsightWindow(char key)
        {
            // The insight window is shown when '(' or a ',' of a function signature is typed.
            if (key != '(' && key != ',')
            {
                return;
            }

            // Identify the region at the cursor position
            var          document    = _textEditor.Document;
            int          caretOffset = _textEditor.TextArea.Caret.Offset;
            ShaderRegion region      = _parser.IdentifyRegion(document, caretOffset);

            // Fetch lookup tables for the given region.
            NamedObjectCollection <NamedCompletionData>[] lookupTables = GetInsightLookupTables(region);
            if (lookupTables == null)
            {
                return;
            }

            // Find the name of the function.
            int offset = caretOffset;

            if (offset == 0)
            {
                return;
            }

            string identifier = null;

            if (key == '(')
            {
                // Code should look like this:
                //   "Function|"
                int startOfIdentifier = TextUtilities.FindStartOfIdentifier(document, offset - 1);
                if (startOfIdentifier >= 0)
                {
                    identifier = document.GetText(startOfIdentifier, offset - startOfIdentifier);
                }
            }
            else if (key == ',')
            {
                // Check whether we are inside a parameter list.
                //   "Function(param1, param2|"
                offset     = TextUtilities.FindOpeningBracket(document, offset - 1, '(', ')');
                identifier = TextUtilities.GetIdentifierAt(document, offset - 1);
            }

            // Fetch the function description.
            FunctionCompletionData function = null;

            if (!string.IsNullOrEmpty(identifier))
            {
                foreach (NamedObjectCollection <NamedCompletionData> lookupTable in lookupTables)
                {
                    if (lookupTable.TryGet(identifier, out function))
                    {
                        break;
                    }
                }
            }

            ShowOverloadInsightWindow(function);
        }