Пример #1
0
        private IEnumerable <ITagSpan <IClassificationTag> > GetTags(IEnumerable <ITagSpan <IClassificationTag> > sourceSpans, ITextSnapshot snapshot)
        {
            var e = sourceSpans.GetEnumerator();

            try {
                IClassificationTag currentTag  = null;
                SnapshotSpan       currentSpan = new SnapshotSpan();
                while (e.MoveNext())
                {
                    var c1 = e.Current;
                    currentSpan = c1.Span;
                    currentTag  = c1.Tag;
                    while (e.MoveNext())
                    {
                        var c2 = e.Current;
                        if (IsSameTag(currentTag, c2) && AreAdjacent(currentSpan, c2))
                        {
                            currentSpan = new SnapshotSpan(currentSpan.Start, c2.Span.End - currentSpan.Start);
                        }
                        else
                        {
                            yield return(c1);

                            yield return(c2);
                        }
                    }
                    yield return(new TagSpan <IClassificationTag>(currentSpan, currentTag));
                }
            } finally {
                e.Dispose();
            }
        }
Пример #2
0
        private String getKeywordAt(List <IMappingTagSpan <IClassificationTag> > tagList, int tagIndex)
        {
            string keyword = null;

            if (tagIndex < tagList.Count)
            {
                var buffer = _textView.TextBuffer;
                IClassificationTag currentTag  = tagList[tagIndex].Tag;
                IMappingSpan       currentSpan = tagList[tagIndex].Span;
                //
                if (currentTag.ClassificationType.IsOfType("keyword"))
                {
                    var spans = currentSpan.GetSpans(buffer);
                    if (spans.Count > 0)
                    {
                        SnapshotSpan kwSpan = spans[0];
                        keyword = kwSpan.GetText();
                        keyword = keyword.ToUpper();
                    }
                }
            }
            return(keyword);
        }
Пример #3
0
 NumberTaggerProvider(IClassificationTypeRegistryService classificationTypeRegistryService, DebuggerSettings debuggerSettings)
 {
     stringClassificationTag = new ClassificationTag(classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.Number));
     this.debuggerSettings   = debuggerSettings;
 }
Пример #4
0
 private bool IsSameTag(IClassificationTag c1, ITagSpan <IClassificationTag> c2)
 {
     return(c1.ClassificationType.Classification == c2.Tag.ClassificationType.Classification);
 }
Пример #5
0
 UriClassificationTaggerProvider(IViewTagAggregatorFactoryService viewTagAggregatorFactoryService, IThemeClassificationTypeService themeClassificationTypeService)
 {
     this.viewTagAggregatorFactoryService = viewTagAggregatorFactoryService;
     classificationTag = new ClassificationTag(themeClassificationTypeService.GetClassificationType(TextColor.Url));
 }
Пример #6
0
        /// <summary>
        /// Get the first keyword in Line. The modifiers (Private, Protected, ... ) are ignored
        /// If the first Keyword is a Comment, "//" is returned
        /// </summary>
        /// <param name="line">The line to analyze</param>
        /// <param name="doSkipped">Bool value indicating if a "DO" keyword has been skipped</param>
        /// <param name="minIndent"></param>
        /// <returns></returns>
        private String getFirstKeywordInLine(ITextSnapshotLine line, out bool doSkipped, out int minIndent)
        {
            minIndent = -1;
            doSkipped = false;
            List <IMappingTagSpan <IClassificationTag> > tagList = GetTagsInLine(line);
            String keyword = "";

            //
            if (tagList.Count > 0)
            {
                var          buffer      = this._textView.TextBuffer;
                IMappingSpan currentSpan = tagList[0].Span;
                ///////////////////////////////////////////
                //SnapshotPoint? snapPointFirst = currentSpan.Start.GetPoint(buffer, PositionAffinity.Predecessor);
                //// Extract the start of line
                //SnapshotSpan toIndent = new SnapshotSpan(line.Start, snapPointFirst.Value.Position - line.Start.Position);
                //String startOfLine = toIndent.GetText();
                //// Convert Tabs to Spaces
                //startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize));
                //// So, at least, to align to previous line, we will need...
                //minIndent = startOfLine.Length;
                ////////////////////////////////////////////
                String startOfLine = line.GetText();
                startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize));
                // So, at least, to align to previous line, we will need...
                minIndent = (startOfLine.Length - startOfLine.TrimStart(' ').Length);
                //
                int tagIndex = 0;
                while (tagIndex < tagList.Count)
                {
                    IClassificationTag currentTag = tagList[tagIndex].Tag;
                    currentSpan = tagList[tagIndex].Span;
                    //
                    if (currentTag.ClassificationType.IsOfType("keyword"))
                    {
                        var spans = currentSpan.GetSpans(buffer);
                        if (spans.Count > 0)
                        {
                            SnapshotSpan kwSpan = spans[0];
                            keyword = kwSpan.GetText();
                            keyword = keyword.ToUpper();
                            // it could be modifier...
                            switch (keyword)
                            {
                            case "PROTECTED":
                            case "INTERNAL":
                            case "HIDDEN":
                            case "PRIVATE":
                            case "EXPORT":
                            case "PUBLIC":
                            case "STATIC":
                            case "SEALED":
                            case "ABSTRACT":
                            case "VIRTUAL":
                            case "PARTIAL":
                                tagIndex++;
                                keyword = "";
                                continue;

                            case "DO":
                                tagIndex++;
                                keyword   = "";
                                doSkipped = true;
                                continue;

                            default:
                                break;
                            }
                        }
                    }
                    else if (currentTag.ClassificationType.IsOfType("comment"))
                    {
                        //
                        keyword = "//";
                    }
                    // out please
                    break;
                }
                ;
            }
            return(keyword);
        }
