Ejemplo n.º 1
0
 public override ICompletionDataList HandleCodeCompletion(
     CodeCompletionContext completionContext, char completionChar, ref int triggerWordLength)
 {
     if (localDocumentInfo == null)
     {
         return(base.HandleCodeCompletion(completionContext, completionChar, ref triggerWordLength));
     }
     localDocumentInfo.HiddenDocument.Editor.InsertAtCaret(completionChar.ToString());
     return(documentBuilder.HandleCompletion(defaultDocument, completionContext, documentInfo, localDocumentInfo, completionChar, ref triggerWordLength));
 }
Ejemplo n.º 2
0
        protected override ICompletionDataList HandleCodeCompletion(CodeCompletionContext completionContext,
                                                                    bool forced, ref int triggerWordLength)
        {
            ITextBuffer buf = this.Buffer;
            // completionChar may be a space even if the current char isn't, when ctrl-space is fired t
            char currentChar = completionContext.TriggerOffset < 1? ' ' : buf.GetCharAt(completionContext.TriggerOffset - 1);

            //char previousChar = completionContext.TriggerOffset < 2? ' ' : buf.GetCharAt (completionContext.TriggerOffset - 2);

            //directive names
            if (Tracker.Engine.CurrentState is AspNetDirectiveState)
            {
                var directive = Tracker.Engine.Nodes.Peek() as AspNetDirective;
                if (HasDoc && directive != null && directive.Region.Start.Line == completionContext.TriggerLine &&
                    directive.Region.Start.Column + 4 == completionContext.TriggerLineOffset)
                {
                    return(DirectiveCompletion.GetDirectives(aspDoc.Type));
                }
                return(null);
            }
            else if (Tracker.Engine.CurrentState is S.XmlNameState && Tracker.Engine.CurrentState.Parent is AspNetDirectiveState)
            {
                var directive = Tracker.Engine.Nodes.Peek() as AspNetDirective;
                if (HasDoc && directive != null && directive.Region.Start.Line == completionContext.TriggerLine &&
                    directive.Region.Start.Column + 5 == completionContext.TriggerLineOffset && char.IsLetter(currentChar))
                {
                    triggerWordLength = 1;
                    return(DirectiveCompletion.GetDirectives(aspDoc.Type));
                }
                return(null);
            }

            bool isAspExprState = Tracker.Engine.CurrentState is AspNetExpressionState;

            //non-xml tag completion
            if (currentChar == '<' && !(isAspExprState || Tracker.Engine.CurrentState is S.XmlFreeState))
            {
                var list = new CompletionDataList();
                AddAspBeginExpressions(list);
                return(list);
            }

            if (!HasDoc || aspDoc.Info.DocType == null)
            {
                //FIXME: get doctype from master page
                DocType = null;
            }
            else
            {
                DocType = new MonoDevelop.Xml.StateEngine.XDocType(DomLocation.Empty);
                var matches = DocTypeRegex.Match(aspDoc.Info.DocType);
                DocType.PublicFpi = matches.Groups["fpi"].Value;
                DocType.Uri       = matches.Groups["uri"].Value;
            }

            //completion for ASP.NET expressions
            if (documentBuilder != null && isAspExprState)
            {
                InitializeCodeCompletion();
                return(documentBuilder.HandleCompletion(hiddenDocument, documentInfo, localDocumentInfo,
                                                        new AspProjectDomWrapper(documentInfo), currentChar, ref triggerWordLength));
            }

            if (Tracker.Engine.CurrentState is HtmlScriptBodyState)
            {
                var el = Tracker.Engine.Nodes.Peek() as S.XElement;
                if (el != null)
                {
                    var att = GetHtmlAtt(el, "runat");
                    if (att != null && "server".Equals(att.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        if (documentBuilder != null)
                        {
                            // TODO: C# completion
                        }
                    }

                    /*
                     * else {
                     *      att = GetHtmlAtt (el, "language");
                     *      if (att == null || "javascript".Equals (att.Value, StringComparison.OrdinalIgnoreCase)) {
                     *          att = GetHtmlAtt (el, "type");
                     *              if (att == null || "text/javascript".Equals (att.Value, StringComparison.OrdinalIgnoreCase)) {
                     *                      // TODO: JS completion
                     *              }
                     *      }
                     * }*/
                }
            }

            return(base.HandleCodeCompletion(completionContext, forced, ref triggerWordLength));
        }