Browse Source

add folding for Imports in VB

pull/703/head
Siegfried Pammer 10 years ago
parent
commit
3844ca3036
  1. 63
      ILSpy/VB/VBTextOutputFormatter.cs

63
ILSpy/VB/VBTextOutputFormatter.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.ILSpy.VB
{ {
readonly ITextOutput output; readonly ITextOutput output;
readonly Stack<AstNode> nodeStack = new Stack<AstNode>(); readonly Stack<AstNode> nodeStack = new Stack<AstNode>();
bool firstImport, lastImport;
public VBTextOutputFormatter(ITextOutput output) public VBTextOutputFormatter(ITextOutput output)
{ {
@ -43,28 +45,36 @@ namespace ICSharpCode.ILSpy.VB
public void StartNode(AstNode node) public void StartNode(AstNode node)
{ {
// var ranges = node.Annotation<List<ILRange>>(); // var ranges = node.Annotation<List<ILRange>>();
// if (ranges != null && ranges.Count > 0) // if (ranges != null && ranges.Count > 0)
// { // {
// // find the ancestor that has method mapping as annotation // // find the ancestor that has method mapping as annotation
// if (node.Ancestors != null && node.Ancestors.Count() > 0) // if (node.Ancestors != null && node.Ancestors.Count() > 0)
// { // {
// var n = node.Ancestors.FirstOrDefault(a => a.Annotation<MemberMapping>() != null); // var n = node.Ancestors.FirstOrDefault(a => a.Annotation<MemberMapping>() != null);
// if (n != null) { // if (n != null) {
// MemberMapping mapping = n.Annotation<MemberMapping>(); // MemberMapping mapping = n.Annotation<MemberMapping>();
// //
// // add all ranges // // add all ranges
// foreach (var range in ranges) { // foreach (var range in ranges) {
// mapping.MemberCodeMappings.Add(new SourceCodeMapping { // mapping.MemberCodeMappings.Add(new SourceCodeMapping {
// ILInstructionOffset = range, // ILInstructionOffset = range,
// SourceCodeLine = output.CurrentLine, // SourceCodeLine = output.CurrentLine,
// MemberMapping = mapping // MemberMapping = mapping
// }); // });
// } // }
// } // }
// } // }
// } // }
if (nodeStack.Count == 0) {
if (node is ImportsStatement) {
firstImport = !(node.PrevSibling is ImportsStatement);
lastImport = !(node.NextSibling is ImportsStatement);
} else {
firstImport = false;
lastImport = false;
}
}
nodeStack.Push(node); nodeStack.Push(node);
} }
@ -100,6 +110,11 @@ namespace ICSharpCode.ILSpy.VB
return; return;
} }
if (firstImport) {
output.MarkFoldStart(defaultCollapsed: true);
firstImport = false;
}
output.Write(identifier); output.Write(identifier);
} }
@ -198,6 +213,10 @@ namespace ICSharpCode.ILSpy.VB
public void NewLine() public void NewLine()
{ {
if (lastImport) {
output.MarkFoldEnd();
lastImport = false;
}
output.WriteLine(); output.WriteLine();
} }

Loading…
Cancel
Save