Пример #7
0
        private int?alignToSpecificTokens(ITextSnapshotLine currentLine, String tokenList)
        {
            int            indentValue = 0;
            bool           found       = false;
            Stack <String> context     = new Stack <String>();

            //
            try
            {
                String[] possibleTokens = tokenList.Split(',');
                // On what line are we ?
                int lineNumber = currentLine.LineNumber;
                // We need to analyze the Previous line
                lineNumber = lineNumber - 1;
                while (lineNumber > 0)
                {
                    // We need to analyze the Previous line
                    lineNumber = lineNumber - 1;
                    ITextSnapshotLine line = currentLine.Snapshot.GetLineFromLineNumber(lineNumber);
                    List <IMappingTagSpan <IClassificationTag> > tagList = GetTagsInLine(line);
                    String currentKeyword = "";
                    //
                    if (tagList.Count > 0)
                    {
                        var          buffer      = this._textView.TextBuffer;
                        IMappingSpan currentSpan = tagList[0].Span;

                        /*
                         * SnapshotPoint? snapPointFirst = currentSpan.Start.GetPoint(buffer, PositionAffinity.Predecessor);
                         * // Extract the start of line
                         * SnapshotSpan toIndent = new SnapshotSpan(line.Start, snapPointFirst.Value.Position - line.Start.Position);
                         * String startOfLine = toIndent.GetText();
                         * // Convert Tabs to Spaces
                         * startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize));
                         * // So, at least, to align to previous line, we will need...
                         * indentValue = startOfLine.Length;
                         */
                        String startOfLine = line.GetText();
                        startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize));
                        // So, at least, to align to previous line, we will need...
                        indentValue = (startOfLine.Length - startOfLine.TrimStart(' ').Length);
                        //
                        IClassificationTag currentTag = tagList[0].Tag;
                        currentSpan = tagList[0].Span;
                        //
                        if (currentTag.ClassificationType.IsOfType("keyword"))
                        {
                            var spans = currentSpan.GetSpans(buffer);
                            if (spans.Count > 0)
                            {
                                SnapshotSpan kwSpan = spans[0];
                                currentKeyword = kwSpan.GetText();
                                currentKeyword = currentKeyword.ToUpper();
                                if (possibleTokens.Contains <String>(currentKeyword))
                                {
                                    if (context.Count == 0)
                                    {
                                        found = true;
                                        break;
                                    }
                                    else
                                    {
                                        tokenList      = context.Pop();
                                        possibleTokens = tokenList.Split(',');
                                    }
                                }
                                // Here we should also check for nested construct or we might get false positive...
                                string outdentToken;
                                if ((outdentToken = this.searchSpecialOutdentKeyword(currentKeyword)) != null)
                                {
                                    context.Push(tokenList);
                                    tokenList      = outdentToken;
                                    possibleTokens = tokenList.Split(',');
                                }
                            }
                        }
                        //
                        indentValue = 0;
                    }
                }
            }
            finally
            {
                //
            }
            //
            if (found)
            {
                return(indentValue);
            }
            else
            {
                return(null);
            }
        }
