示例#1
0
 public HaXeCompletion(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler handler)
 {
     this.sci = sci;
     this.expr = expr;
     this.autoHide = autoHide;
     this.handler = handler;
     tips = new ArrayList();
     nbErrors = 0;
 }
示例#2
0
 public HaxeComplete(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler completionHandler)
 {
     Sci      = sci;
     Expr     = expr;
     AutoHide = autoHide;
     handler  = completionHandler;
     Status   = HaxeCompleteStatus.NONE;
     FileName = PluginBase.MainForm.CurrentDocument.FileName;
 }
 public HaXeCompletion(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler handler)
 {
     this.sci      = sci;
     this.expr     = expr;
     this.autoHide = autoHide;
     this.handler  = handler;
     tips          = new ArrayList();
     nbErrors      = 0;
 }
示例#4
0
 public HaxeComplete(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler completionHandler)
 {
     Sci = sci;
     Expr = expr;
     AutoHide = autoHide;
     handler = completionHandler;
     Status = HaxeCompleteStatus.NONE;
     FileName = PluginBase.MainForm.CurrentDocument.FileName;
 }
示例#5
0
 public HaxeComplete(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler completionHandler, HaxeCompilerService compilerService)
 {
     Sci             = sci;
     Expr            = expr;
     CurrentWord     = Sci.GetWordFromPosition(Sci.CurrentPos);
     AutoHide        = autoHide;
     handler         = completionHandler;
     CompilerService = compilerService;
     Status          = HaxeCompleteStatus.NONE;
     FileName        = PluginBase.MainForm.CurrentDocument.FileName;
 }
示例#6
0
 public HaxeComplete(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler completionHandler, HaxeCompilerService compilerService, SemVer haxeVersion)
 {
     Sci              = sci;
     Expr             = expr;
     CurrentWord      = Sci.GetWordFromPosition(Sci.CurrentPos);
     AutoHide         = autoHide;
     handler          = completionHandler;
     CompilerService  = compilerService;
     Status           = HaxeCompleteStatus.NONE;
     FileName         = sci.FileName;
     this.haxeVersion = haxeVersion;
 }
示例#7
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <returns>Null (not handled) or function signature</returns>
        public override MemberModel ResolveFunctionContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (resolvingFunction || hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop)
                return null;

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
                return null;

            // Do not show error
            string val = expression.Value;
            if (val == "for" ||
                val == "while" ||
                val == "if" ||
                val == "switch" ||
                val == "function" ||
                val == "catch" ||
                val == "trace")
                return null;

            expression.Position++;
            HaXeCompletion hc = new HaXeCompletion(sci, expression, autoHide, completionModeHandler);
            hc.getList(OnFunctionCompletionResult);

            resolvingFunction = true;
            return null; // running asynchronously
        }
示例#8
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <param name="autoHide">Auto-started completion (is false when pressing Ctrl+Space)</param>
        /// <returns>Null (not handled) or member list</returns>
        public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (resolvingDot || hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop)
                return null;

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
                return null;

            // auto-started completion, can be ignored for performance (show default completion tooltip)
            if (expression.Value.IndexOf(".") < 0 || (autoHide && !expression.Value.EndsWith(".")))
                if (hxsettings.DisableMixedCompletion && expression.Value.Length > 0 && autoHide) return new MemberList();
                else return null;

            // empty expression
            if (expression.Value != "")
            {
                // async processing
                HaXeCompletion hc = new HaXeCompletion(sci, expression, autoHide, completionModeHandler);
                hc.getList(OnDotCompletionResult);
                resolvingDot = true;
            }

            if (hxsettings.DisableMixedCompletion) return new MemberList();
            return null;
        }
示例#9
0
 public HaxeComplete330(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler completionHandler, HaxeCompilerService compilerService, SemVer haxeVersion) : base(sci, expr, autoHide, completionHandler, compilerService, haxeVersion)
 {
 }
