Ejemplo n.º 1
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            if (firsttime)
            {
                bool newversion;
                _languangeService.Parse(_buffer, out newversion);
                firsttime = false;
            }

            ITextSnapshot currentSnapshot = _buffer.CurrentSnapshot;

            var ts = _languangeService.GetClassificationInfo(filepath);

            var lines = currentSnapshot.Lines.ToArray();

            foreach (var t in ts)
            {
                TextSpan scope = t.Item2;
                if (t.Item4 == SQDeclarationType.Class ||
                    t.Item4 == SQDeclarationType.Enum)
                {
                    scope = t.Item1;
                }
                if (scope.iEndLine == -1 || scope.iStartLine == -1 ||
                    scope.iEndLine >= currentSnapshot.LineCount || scope.iStartLine >= currentSnapshot.LineCount)
                {
                    continue;
                }

                int           length         = 0;
                string        collpasedlabel = t.Item3;
                SnapshotPoint?start          = null;
                try
                {
                    var startLine = lines[scope.iStartLine];
                    var endLine   = lines[scope.iEndLine];
                    start  = startLine.Start + scope.iStartIndex;
                    length = (endLine.Start - startLine.Start) + scope.iEndIndex - scope.iStartIndex;
                    if (start.Value.Position + length >= currentSnapshot.Length)
                    {
                        length = currentSnapshot.Length - start.Value.Position;
                    }
                }
                catch (Exception)
                {
                    length = 0;
                }
                if (length > 0 && start != null)
                {
                    bool         update = false;
                    SnapshotSpan snap   = new SnapshotSpan(start.Value, length);
                    foreach (var nspan in spans)
                    {
                        var line = currentSnapshot.GetLineFromPosition(nspan.Start);
                        if (line.Extent.IntersectsWith(snap))
                        {
                            update = true;
                            break;
                        }
                    }
                    if (!update)
                    {
                        continue;
                    }

                    if (ForceNewVersion)
                    {
                        TagsChanged(this, new SnapshotSpanEventArgs(snap));
                    }
                    switch (t.Item4)
                    {
                    case SQDeclarationType.AttributeScope:
                        yield return(new TagSpan <ClassificationTag>(snap, _attribtag)); break;

                    case SQDeclarationType.CommentScope:
                        yield return(new TagSpan <ClassificationTag>(snap, _commenttag)); break;

                    case SQDeclarationType.LiteralScope:
                        yield return(new TagSpan <ClassificationTag>(snap, _stringtag)); break;

                    case SQDeclarationType.Extend:
                    case SQDeclarationType.Class:
                        yield return(new TagSpan <ClassificationTag>(snap, _classtag)); break;

                    case SQDeclarationType.Enum:
                        yield return(new TagSpan <ClassificationTag>(snap, _enumtag)); break;

                    case SQDeclarationType.SubName:
                        yield return(new TagSpan <ClassificationTag>(snap, _subnametag)); break;

                    case SQDeclarationType.Number:
                        yield return(new TagSpan <ClassificationTag>(snap, _numberictag)); break;

                    case SQDeclarationType.KeyWord:
                        yield return(new TagSpan <ClassificationTag>(snap, _keywordtag)); break;
                    }
                }
            }
            ForceNewVersion = false;

            /* if (cachekeys != null)
             * {
             *   foreach (var kwspan in cachekeys)
             *   {
             *       bool cancel = false;
             *       foreach (var nokwspan in nokeywordspans)
             *       {
             *           if (nokwspan.Contains(kwspan.Position))//nokwspan.IntersectsWith(kwspan))
             *           {
             *               cancel = true;
             *               break;
             *           }
             *       }
             *       if (cancel)
             *           yield break;
             *
             *       SnapshotSpan keysnap = new SnapshotSpan(currentSnapshot, kwspan.Position, kwspan.Length);
             *         if (ForceNewVersion)
             *       //   TagsChanged(this, new SnapshotSpanEventArgs(keysnap));
             *
             *       yield return new TagSpan<ClassificationTag>(keysnap, _keywordtag);
             *   }
             * }*/
            /*foreach (var t in _currentTags)
             * {
             *  yield return t;
             * }*/
        }
Ejemplo n.º 2
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("SQCompletionSource");
            }

            if (!_languageService.IntellisenseEnabled)
            {
                return;
            }

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

            if (triggerPoint == null)
            {
                return;
            }
            var           line  = triggerPoint.GetContainingLine();
            SnapshotPoint start = triggerPoint;

            /*TextExtent extent = _navigator.GetExtentOfWord(triggerPoint);
             * string ex = extent.Span.ToString();*/

            while (start > line.Start && !char.IsWhiteSpace((start - 1).GetChar()))
            {
                start -= 1;
            }

            _languageService.Parse();
            SQInstance inst = _languageService.LanguageInstance;
            //Dictionary<string, Completion> completions = new Dictionary<string, Completion>();
            int lineid = line.LineNumber;
            int index  = 0;
            var value  = inst.Dive(_buffer, lineid, index);
            //var value = inst.Dive(lineid, index);
            List <SQDeclaration> collected = new List <SQDeclaration>();

            inst.CollectNodes(collected, value);
            Dictionary <string, Completion> completions = new Dictionary <string, Completion>(collected.Count);

            /*var keyword = _glyphService.GetGlyph(StandardGlyphGroup.GlyphKeyword, StandardGlyphItem.GlyphItemPublic);
             * foreach (string key in SQLanguageServiceEX.KeyWords.Keys)
             * {
             *  Completion c = new SQCompletion(key, key, "Squirrel Reserved Word", keyword, key) { Url = "N/A", Tag = null };
             *  completions[key] = c;
             * }*/
            foreach (SQDeclaration d in collected)
            {
                if (d.Type == SQDeclarationType.Function ||
                    d.Type == SQDeclarationType.Variable ||
                    d.Type == SQDeclarationType.Class ||
                    d.Type == SQDeclarationType.Enum)
                {
                    string classname   = d.Parent != null && d.Parent.Type != SQDeclarationType.File ? d.Parent.Name : "";
                    string key         = d.Name;
                    string description = key;
                    string name        = key;
                    if (!string.IsNullOrEmpty(classname))
                    {
                        description = classname + "::" + key;
                    }
                    BitmapImage image = null;
                    string      id    = "";
                    switch (d.Type)
                    {
                    case SQDeclarationType.Class:
                        image = SQVSUtils.ClassIcon; id = "class"; break;

                    case SQDeclarationType.Function:
                    {
                        image = SQVSUtils.FunctionIcon; id = "function";
                        //des
                        SQDeclaration.SQFunction f = (SQDeclaration.SQFunction)d;
                        var parameters             = f.GetParameterNames();
                        description += string.Format("({0})", string.Join(", ", parameters.ToArray()));
                        break;
                    }

                    case SQDeclarationType.Variable:
                        image = SQVSUtils.FieldIcon; id = "variable"; break;

                    case SQDeclarationType.Enum:
                        image = SQVSUtils.EnumIcon; id = "enum"; break;
                    }
                    Completion c = new SQCompletion(key, key, string.Format("{0} {1}", id, description), image, "hahaha" + classname + key)
                    {
                        Url = d.Url, Tag = d
                    };
                    completions[description] = c;
                }
            }
            var applicableTo = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);

            Completion[]             cs      = completions.Values.ToArray();
            IEnumerable <Completion> ordered = cs.OrderBy(x => { return(x.DisplayText); });

            completionSets.Add(new CompletionSet("Declarations", "Declarations", applicableTo, ordered, Enumerable.Empty <Completion>()));
        }