示例#1
0
        public static bool IsCompletionAllowed(IEditorData Editor, char enteredChar)
        {
            if (Editor.CaretOffset > 0)
            {
                if (Editor.CaretLocation.Line == 1 && Editor.ModuleCode.Length > 0 && Editor.ModuleCode[0] == '#')
                {
                    return(false);
                }

                if (enteredChar == '.' || enteredChar == '_')
                {
                    // Don't complete on a double/multi-dot
                    if (Editor.CaretOffset > 1 && Editor.ModuleCode[Editor.CaretOffset - 2] == enteredChar)
                    {
                        // ISSUE: When a dot was typed, off-1 is the dot position,
                        // if a letter was typed, off-1 is the char before the typed letter..
                        return(false);
                    }
                }
                // If typing a begun identifier, return immediately
                else if ((DTokens.IsIdentifierChar(enteredChar) || enteredChar == '\0') &&
                         DTokens.IsIdentifierChar(Editor.ModuleCode[Editor.CaretOffset - 1]))
                {
                    return(false);
                }

                return(!CaretContextAnalyzer.IsInCommentAreaOrString(Editor.ModuleCode, Editor.CaretOffset));
            }

            return(true);
        }
        private bool GetVisibleMemberFilter(IEditorData Editor, char enteredChar, ref MemberFilter visibleMembers, ref IStatement curStmt)
        {
            if (trackVars == null)
            {
                // --> Happens if no actual declaration syntax given --> Show types/keywords anyway
                visibleMembers = MemberFilter.Types | MemberFilter.Keywords | MemberFilter.TypeParameters;
            }
            else
            {
                var n  = trackVars.LastParsedObject as INode;
                var dv = n as DVariable;
                if (trackVars.ExpectingNodeName)
                {
                    if (dv != null && dv.IsAlias && dv.Type == null)
                    {
                        // Show completion because no aliased type has been entered yet
                    }
                    else if (n != null && n.NameHash == 0 && enteredChar != '\0')
                    {
                        return(false);
                    }
                }

                else if (trackVars.LastParsedObject is TokenExpression &&
                         DTokens.BasicTypes[(trackVars.LastParsedObject as TokenExpression).Token] &&
                         DTokens.IsIdentifierChar(enteredChar))
                {
                    return(false);
                }

                if (trackVars.LastParsedObject is Modifier)
                {
                    var attr = trackVars.LastParsedObject as Modifier;

                    if (attr.IsStorageClass && attr.Token != DTokens.Abstract)
                    {
                        return(false);
                    }
                }

                else if (trackVars.IsParsingBaseClassList)
                {
                    var dc = parsedBlock as DClassLike;
                    if (dc != null && dc.ClassType == DTokens.Interface)
                    {
                        visibleMembers = MemberFilter.Interfaces | MemberFilter.Templates;
                    }
                    else
                    {
                        visibleMembers = MemberFilter.Classes | MemberFilter.Interfaces | MemberFilter.Templates;
                    }
                    return(true);
                }

                if (trackVars.IsParsingAssignExpression)
                {
                    visibleMembers = MemberFilter.All;
                    return(true);
                }

                if ((trackVars.LastParsedObject is NewExpression && trackVars.IsParsingInitializer) ||
                    trackVars.LastParsedObject is TemplateInstanceExpression && ((TemplateInstanceExpression)trackVars.LastParsedObject).Arguments == null)
                {
                    visibleMembers = MemberFilter.Types;
                }
                else if (enteredChar == ' ')
                {
                    return(false);
                }
                // In class bodies, do not show variables
                else if (!(parsedBlock is BlockStatement || trackVars.IsParsingInitializer))
                {
                    bool showVariables = false;
                    var  dbn           = parsedBlock as DBlockNode;
                    if (dbn != null && dbn.StaticStatements != null && dbn.StaticStatements.Count > 0)
                    {
                        var ss = dbn.StaticStatements[dbn.StaticStatements.Count - 1];
                        if (Editor.CaretLocation > ss.Location && Editor.CaretLocation <= ss.EndLocation)
                        {
                            showVariables = true;
                        }
                    }

                    if (!showVariables)
                    {
                        visibleMembers = MemberFilter.All ^ MemberFilter.Variables;
                    }
                }

                // Hide completion if having typed a '0.' literal
                else if (trackVars.LastParsedObject is IdentifierExpression &&
                         (trackVars.LastParsedObject as IdentifierExpression).Format == LiteralFormat.Scalar)
                {
                    return(false);
                }

                /*
                 * Handle module-scoped things:
                 * When typing a dot without anything following, trigger completion and show types, methods and vars that are located in the module & import scope
                 */
                else if (trackVars.LastParsedObject is TokenExpression &&
                         ((TokenExpression)trackVars.LastParsedObject).Token == DTokens.Dot)
                {
                    visibleMembers = MemberFilter.Methods | MemberFilter.Types | MemberFilter.Variables | MemberFilter.TypeParameters;
                    curBlock       = Editor.SyntaxTree;
                    curStmt        = null;
                }

                // In a method, parse from the method's start until the actual caret position to get an updated insight
                if (visibleMembers.HasFlag(MemberFilter.Variables) &&
                    curBlock is DMethod &&
                    parsedBlock is BlockStatement)
                {
                }
                else
                {
                    curStmt = null;
                }
            }
            return(true);
        }