示例#10
0
        /// <summary>
        /// Find Actionscript expression at cursor position
        /// </summary>
        /// <param name="sci">Scintilla Control</param>
        /// <param name="position">Cursor position</param>
        /// <param name="ignoreWhiteSpace">Skip whitespace at position</param>
        /// <returns></returns>
        private static ASExpr GetExpression(ScintillaNet.ScintillaControl Sci, int position, bool ignoreWhiteSpace)
        {
            ASExpr expression = new ASExpr();
            expression.Position = position;
            expression.Separator = ' ';

            // file's member declared at this position
            expression.ContextMember = ASContext.Context.CurrentMember;
            int minPos = 0;
            string body = null;
            if (expression.ContextMember != null)
            {
                minPos = Sci.PositionFromLine(expression.ContextMember.LineFrom);
                StringBuilder sbBody = new StringBuilder();
                for (int i = expression.ContextMember.LineFrom; i <= expression.ContextMember.LineTo; i++)
                    sbBody.Append(Sci.GetLine(i)).Append('\n');
                body = sbBody.ToString();
                //int tokPos = body.IndexOf(expression.ContextMember.Name);
                //if (tokPos >= 0) minPos += tokPos + expression.ContextMember.Name.Length;

                if ((expression.ContextMember.Flags & (FlagType.Function | FlagType.Constructor | FlagType.Getter | FlagType.Setter)) > 0)
                {
                    expression.ContextFunction = expression.ContextMember;
                    expression.FunctionOffset = expression.ContextMember.LineFrom;

                    Match mStart = Regex.Match(body, "(\\)|[a-z0-9*.,-<>])\\s*{", RegexOptions.IgnoreCase);
                    if (mStart.Success)
                    {
                        // cleanup function body & offset
                        int pos = mStart.Index + mStart.Length;
                        expression.BeforeBody = (position < Sci.PositionFromLine(expression.ContextMember.LineFrom) + pos);
                        string pre = body.Substring(0, pos);
                        for (int i = 0; i < pre.Length - 1; i++)
                            if (pre[i] == '\r') { expression.FunctionOffset++; if (pre[i + 1] == '\n') i++; }
                            else if (pre[i] == '\n') expression.FunctionOffset++;
                        body = body.Substring(pos);
                    }
                    expression.FunctionBody = body;
                }
                else
                {
                    int eqPos = body.IndexOf('=');
                    expression.BeforeBody = (eqPos < 0 || position < Sci.PositionFromLine(expression.ContextMember.LineFrom) + eqPos);
                }
            }

            // get the word characters from the syntax definition
            string characterClass = ScintillaNet.ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters;

            // get expression before cursor
            ContextFeatures features = ASContext.Context.Features;
            int stylemask = (1 << Sci.StyleBits) - 1;
            int style = (position >= minPos) ? Sci.StyleAt(position) & stylemask : 0;
            StringBuilder sb = new StringBuilder();
            StringBuilder sbSub = new StringBuilder();
            int subCount = 0;
            char c = ' ';
            char c2;
            int startPos = position;
            int braceCount = 0;
            int sqCount = 0;
            int genCount = 0;
            bool hasGenerics = features.hasGenerics;
            bool hadWS = false;
            bool hadDot = ignoreWhiteSpace;
            bool inRegex = false;
            char dot = features.dot[features.dot.Length - 1];
            while (position > minPos)
            {
                position--;
                style = Sci.StyleAt(position) & stylemask;
                if (style == 14) // regex literal
                {
                    inRegex = true;
                }
                else if (!ASComplete.IsCommentStyle(style))
                {
                    c2 = c;
                    c = (char)Sci.CharAt(position);
                    // end of regex literal
                    if (inRegex)
                    {
                        inRegex = false;
                        if (expression.SubExpressions == null) expression.SubExpressions = new List<string>();
                        expression.SubExpressions.Add("");
                        sb.Insert(0, "RegExp.#" + (subCount++) + "~");
                    }
                    // array access
                    if (c == '[')
                    {
                        sqCount--;
                        if (sqCount == 0)
                        {
                            if (sbSub.Length > 0) sbSub.Insert(0, '[');
                            if (braceCount == 0) sb.Insert(0, ".[]");
                            continue;
                        }
                        if (sqCount < 0)
                        {
                            expression.Separator = ';';
                            break;
                        }
                    }
                    else if (c == ']')
                    {
                        sqCount++;
                    }
                    //
                    else if (c == '<' && hasGenerics)
                    {
                        genCount--;
                        if (genCount < 0)
                        {
                            expression.Separator = ';';
                            break;
                        }
                    }
                    // ignore sub-expressions (method calls' parameters)
                    else if (c == '(')
                    {
                        braceCount--;
                        if (braceCount == 0)
                        {
                            sbSub.Insert(0, c);
                            expression.SubExpressions.Add(sbSub.ToString());
                            sb.Insert(0, ".#" + (subCount++) + "~"); // method call or sub expression

                            int testPos = position - 1;
                            string testWord = ASComplete.GetWordLeft(Sci, ref testPos);
                            if (testWord == "return" || testWord == "case" || testWord == "defaut")
                            {
                                // ex: return (a as B).<complete>
                                expression.Separator = ';';
                                expression.WordBefore = testWord;
                                break;
                            }
                            else continue;
                        }
                        else if (braceCount < 0)
                        {
                            expression.Separator = ';';
                            int testPos = position - 1;
                            string testWord = ASComplete.GetWordLeft(Sci, ref testPos); // anonymous function
                            string testWord2 = ASComplete.GetWordLeft(Sci, ref testPos) ?? "null"; // regular function
                            if (testWord == features.functionKey || testWord == "catch"
                                || testWord2 == features.functionKey
                                || testWord2 == features.getKey || testWord2 == features.setKey)
                            {
                                expression.Separator = ',';
                                expression.coma = ComaExpression.FunctionDeclaration;
                            }
                            break;
                        }
                    }
                    else if (c == ')')
                    {
                        if (!hadDot)
                        {
                            expression.Separator = ';';
                            break;
                        }
                        if (braceCount == 0) // start sub-expression
                        {
                            if (expression.SubExpressions == null) expression.SubExpressions = new List<string>();
                            sbSub = new StringBuilder();
                        }
                        braceCount++;
                    }
                    else if (c == '>' && hasGenerics)
                    {
                        if (c2 == '.' || c2 == '(')
                            genCount++;
                        else break;
                    }
                    if (braceCount > 0 || sqCount > 0 || genCount > 0)
                    {
                        if (c == ';') // not expected: something's wrong
                        {
                            expression.Separator = ';';
                            break;
                        }
                        // build sub expression
                        sbSub.Insert(0, c);
                        continue;
                    }
                    // build expression
                    if (c <= 32)
                    {
                        if (genCount == 0) hadWS = true;
                    }
                    else if (c == dot)
                    {
                        if (features.dot.Length == 2)
                            hadDot = position > 0 && Sci.CharAt(position - 1) == features.dot[0];
                        else hadDot = true;
                        sb.Insert(0, c);
                    }
                    else if (characterClass.IndexOf(c) >= 0)
                    {
                        if (hadWS && !hadDot)
                        {
                            expression.Separator = ' ';
                            break;
                        }
                        hadWS = false;
                        hadDot = false;
                        sb.Insert(0, c);
                        startPos = position;
                    }
                    else if (c == ';')
                    {
                        expression.Separator = ';';
                        break;
                    }
                    else if (hasGenerics && (genCount > 0 || c == '<'))
                    {
                        sb.Insert(0, c);
                    }
                    else if (c == '{')
                    {
                        expression.coma = DisambiguateComa(Sci, position, minPos);
                        expression.Separator = (expression.coma == ComaExpression.None) ? ';' : ',';
                        break;
                    }
                    else if (c == ',')
                    {
                        expression.coma = DisambiguateComa(Sci, position, minPos);
                        expression.Separator = (expression.coma == ComaExpression.None) ? ';' : ',';
                        break;
                    }
                    else if (c == ':')
                    {
                        expression.Separator = ':';
                        break;
                    }
                    else if (c == '=')
                    {
                        expression.Separator = '=';
                        break;
                    }
                    else //if (hadWS && !hadDot)
                    {
                        if (c == '\'' || c == '"') expression.Separator = '"';
                        else expression.Separator = ';';
                        break;
                    }
                }
                // string literals only allowed in sub-expressions
                else
                {
                    if (braceCount == 0) // not expected: something's wrong
                    {
                        expression.Separator = ';';
                        break;
                    }
                }
            }

            // check if there is a particular keyword
            if (expression.Separator == ' ')
            {
                expression.WordBefore = ASComplete.GetWordLeft(Sci, ref position);
            }

            // result
            expression.Value = sb.ToString();
            expression.PositionExpression = startPos;

            return expression;
        }
