Exemplo n.º 1
0
        public override Task <ICompletionDataList> HandleCodeCompletionAsync(CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken))
        {
            if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CharTyped)
            {
                int  pos = completionContext.TriggerOffset;
                char ch  = CompletionWidget != null?CompletionWidget.GetChar(pos - 1) : Editor.GetCharAt(pos - 1);

                if (pos > 0 && ch == triggerInfo.TriggerCharacter.Value)
                {
                    tracker.UpdateEngine();
                    return(HandleCodeCompletion(completionContext, false, token));
                }
            }
            else if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand)
            {
                int pos = completionContext.TriggerOffset;
                if (pos <= 0)
                {
                    return(null);
                }
                tracker.UpdateEngine();
                return(HandleCodeCompletion(completionContext, true, default(CancellationToken)));
            }
            return(null);
        }
Exemplo n.º 2
0
		public override Task<ICompletionDataList> HandleCodeCompletionAsync (CodeCompletionContext completionContext, char completionChar, CancellationToken token = default(CancellationToken))
		{
			int pos = completionContext.TriggerOffset;
			char ch = CompletionWidget != null ? CompletionWidget.GetChar (pos - 1) : Editor.GetCharAt (pos - 1);
			if (pos > 0 && ch == completionChar) {
				tracker.UpdateEngine ();
				return HandleCodeCompletion (completionContext, false, token);
			}
			return null;
		}
        public override ICompletionDataList HandleCodeCompletion(
            CodeCompletionContext completionContext, char completionChar, ref int triggerWordLength)
        {
            int  pos = completionContext.TriggerOffset;
            char ch  = CompletionWidget != null?CompletionWidget.GetChar(pos - 1) : Editor.GetCharAt(pos - 1);

            if (pos > 0 && ch == completionChar)
            {
                tracker.UpdateEngine();
                return(HandleCodeCompletion(completionContext, false, ref triggerWordLength));
            }
            return(null);
        }
Exemplo n.º 4
0
        public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
        {
            updater.BeginUpdate();
            if (this.CompletionWidget != null)
            {
                switch (keyChar)
                {
                case '(':
                case ')':
                case ';':
                case ']':
                    ParameterInformationWindowManager.HideWindow(this, CompletionWidget);
                    break;

                default:
                    if (lastTriggerOffset >= 0 && char.IsDigit(keyChar))
                    {
                        bool containsDigitsOnly = true;

                        for (int offset = lastTriggerOffset; offset < CompletionWidget.CaretOffset; offset++)
                        {
                            if (!char.IsDigit(CompletionWidget.GetChar(offset)))
                            {
                                containsDigitsOnly = false;
                                break;
                            }
                        }

                        if (containsDigitsOnly)
                        {
                            CompletionWindowManager.HideWindow();
                        }
                    }
                    break;
                }
            }

            var ret = base.KeyPress(key, keyChar, modifier);

            updater.FinishUpdate();
            return(ret);
        }
