示例#1
0
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer)
            where T : ITag
        {
            ITagger <IOutliningRegionTag> CreateBufferTagger()
            {
                Language language = DocumentItem.GetLanguage(buffer);

                ThreadHelper.ThrowIfNotOnUIThread();
                ITagger <IOutliningRegionTag> tagger;

                if (MainPackage.RegionOptions.IsSupported(language) && ScanInfo.TryGet(language, out ScanInfo scanInfo))
                {
                    tagger = new OutliningTagger(buffer, scanInfo);
                }
                else
                {
                    tagger = NonOutliningTagger.Instance;
                }

                return(tagger);
            }

            ITagger <IOutliningRegionTag> result = buffer.Properties.GetOrCreateSingletonProperty(CreateBufferTagger);

            return(result as ITagger <T>);
        }
示例#2
0
        public string Stream(Language language)
        {
            string singleLineCommentDelimiter = null;

            if (ScanInfo.TryGet(language, out ScanInfo scanInfo))
            {
                singleLineCommentDelimiter = scanInfo.TryGetSingleLineCommentDelimiter();
            }

            StringBuilder sb = new();

            int  numLines    = this.lines.Length;
            bool startOfLine = true;

            for (int i = 0; i < numLines; i++)
            {
                string line = this.lines[i];
                RemoveLinePrefix(ref line, singleLineCommentDelimiter);

                if (string.IsNullOrEmpty(line))
                {
                    sb.Append("\r\n");
                    startOfLine = true;
                }
                else
                {
                    if (startOfLine)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append("\r\n");
                        }
                    }
                    else
                    {
                        sb.Append(' ');
                    }

                    sb.Append(line);
                    startOfLine = false;
                }
            }

            if (this.endsInHardReturn)
            {
                sb.Append("\r\n");
            }

            return(sb.ToString());
        }
示例#3
0
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer)
            where T : ITag
        {
            Func <OutliningTagger> createBufferTagger = () =>
            {
                Language language = DocumentItem.GetLanguage(buffer);
                ScanInfo scanInfo;
                ScanInfo.TryGet(language, out scanInfo);
                return(new OutliningTagger(buffer, scanInfo));
            };

            OutliningTagger result = buffer.Properties.GetOrCreateSingletonProperty <OutliningTagger>(createBufferTagger);

            return(result as ITagger <T>);
        }
示例#4
0
        private static bool GetCommentStyle(
            Language language,
            bool useVsIndentation,
            bool preferEndDelimited,
            out string beginDelimiter,
            out string endDelimiter)
        {
            beginDelimiter = null;
            endDelimiter   = null;

            if (ScanInfo.TryGet(language, out ScanInfo scanInfo))
            {
                if (preferEndDelimited)
                {
                    (beginDelimiter, endDelimiter) = scanInfo.TryGetMultiLineCommentDelimiters();
                }

                // If multiLine was preferred but missing (e.g., VB), then we have to return the singleLine.
                if (string.IsNullOrEmpty(beginDelimiter))
                {
                    beginDelimiter = scanInfo.TryGetSingleLineCommentDelimiter();
                }

                // If singleLine was preferred but missing (e.g., HTML, XML), then we have to return the multiLine.
                if (!preferEndDelimited && string.IsNullOrEmpty(beginDelimiter))
                {
                    (beginDelimiter, endDelimiter) = scanInfo.TryGetMultiLineCommentDelimiters();
                }
            }

            switch (language)
            {
            case Language.VB:
                // VB's auto-formatter throws out leading indentation and indents all comments to
                // one level under their parent.  So I won't use my default indentation style for it.
                useVsIndentation = true;
                break;

            case Language.VBScript:
                // In VS 2012, the VBScript language service has selection bugs when commenting
                // and uncommenting, so I'll always use my indentation style for it.
                useVsIndentation = false;
                break;
            }

            return(useVsIndentation);
        }