示例#11
0
 /// <summary>
 /// Let contexts handle code completion
 /// </summary>
 /// <param name="sci">Scintilla control</param>
 /// <param name="expression">Completion context</param>
 /// <returns>Null (not handled) or function signature</returns>
 public virtual MemberModel ResolveFunctionContext(ScintillaControl sci, ASExpr expression, bool autoHide)
 {
     return null;
 }
示例#12
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <returns>Null (not handled) or function signature</returns>
        public override MemberModel ResolveFunctionContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (resolvingFunction || hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || PluginBase.MainForm.CurrentDocument.IsUntitled)
                return null;

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
                return null;

            // Do not show error
            string val = expression.Value;
            if (val == "for" ||
                val == "while" ||
                val == "if" ||
                val == "switch" ||
                val == "function" ||
                val == "catch" ||
                val == "trace")
                return null;

            expression.Position++;
            var hc = new HaxeComplete(sci, expression, autoHide, completionModeHandler, HaxeCompilerService.COMPLETION, GetCurrentSDKVersion());
            hc.GetList(OnFunctionCompletionResult);

            resolvingFunction = true;
            return null; // running asynchronously
        }
示例#13
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <returns>Null (not handled) or function signature</returns>
        public override MemberModel ResolveFunctionContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (hxsettings.DisableCompilerCompletion)
                return null;

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
                return null;

            string[] parts = expression.Value.Split('.');
            string name = parts[parts.Length - 1];
            
            MemberModel member = new MemberModel();

            // Do not show error
            string val = expression.Value;
            if (val == "for" || 
                val == "while" ||
                val == "if" ||
                val == "switch" ||
                val == "function" ||
                val == "catch" ||
                val == "trace")
                return null;

            HaXeCompletion hc = new HaXeCompletion(sci, expression.Position);
            ArrayList al = hc.getList();
            if (al == null || al.Count == 0)
                return null; // haxe.exe not found

            string outputType = al[0].ToString();

            if (outputType == "type" )
            {
                member.Name = name;
                member.Flags = FlagType.Function;
                member.Access = Visibility.Public;

                string type = al[1].ToString();

                Array types = type.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                // Function's arguments
                member.Parameters = new List<MemberModel>();
                int j = 0;
                while (j < types.Length - 1)
                {
                    MemberModel param = new MemberModel(types.GetValue(j).ToString(), "", FlagType.ParameterVar, Visibility.Public);
                    member.Parameters.Add(param);
                    j++;
                }
                // Function's return type
                member.Type = types.GetValue(types.Length - 1).ToString();
            }
            else if ( outputType == "error" )
            {
                string err = al[1].ToString();
                sci.CallTipShow(sci.CurrentPos, err);
                sci.CharAdded += new ScintillaNet.CharAddedHandler(removeTip);
            }
                        
            return member;
        }
