Пример #1
0
        private List <Completion> memberCompletion(ITextSnapshot snapshot, int start, int line, int column)
        {
            List <Completion> memberCompletion = new List <Completion>();
            AstNode           foundNode        = null;

            //Replace '.' with ';' to avoid parse errors
            Span dotSpan = new Span(start, 1);

            snapshot = snapshot.TextBuffer.Delete(dotSpan);

            snapshot = snapshot.TextBuffer.Insert(dotSpan.Start, ";");

            //StaDynParser parser = new StaDynParser(snapshot.TextBuffer, FileUtilities.Instance.getCurrentOpenDocumentFilePath());

            //Parse source
            StaDynSourceFileAST parseResult;// = parser.parseSource();
            StaDynParser        parser = new StaDynParser();

            parser.parseAll();
            parseResult = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath());

            //Replace ';' with '.'
            snapshot = snapshot.TextBuffer.Delete(dotSpan);
            snapshot = snapshot.TextBuffer.Insert(dotSpan.Start, ".");

            //parseResult = DecorateAST.Instance.completeDecorateAndUpdate(parseResult);
            if (parseResult == null || parseResult.Ast == null)
            {
                return(memberCompletion);
            }

            char previousChar = snapshot.GetText(start - 1, 1)[0];

            column += 1;
            //Previous node is a MthodCall or Cast
            if (previousChar == ')')
            {
                //Start point is the ')', not the '.', so start-1
                //foundNode = this.getCurrentInvocation(parseResult, snapshot, start - 1, line, column);
                foundNode = StaDynIntellisenseHelper.Instance.getCurrentInvocation(parseResult, snapshot, start - 1, line, column);
                if (!(foundNode is InvocationExpression) && !(foundNode is NewExpression))
                {
                    foundNode = this.getCurrentCast(parseResult, snapshot, start - 1, line, column);
                }
            }
            //Previous node is ArrayAcces
            else if (previousChar == ']')
            {
                foundNode = this.getCurrentArray(parseResult, snapshot, start, line, column);
            }
            else
            {
                //Node search
                //foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column));
                foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(parseResult.FileName, line, column));
            }


            if (foundNode == null)
            {
                return(null);
            }

            TypeExpression type = (TypeExpression)foundNode.AcceptOperation(new GetNodeTypeOperation(), null);

            if (type == null)
            {
                return(null);
            }

            //Get the type members
            //double dispathcer pattern
            AccessModifier[] members = (AccessModifier[])type.AcceptOperation(new GetMembersOperation(), null);

            string displayName, description;
            bool   duplicate = false;

            foreach (AccessModifier member in members)
            {
                duplicate   = false;
                displayName = member.MemberIdentifier;
                description = displayName;

                if (member.Type != null)
                {
                    //description = member.Type.FullName;
                    description = member.Type.AcceptOperation(new GetTypeSystemName(), null) as string;
                    if (String.IsNullOrEmpty(description))
                    {
                        description = displayName;
                    }
                }
                ImageSource image = CompletionGlyph.Instance.getImage(member.Type, this._glyphService);

                //Completion element = new Completion("." + displayName, "." + displayName, description, image, displayName);

                Completion element = new Completion(displayName, "." + displayName, description, image, displayName);

                //Avoid adding duplicate members
                foreach (Completion completion in memberCompletion)
                {
                    if (completion.DisplayText == element.DisplayText)
                    {
                        if (completion.Description != description)
                        {
                            completion.Description += @" \/ " + description;
                        }
                        duplicate = true;
                        break;
                    }
                }
                if (!duplicate)
                {
                    memberCompletion.Add(element);
                }
                //memberCompletion.Add(element);
            }

            //Sort the elements
            memberCompletion.Sort((x, y) => string.Compare(x.DisplayText, y.DisplayText));

            //Remove duplicates
            //List<Completion> unique = new List<Completion>(memberCompletion.Distinct<Completion>(new CompletionComparer()));

            return(memberCompletion);
        }