public static List <TextSpan> GetEmptyRegions(VSTextView textView) { List <TextSpan> allRegions = new List <TextSpan>(); List <TextSpan> textSpans = GetAllRegions(textView.GetWholeText()); for (int i = 0; i < textSpans.Count; i++) { TextSpan region = textSpans[i]; bool hasContent = false; //检测start和end之间是否都是空行 for (int j = region.iStartLine + 1; j <= region.iEndLine - 1; j++) { string s = textView.GetOneLineText(j); if (!string.IsNullOrEmpty(s.Trim())) { //region之间有内容 hasContent = true; break; } } if (!hasContent) { allRegions.Add(region); } } return(allRegions); }
public static List <int> GetBlankLiens(VSTextView textView) { List <int> lines = new List <int>(); using (IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(textView.GetWholeText()))) { parser.ParseMethodBodies = false; parser.Parse(); List <ISpecial> currentSpecials = parser.Lexer.SpecialTracker.CurrentSpecials; TextSpan textSpan = new TextSpan(); foreach (ISpecial currentSpecial in currentSpecials) { if (currentSpecial is BlankLine) { BlankLine region = currentSpecial as BlankLine; lines.Add(region.StartPosition.Line - 1); } } } return(lines); }