示例#14
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <param name="autoHide">Auto-started completion (is false when pressing Ctrl+Space)</param>
        /// <returns>Null (not handled) or member list</returns>
        public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (hxsettings.DisableCompilerCompletion)
                return null;

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
                return null;

            // auto-started completion, can be ignored for performance (show default completion tooltip)
            if (autoHide && !expression.Value.EndsWith("."))
                if ( hxsettings.DisableMixedCompletion )
                    return new MemberList();
                else
                    return null;

            MemberList list = new MemberList();
           
            HaXeCompletion hc = new HaXeCompletion(sci, expression.Position);
            ArrayList al = hc.getList();
            if (al == null || al.Count == 0) 
                return null; // haxe.exe not found
            
            string outputType = al[0].ToString();

            if( outputType == "error" )
            {
                string err = al[1].ToString();
                sci.CallTipShow(sci.CurrentPos, err);
                sci.CharAdded += new ScintillaNet.CharAddedHandler(removeTip);
                
                // show default completion tooltip
                if (!hxsettings.DisableMixedCompletion)
                    return null;
            }
            else if (outputType == "list")
            {
                foreach (ArrayList i in al[ 1 ] as ArrayList)
                {
                    string var = i[0].ToString();
                    string type = i[1].ToString();
                    string desc = i[2].ToString();

                    FlagType flag = FlagType.Variable;

                    MemberModel member = new MemberModel();
                    member.Name = var;
                    member.Access = Visibility.Public;
                    
                    // Package or Class
                    if (type == "")
                    {
                        string bl = var.Substring( 0, 1 );
                        if (bl == bl.ToLower())
                            flag = FlagType.Package;
                        else
                            flag = FlagType.Class;
                    }
                    // Function or Variable
                    else
                    {
                        Array types = type.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                        // Function
                        if (types.Length > 1)
                        {
                            flag = FlagType.Function;

                            // Function's arguments
                            member.Parameters = new List<MemberModel>();
                            int j = 0;
                            while (j < types.Length - 1)
                            {
                                MemberModel param = new MemberModel(types.GetValue(j).ToString(), "", FlagType.ParameterVar, Visibility.Public);
                                member.Parameters.Add(param);
                                j++;
                            }

                            // Function's return type
                            member.Type = types.GetValue(types.Length - 1).ToString();
                        }
                        // Variable
                        else
                        {
                            flag = FlagType.Variable;
                            // Variable's type
                            member.Type = type;
                        }    
                       
                    }
                                        
                    member.Flags = flag;
                    
                   list.Add(member);
                }
            }
            return list;
        }