Exemplo n.º 5
0
        public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
        {
            var buffer = EditableBuffer;

            if (CompletionWindowManager.IsVisible)
            {
                // do some things to minimize keystrokes with code completion
                if (keyChar == '=')
                {
                    // we're in an attribute completion, so automatically add the quote and show completions (if available)
                    var ret = base.KeyPress(key, keyChar, modifier);
                    if (!ret)
                    {
                        base.KeyPress((Gdk.Key) 0, '"', Gdk.ModifierType.None);
                        buffer.InsertText(buffer.CursorPosition, "\"");
                        buffer.CursorPosition--;
                    }
                    return(ret);
                }
                if (key == Gdk.Key.Return &&
                    modifier == Gdk.ModifierType.None &&
                    isParameterValueCompletion)
                {
                    // finish completion
                    base.KeyPress(key, keyChar, modifier);
                    // if double quote already exists, skip it!
                    if (buffer.GetCharAt(buffer.CursorPosition) == '"')
                    {
                        buffer.CursorPosition++;
                        return(false);
                    }
                    // no double quote yet, so add it
                    return(base.KeyPress((Gdk.Key) 0, '"', Gdk.ModifierType.None));
                }
                if (keyChar == '"' || keyChar == '\'')
                {
                    // finish completion with double quote
                    base.KeyPress(Gdk.Key.Return, '\0', Gdk.ModifierType.None);
                    // if double quote already exists, skip it!
                    if (buffer.GetCharAt(buffer.CursorPosition) == keyChar)
                    {
                        buffer.CursorPosition++;
                        return(false);
                    }
                    return(base.KeyPress(key, keyChar, modifier));
                }
            }
            if (keyChar == '>')
            {
                // finish completion first
                if (CompletionWindowManager.IsVisible)
                {
                    base.KeyPress(Gdk.Key.Return, '\0', Gdk.ModifierType.None);
                }

                // add self-closing tag if there is no content for the control
                if (!HasContentAtCurrentElement())
                {
                    base.KeyPress((Gdk.Key) 0, '/', Gdk.ModifierType.None);
                    //buffer.InsertText(buffer.CursorPosition++, "/");
                    return(base.KeyPress(key, keyChar, modifier));
                }
            }
            if (keyChar == '"' || keyChar == '\'')
            {
                // if double quote already exists, skip it!
                if (buffer.GetCharAt(buffer.CursorPosition) == keyChar)
                {
                    buffer.CursorPosition++;
                    return(false);
                }
            }
            if (keyChar == '.')
            {
                var result = base.KeyPress(key, keyChar, modifier);
                // provide completions for <Control.Property> elements
                var completionContext = CompletionWidget.CurrentCodeCompletionContext;
                var offset            = completionContext.TriggerOffset - 1;
                var ch = CompletionWidget.GetChar(offset);
                while (ch != '\0' && (XmlConvert.IsNCNameChar(ch) || ch == ':') && offset > 0)
                {
                    offset--;
                    ch = CompletionWidget.GetChar(offset);
                }
                if (ch != '\0' && ch != '<')
                {
                    return(result);
                }
                offset++;
                var len  = completionContext.TriggerOffset - offset;
                var name = Editor.GetTextAt(offset, len);
                try
                {
                    XmlConvert.VerifyName(name);
                }
                catch (XmlException)
                {
                    // not a valid xml name
                    return(result);
                }

                var xobject = Tracker.Engine.Nodes.Peek(1) as IAttributedXObject;
                if (xobject == null)
                {
                    string prefix = null;
                    var    nsidx  = name.IndexOf(':');
                    if (nsidx > 0)
                    {
                        prefix = name.Substring(0, nsidx);
                        name   = name.Substring(nsidx + 1);
                    }
                    name    = name.TrimEnd('.');
                    xobject = new XElement(Tracker.Engine.Location, new XName(prefix, name));
                }

                var attributeDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                if (xobject.Attributes != null)
                {
                    foreach (XAttribute current in xobject.Attributes)
                    {
                        attributeDictionary[current.Name.FullName] = current.Value ?? string.Empty;
                    }
                }
                var completions = GetAttributeCompletions(xobject, attributeDictionary, XmlCompletionData.DataType.XmlElement, true);

                if (completions != null)
                {
                    ShowCompletion(completions);
                    return(false);
                }
            }
            return(base.KeyPress(key, keyChar, modifier));
        }
        int GetCurrentParameterIndex(int startOffset)
        {
            int cursor = CompletionWidget.CurrentCodeCompletionContext.TriggerOffset;
            int i      = startOffset;

            if (i < 0 || i >= Editor.Length)
            {
                return(-1);
            }

            if (i > cursor)
            {
                return(-1);
            }
            else if (i == cursor)
            {
                return(0);
            }
            // step over to the opening parenthesis at function call
            // if this fails, that means the paranthesis has been removed after invoking parameter hinting
            // and its safe to return -1 (and destroy the PH widget)
            try {
                while (Editor.GetCharAt(i) != '(')
                {
                    i++;
                }
            } catch {
                return(-1);
            }
            int parameterIndex      = 1;
            int inTemplateSpecifier = 0;
            int inCurvyBracket      = 0;
            int inParentesis        = 0;
            int inBracket           = 0;

            while (i++ < cursor)
            {
                if (i >= CompletionWidget.TextLength)
                {
                    break;
                }
                char ch = CompletionWidget.GetChar(i);
                switch (ch)
                {
                case '<':
                    ++inTemplateSpecifier;
                    break;

                case '>':
                    --inTemplateSpecifier;
                    break;

                case '(':
                    ++inParentesis;
                    break;

                case ')':
                    --inParentesis;
                    if (inParentesis == 0)
                    {
                        return(-1);
                    }
                    break;

                case '[':
                    ++inBracket;
                    break;

                case ']':
                    --inBracket;
                    break;

                case '{':
                    ++inCurvyBracket;
                    break;

                case '}':
                    --inCurvyBracket;
                    break;

                case ',':
                    if (inTemplateSpecifier == 0 &&
                        inParentesis == 0 &&
                        inBracket == 0 &&
                        inCurvyBracket == 0)
                    {
                        parameterIndex++;
                    }
                    break;
                }
            }
            return(parameterIndex);
        }