Example #1
0
 internal ParserLauncher(ITextBuffer textBuffer, string fileName)
 {
     this.fileName   = fileName;
     this.textBuffer = textBuffer;
     //this.Parser = new StaDynParser(textBuffer, fileName);
     this.Parser         = new StaDynParser();
     textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(TextBuffer_Changed);
 }
Example #2
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
            {
                throw new ObjectDisposedException("StaDynQuickInfoSource");
            }

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            char c = triggerPoint.GetChar();

            if (triggerPoint == null || Char.IsWhiteSpace(c))
            {
                return;
            }

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

            ////Parse source
            //StaDynSourceFileAST parseResult = parser.parseSource();
            ////parseResult = DecorateAST.Instance.completeDecorateAST(parseResult);
            ////parseResult= DecorateAST.Instance.completeDecorateAndUpdate(parseResult.FileName, true);
            //parseResult = DecorateAST.Instance.completeDecorateAndUpdate(parseResult);
            StaDynParser parser = new StaDynParser();

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

            if (parseResult == null || parseResult.Ast == null)
            {
                return;
            }

            foreach (IMappingTagSpan <StaDynTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                var tagType = curTag.Tag.type;

                var tagSpan = curTag.Span.GetSpans(_buffer).First();
                applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);

                string output = String.Empty;

                switch (tagType)
                {
                case StaDynTokenTypes.Text:
                case StaDynTokenTypes.Identifier:
                case StaDynTokenTypes.String:
                case StaDynTokenTypes.TypeDefinition:
                case StaDynTokenTypes.DynamicVar:
                case StaDynTokenTypes.Literal:
                    //Gets the tag info
                    output = this.getQuickInfo(curTag, parseResult);
                    break;

                case StaDynTokenTypes.Operator:
                case StaDynTokenTypes.Delimiter:
                case StaDynTokenTypes.WhiteSpace:
                    //Nothing to do
                    continue;

                case StaDynTokenTypes.Keyword:
                case StaDynTokenTypes.LineComment:
                case StaDynTokenTypes.Comment:
                case StaDynTokenTypes.Number:
                    if (curTag.Tag.StaDynToken.getText() == ".")
                    {
                        continue;
                    }
                    //Show the same tag
                    output = curTag.Tag.StaDynToken.getText();
                    break;

                default:
                    break;
                }

                quickInfoContent.Add(output);
            }
        }
Example #3
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);
        }