示例#15
0
        public override bool HandleGotoDeclaration(ScintillaControl sci, ASExpr expression)
        {
            if (hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || GetCurrentSDKVersion().IsOlderThan(new SemVer("3.2.0")))
                return false;

            var hc = new HaxeComplete(sci, expression, false, completionModeHandler, HaxeCompilerService.POSITION, GetCurrentSDKVersion());
            hc.GetPosition(OnPositionResult);
            return true;
        }
示例#16
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <param name="autoHide">Auto-started completion (is false when pressing Ctrl+Space)</param>
        /// <returns>Null (not handled) or member list</returns>
        public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (resolvingDot || hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || PluginBase.MainForm.CurrentDocument.IsUntitled)
                return null;

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
                return null;

            // auto-started completion, can be ignored for performance (show default completion tooltip)
            if (expression.Value.IndexOfOrdinal(".") < 0 || (autoHide && !expression.Value.EndsWith('.')))
                if (hxsettings.DisableMixedCompletion && expression.Value.Length > 0 && autoHide) return new MemberList();
                else return null;

            // empty expression
            if (expression.Value != "")
            {
                // async processing
                var hc = new HaxeComplete(sci, expression, autoHide, completionModeHandler, HaxeCompilerService.COMPLETION, GetCurrentSDKVersion());
                hc.GetList(OnDotCompletionResult);
                resolvingDot = true;
            }

            if (hxsettings.DisableMixedCompletion) return new MemberList();
            return null;
        }
示例#17
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <returns>Null (not handled) or function signature</returns>
        public override MemberModel ResolveFunctionContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (hxsettings.DisableCompilerCompletion)
            {
                return(null);
            }

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
            {
                return(null);
            }

            string[] parts = expression.Value.Split('.');
            string   name  = parts[parts.Length - 1];

            MemberModel member = new MemberModel();

            // Do not show error
            string val = expression.Value;

            if (val == "for" ||
                val == "while" ||
                val == "if" ||
                val == "switch" ||
                val == "function" ||
                val == "catch" ||
                val == "trace")
            {
                return(null);
            }

            HaXeCompletion hc = new HaXeCompletion(sci, expression.Position);
            ArrayList      al = hc.getList();

            if (al == null || al.Count == 0)
            {
                return(null); // haxe.exe not found
            }
            string outputType = al[0].ToString();

            if (outputType == "type")
            {
                member.Name   = name;
                member.Flags  = FlagType.Function;
                member.Access = Visibility.Public;

                string type = al[1].ToString();

                Array types = type.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                // Function's arguments
                member.Parameters = new List <MemberModel>();
                int j = 0;
                while (j < types.Length - 1)
                {
                    MemberModel param = new MemberModel(types.GetValue(j).ToString(), "", FlagType.ParameterVar, Visibility.Public);
                    member.Parameters.Add(param);
                    j++;
                }
                // Function's return type
                member.Type = types.GetValue(types.Length - 1).ToString();
            }
            else if (outputType == "error")
            {
                string err = al[1].ToString();
                sci.CallTipShow(sci.CurrentPos, err);
                sci.CharAdded += new ScintillaNet.CharAddedHandler(removeTip);
            }

            return(member);
        }