Пример #8
0
 internal MetaTaggerProvider([Import] ITableManagerProvider provider, [Import] ITextDocumentFactoryService textDocumentFactoryService, [Import] IClassificationTypeRegistryService classificationRegistryService)
     : base(provider, textDocumentFactoryService, classificationRegistryService, MetaLanguage.Instance)
 {
     this.TypeClassificationTag = new ClassificationTag(this.ClassificationRegistryService.GetClassificationType(MetaClassificationTypes.Type));
     _syntaxFacts = MetaLanguage.Instance.SyntaxFacts;
 }
Пример #9
0
        private int?alignToSpecificToken_(ITextSnapshotLine currentLine, String token)
        {
            int  indentValue = 0;
            bool found       = false;

            try
            {
                // On what line are we ?
                int lineNumber = currentLine.LineNumber;
                // We need to analyze the Previous line
                lineNumber = lineNumber - 1;
                while (lineNumber > 0)
                {
                    // We need to analyze the Previous line
                    lineNumber = lineNumber - 1;
                    ITextSnapshotLine line = currentLine.Snapshot.GetLineFromLineNumber(lineNumber);
                    List <IMappingTagSpan <IClassificationTag> > tagList = GetTagsInLine(line);
                    String keyword = "";
                    //
                    if (tagList.Count > 0)
                    {
                        var          buffer      = this._textView.TextBuffer;
                        IMappingSpan currentSpan = tagList[0].Span;

                        /*
                         * SnapshotPoint? snapPointFirst = currentSpan.Start.GetPoint(buffer, PositionAffinity.Predecessor);
                         * // Extract the start of line
                         * SnapshotSpan toIndent = new SnapshotSpan(line.Start, snapPointFirst.Value.Position - line.Start.Position);
                         * String startOfLine = toIndent.GetText();
                         * // Convert Tabs to Spaces
                         * startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize));
                         * // So, at least, to align to previous line, we will need...
                         * indentValue = startOfLine.Length;
                         */
                        String startOfLine = line.GetText();
                        startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize));
                        // So, at least, to align to previous line, we will need...
                        indentValue = (startOfLine.Length - startOfLine.TrimStart(' ').Length);
                        //
                        IClassificationTag currentTag = tagList[0].Tag;
                        currentSpan = tagList[0].Span;
                        //
                        if (currentTag.ClassificationType.IsOfType("keyword"))
                        {
                            var spans = currentSpan.GetSpans(buffer);
                            if (spans.Count > 0)
                            {
                                SnapshotSpan kwSpan = spans[0];
                                keyword = kwSpan.GetText();
                                keyword = keyword.ToUpper();
                                if (keyword == token)
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                        //
                        indentValue = 0;
                    }
                }
            }
            finally
            {
                //
            }
            //
            if (found)
            {
                return(indentValue);
            }
            else
            {
                return(null);
            }
        }
Пример #10
0
 BookmarkNameTaggerProvider(IClassificationTypeRegistryService classificationTypeRegistryService, BookmarksSettings bookmarksSettings)
 {
     nameClassificationTag  = new ClassificationTag(classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.BookmarkName));
     this.bookmarksSettings = bookmarksSettings;
 }
Пример #11
0
 ThreadNameTaggerProvider(IClassificationTypeRegistryService classificationTypeRegistryService, DebuggerSettings debuggerSettings)
 {
     nameClassificationTag = new ClassificationTag(classificationTypeRegistryService.GetClassificationType(ThreadFormatter.NameColorClassificationTypeName));
     this.debuggerSettings = debuggerSettings;
 }
 public static bool IsComment(this IClassificationTag tag)
 {
     return(tag.ClassificationType.Classification.ContainsCaseIgnored("comment"));
 }
 public static bool IsXmlDoc(this IClassificationTag tag)
 {
     return(tag.ClassificationType.Classification.ContainsCaseIgnored("doc"));
 }
 public ClassificationTagDescriptor(IClassificationTag classificationTag)
 {
     ClassificationType = classificationTag.ClassificationType;
 }
Пример #15
0
 public static TextTaggerBase GetRegexTagger(IClassificationTag tag, string pattern, int useGroup, StringComparison comparison)
 {
     return(new RegexTagger {
         Pattern = pattern, StringComparison = comparison, UseGroup = useGroup, Tag = tag
     });
 }
Пример #16
0
 public static TextTaggerBase GetStartWithTagger(IClassificationTag tag, string prefix, bool skipLeadingWhitespace, StringComparison comparison)
 {
     return(new StartWithTagger {
         Prefix = prefix, StringComparison = comparison, Tag = tag, SkipLeadingWhitespace = skipLeadingWhitespace
     });
 }