示例#18
0
 /// <summary>
 /// Let contexts handle code completion
 /// </summary>
 /// <param name="sci">Scintilla control</param>
 /// <param name="expression">Completion context</param>
 /// <param name="autoHide">Auto-started completion (is false when pressing Ctrl+Space)</param>
 /// <returns>Null (not handled) or member list</returns>
 public virtual MemberList ResolveDotContext(ScintillaControl sci, ASExpr expression, bool autoHide)
 {
     return null;
 }
示例#19
0
        /// <summary>
        /// Let contexts handle code completion
        /// </summary>
        /// <param name="sci">Scintilla control</param>
        /// <param name="expression">Completion context</param>
        /// <param name="autoHide">Auto-started completion (is false when pressing Ctrl+Space)</param>
        /// <returns>Null (not handled) or member list</returns>
        public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci, ASExpr expression, bool autoHide)
        {
            if (hxsettings.DisableCompilerCompletion)
            {
                return(null);
            }

            if (autoHide && !hxsettings.DisableCompletionOnDemand)
            {
                return(null);
            }

            // auto-started completion, can be ignored for performance (show default completion tooltip)
            if (autoHide && !expression.Value.EndsWith("."))
            {
                if (hxsettings.DisableMixedCompletion)
                {
                    return(new MemberList());
                }
                else
                {
                    return(null);
                }
            }

            MemberList list = new MemberList();

            HaXeCompletion hc = new HaXeCompletion(sci, expression.Position);
            ArrayList      al = hc.getList();

            if (al == null || al.Count == 0)
            {
                return(null); // haxe.exe not found
            }
            string outputType = al[0].ToString();

            if (outputType == "error")
            {
                string err = al[1].ToString();
                sci.CallTipShow(sci.CurrentPos, err);
                sci.CharAdded += new ScintillaNet.CharAddedHandler(removeTip);

                // show default completion tooltip
                if (!hxsettings.DisableMixedCompletion)
                {
                    return(null);
                }
            }
            else if (outputType == "list")
            {
                foreach (ArrayList i in al[1] as ArrayList)
                {
                    string var  = i[0].ToString();
                    string type = i[1].ToString();
                    string desc = i[2].ToString();

                    FlagType flag = FlagType.Variable;

                    MemberModel member = new MemberModel();
                    member.Name   = var;
                    member.Access = Visibility.Public;

                    // Package or Class
                    if (type == "")
                    {
                        string bl = var.Substring(0, 1);
                        if (bl == bl.ToLower())
                        {
                            flag = FlagType.Package;
                        }
                        else
                        {
                            flag = FlagType.Class;
                        }
                    }
                    // Function or Variable
                    else
                    {
                        Array types = type.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                        // Function
                        if (types.Length > 1)
                        {
                            flag = FlagType.Function;

                            // Function's arguments
                            member.Parameters = new List <MemberModel>();
                            int j = 0;
                            while (j < types.Length - 1)
                            {
                                MemberModel param = new MemberModel(types.GetValue(j).ToString(), "", FlagType.ParameterVar, Visibility.Public);
                                member.Parameters.Add(param);
                                j++;
                            }

                            // Function's return type
                            member.Type = types.GetValue(types.Length - 1).ToString();
                        }
                        // Variable
                        else
                        {
                            flag = FlagType.Variable;
                            // Variable's type
                            member.Type = type;
                        }
                    }

                    member.Flags = flag;

                    list.Add(member);
                }
            }
            return(list);
        }
示例#20
0
 public virtual bool HandleGotoDeclaration(ScintillaControl sci, ASExpr expression)
 {
     return false;
 }
示例#21
0
        public static void EnvelopInFunction()
        {
            ScintillaNet.ScintillaControl sci = ASCompletion.Context.ASContext.CurSciControl;

            ASCompletion.Model.MemberModel mm =   ASContext.Context.CurrentMember;
            int startLine = sci.LineFromPosition(sci.SelectionStart);
            int endLine = sci.LineFromPosition(sci.SelectionEnd);

            if (mm == null || (startLine <(mm.LineFrom +2)) || (endLine >= mm.LineTo) )
            {
                MessageBox.Show("The text is not in a body function!!!");
                return;
            }

            ASExpr expr = new ASExpr();

            expr = GetExpression(sci, sci.CurrentPos, true);
            ASCompletion.Model.MemberList ml =  ASCompletion.Completion.ASComplete.ParseLocalVars(expr);

            QuickGenerator.UI.form.CreateFunctionForm form = new QuickGenerator.UI.form.CreateFunctionForm();

            form.ShowDialog();

            if (form.cancel) return;

            if (form.NameFunction.Trim().Length == 0)
            {
                MessageBox.Show("Name function missing!!");
                return;
            }

            string text = sci.SelText;

            string[] lines = text.Split('\n');

            string nl = ASCompletion.Completion.ASComplete.GetNewLineMarker(sci.EOLMode);
            StringBuilder sbBody = new StringBuilder(text.Length);
            int indent = sci.GetLineIndentation(mm.LineFrom);

            string tab = new string('\t', indent / sci.Indent);

            for (int x = 0; x < lines.Length; x++)
            {
                sbBody.Append(nl);
                sbBody.Append(tab);
                sbBody.Append('\t');
                sbBody.Append(lines[x].Trim());

            }

            int startSelection = sci.SelectionStart;
            int endSelection = sci.SelectionEnd;

            Regex regWords = new Regex("\\b[a-zA-Z][a-zA-Z0-9]*\\b");

            MatchCollection matchCollettion = regWords.Matches(text);
            Match mtc;
            List<string> words = new List<string>();
            for (int i = 0; i < matchCollettion.Count; i++)
            {
                mtc = matchCollettion[i];

                if (!words.Contains(mtc.Value))
                    words.Add(mtc.Value);

            }

            StringBuilder sbParams = new StringBuilder(100);
            StringBuilder nameFunction = new StringBuilder(100);
            nameFunction.Append(form.NameFunction);

            MemberModel member;

            List<MemberModel> membersToInsert = new List<MemberModel>();

            for (int i = 0; i < ml.Count; i++)
            {
                member = ml[i];
                int length = words.Count;

                for (int j = 0; j < length; j++)
                {
                    if (member.Name == words[j])
                    {
                        words.RemoveAt(j);

                        if (!(startLine <= member.LineFrom && endLine >= member.LineFrom))
                         membersToInsert.Add(member);

                        break;
                    }

                }

            }

            nameFunction.Append("(");

            if (membersToInsert.Count > 0)
            {
                foreach (MemberModel item in membersToInsert)
                {

                    sbParams.Append(item.Name);
                    sbParams.Append(":");
                    sbParams.Append(item.Type);
                    nameFunction.Append(item.Name);
                    sbParams.Append(", ");
                    nameFunction.Append(", ");
                }

                sbParams.Remove(sbParams.Length - 2, 2);
                nameFunction.Remove(nameFunction.Length - 2, 2);
            }

            nameFunction.Append(");");

            int pos = sci.PositionFromLine(mm.LineTo + 1);

            StringBuilder sb = new StringBuilder(200);
            tab = nl + tab;

            sb.Insert(0, "\nfunction [@1]([@2])\n{[@3]\n}");
            sb.Replace("\n", tab);
            sb.Replace("[@1]", form.NameFunction);
            sb.Replace("[@2]", sbParams.ToString());
            sb.Replace("[@3]", sbBody.ToString());

            sci.BeginUndoAction();

            sci.InsertText(pos,sb.ToString());
            int currentLine = sci.LineFromPosition(startSelection);
            int oldIndent = sci.GetLineIndentation(currentLine );

            sci.SetSel(startSelection, endSelection);

            sci.ReplaceSel("");

            if (form.writeNameFunction)
            {

                int newIndent = sci.GetLineIndentation(currentLine);
                sci.InsertText(startSelection, nameFunction.ToString());

                if (oldIndent != newIndent)
                {
                    sci.SetLineIndentation(currentLine,oldIndent);
                }
                sci.LineEnd();

            }

            sci.EndUndoAction();
        }