|
|
|
@ -1,6 +1,6 @@ |
|
|
|
//
|
|
|
|
//
|
|
|
|
// AstFormattingVisitor.cs
|
|
|
|
// AstFormattingVisitor.cs
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Author:
|
|
|
|
// Author:
|
|
|
|
// Mike Krüger <mkrueger@novell.com>
|
|
|
|
// Mike Krüger <mkrueger@novell.com>
|
|
|
|
//
|
|
|
|
//
|
|
|
|
@ -24,6 +24,7 @@ |
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
// THE SOFTWARE.
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Diagnostics; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
@ -35,10 +36,23 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class AstFormattingVisitor : DepthFirstAstVisitor<object, object> |
|
|
|
public class AstFormattingVisitor : DepthFirstAstVisitor<object, object> |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
struct TextReplaceAction |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
internal readonly int Offset; |
|
|
|
|
|
|
|
internal readonly int RemovalLength; |
|
|
|
|
|
|
|
internal readonly string NewText; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TextReplaceAction(int offset, int removalLength, string newText) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this.Offset = offset; |
|
|
|
|
|
|
|
this.RemovalLength = removalLength; |
|
|
|
|
|
|
|
this.NewText = newText; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CSharpFormattingOptions policy; |
|
|
|
CSharpFormattingOptions policy; |
|
|
|
IDocument document; |
|
|
|
IDocument document; |
|
|
|
Script script; |
|
|
|
List<TextReplaceAction> changes = new List<TextReplaceAction> (); |
|
|
|
//List<TextReplaceAction> changes = new List<TextReplaceAction> ();
|
|
|
|
|
|
|
|
Indent curIndent = new Indent (); |
|
|
|
Indent curIndent = new Indent (); |
|
|
|
|
|
|
|
|
|
|
|
public int IndentLevel { |
|
|
|
public int IndentLevel { |
|
|
|
@ -67,22 +81,70 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
public string EolMarker { get; set; } |
|
|
|
public string EolMarker { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public AstFormattingVisitor (CSharpFormattingOptions policy, IDocument document, Script script, bool tabsToSpaces = false, int indentationSize = 4) |
|
|
|
public AstFormattingVisitor (CSharpFormattingOptions policy, IDocument document, bool tabsToSpaces = false, int indentationSize = 4) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (policy == null) |
|
|
|
if (policy == null) |
|
|
|
throw new ArgumentNullException("policy"); |
|
|
|
throw new ArgumentNullException("policy"); |
|
|
|
if (document == null) |
|
|
|
if (document == null) |
|
|
|
throw new ArgumentNullException("document"); |
|
|
|
throw new ArgumentNullException("document"); |
|
|
|
if (script == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("script"); |
|
|
|
|
|
|
|
this.policy = policy; |
|
|
|
this.policy = policy; |
|
|
|
this.document = document; |
|
|
|
this.document = document; |
|
|
|
this.script = script; |
|
|
|
|
|
|
|
this.curIndent.TabsToSpaces = tabsToSpaces; |
|
|
|
this.curIndent.TabsToSpaces = tabsToSpaces; |
|
|
|
this.curIndent.TabSize = indentationSize; |
|
|
|
this.curIndent.TabSize = indentationSize; |
|
|
|
this.EolMarker = Environment.NewLine; |
|
|
|
this.EolMarker = Environment.NewLine; |
|
|
|
CorrectBlankLines = true; |
|
|
|
CorrectBlankLines = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Applies the changes to the input document.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public void ApplyChanges() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ApplyChanges(0, document.TextLength, document.Replace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ApplyChanges(int startOffset, int length) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ApplyChanges(startOffset, length, document.Replace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Applies the changes to the given Script instance.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public void ApplyChanges(Script script) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ApplyChanges(0, document.TextLength, script.Replace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ApplyChanges(int startOffset, int length, Script script) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ApplyChanges(startOffset, length, script.Replace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ApplyChanges(int startOffset, int length, Action<int, int, string> documentReplace) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int endOffset = startOffset + length; |
|
|
|
|
|
|
|
int lastChangeEnd = 0; |
|
|
|
|
|
|
|
int delta = 0; |
|
|
|
|
|
|
|
foreach (var change in changes.OrderBy(c => c.Offset)) { |
|
|
|
|
|
|
|
if (change.Offset < lastChangeEnd) { |
|
|
|
|
|
|
|
Debug.Fail("Detected overlapping change"); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lastChangeEnd = change.Offset + change.RemovalLength; |
|
|
|
|
|
|
|
if (change.Offset < startOffset) { |
|
|
|
|
|
|
|
// skip all changes in front of the begin offset
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} else if (change.Offset > endOffset) { |
|
|
|
|
|
|
|
// skip this change unless it depends on one that we already applied
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
documentReplace(change.Offset + delta, change.RemovalLength, change.NewText); |
|
|
|
|
|
|
|
delta += change.NewText.Length - change.RemovalLength; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
changes.Clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override object VisitCompilationUnit (CompilationUnit unit, object data) |
|
|
|
public override object VisitCompilationUnit (CompilationUnit unit, object data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -137,9 +199,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
public override object VisitUsingDeclaration (UsingDeclaration usingDeclaration, object data) |
|
|
|
public override object VisitUsingDeclaration (UsingDeclaration usingDeclaration, object data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(usingDeclaration.PrevSibling is UsingDeclaration || usingDeclaration.PrevSibling is UsingAliasDeclaration)) |
|
|
|
if (!(usingDeclaration.PrevSibling is UsingDeclaration || usingDeclaration.PrevSibling is UsingAliasDeclaration)) |
|
|
|
EnsureBlankLinesBefore (usingDeclaration, policy.BlankLinesBeforeUsings); |
|
|
|
EnsureBlankLinesBefore (usingDeclaration, policy.BlankLinesBeforeUsings); |
|
|
|
if (!(usingDeclaration.NextSibling is UsingDeclaration || usingDeclaration.NextSibling is UsingAliasDeclaration)) |
|
|
|
if (!(usingDeclaration.NextSibling is UsingDeclaration || usingDeclaration.NextSibling is UsingAliasDeclaration)) |
|
|
|
EnsureBlankLinesAfter (usingDeclaration, policy.BlankLinesAfterUsings); |
|
|
|
EnsureBlankLinesAfter (usingDeclaration, policy.BlankLinesAfterUsings); |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -147,9 +209,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
public override object VisitUsingAliasDeclaration (UsingAliasDeclaration usingDeclaration, object data) |
|
|
|
public override object VisitUsingAliasDeclaration (UsingAliasDeclaration usingDeclaration, object data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(usingDeclaration.PrevSibling is UsingDeclaration || usingDeclaration.PrevSibling is UsingAliasDeclaration)) |
|
|
|
if (!(usingDeclaration.PrevSibling is UsingDeclaration || usingDeclaration.PrevSibling is UsingAliasDeclaration)) |
|
|
|
EnsureBlankLinesBefore (usingDeclaration, policy.BlankLinesBeforeUsings); |
|
|
|
EnsureBlankLinesBefore (usingDeclaration, policy.BlankLinesBeforeUsings); |
|
|
|
if (!(usingDeclaration.NextSibling is UsingDeclaration || usingDeclaration.NextSibling is UsingAliasDeclaration)) |
|
|
|
if (!(usingDeclaration.NextSibling is UsingDeclaration || usingDeclaration.NextSibling is UsingAliasDeclaration)) |
|
|
|
EnsureBlankLinesAfter (usingDeclaration, policy.BlankLinesAfterUsings); |
|
|
|
EnsureBlankLinesAfter (usingDeclaration, policy.BlankLinesAfterUsings); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -176,24 +238,24 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
BraceStyle braceStyle; |
|
|
|
BraceStyle braceStyle; |
|
|
|
bool indentBody = false; |
|
|
|
bool indentBody = false; |
|
|
|
switch (typeDeclaration.ClassType) { |
|
|
|
switch (typeDeclaration.ClassType) { |
|
|
|
case ClassType.Class: |
|
|
|
case ClassType.Class: |
|
|
|
braceStyle = policy.ClassBraceStyle; |
|
|
|
braceStyle = policy.ClassBraceStyle; |
|
|
|
indentBody = policy.IndentClassBody; |
|
|
|
indentBody = policy.IndentClassBody; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ClassType.Struct: |
|
|
|
case ClassType.Struct: |
|
|
|
braceStyle = policy.StructBraceStyle; |
|
|
|
braceStyle = policy.StructBraceStyle; |
|
|
|
indentBody = policy.IndentStructBody; |
|
|
|
indentBody = policy.IndentStructBody; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ClassType.Interface: |
|
|
|
case ClassType.Interface: |
|
|
|
braceStyle = policy.InterfaceBraceStyle; |
|
|
|
braceStyle = policy.InterfaceBraceStyle; |
|
|
|
indentBody = policy.IndentInterfaceBody; |
|
|
|
indentBody = policy.IndentInterfaceBody; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ClassType.Enum: |
|
|
|
case ClassType.Enum: |
|
|
|
braceStyle = policy.EnumBraceStyle; |
|
|
|
braceStyle = policy.EnumBraceStyle; |
|
|
|
indentBody = policy.IndentEnumBody; |
|
|
|
indentBody = policy.IndentEnumBody; |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new InvalidOperationException ("unsupported class type : " + typeDeclaration.ClassType); |
|
|
|
throw new InvalidOperationException ("unsupported class type : " + typeDeclaration.ClassType); |
|
|
|
} |
|
|
|
} |
|
|
|
EnforceBraceStyle (braceStyle, typeDeclaration.LBraceToken, typeDeclaration.RBraceToken); |
|
|
|
EnforceBraceStyle (braceStyle, typeDeclaration.LBraceToken, typeDeclaration.RBraceToken); |
|
|
|
|
|
|
|
|
|
|
|
@ -302,10 +364,10 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
// if (n == null || n.IsNull)
|
|
|
|
// if (n == null || n.IsNull)
|
|
|
|
// return 0;
|
|
|
|
// return 0;
|
|
|
|
// AstLocation location = n.StartLocation;
|
|
|
|
// AstLocation location = n.StartLocation;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// int offset = data.LocationToOffset (location.Line, location.Column);
|
|
|
|
// int offset = data.LocationToOffset (location.Line, location.Column);
|
|
|
|
// int i = offset - 1;
|
|
|
|
// int i = offset - 1;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// while (i >= 0 && IsSpacing (data.GetCharAt (i))) {
|
|
|
|
// while (i >= 0 && IsSpacing (data.GetCharAt (i))) {
|
|
|
|
// i--;
|
|
|
|
// i--;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
@ -321,7 +383,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
// respect manual line breaks.
|
|
|
|
// respect manual line breaks.
|
|
|
|
if (location.Column <= 1 || GetIndentation (location.Line).Length == location.Column - 1) |
|
|
|
if (location.Column <= 1 || GetIndentation (location.Line).Length == location.Column - 1) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
int offset = document.GetOffset (location); |
|
|
|
int offset = document.GetOffset (location); |
|
|
|
int i = offset - 1; |
|
|
|
int i = offset - 1; |
|
|
|
while (i >= 0 && IsSpacing (document.GetCharAt (i))) { |
|
|
|
while (i >= 0 && IsSpacing (document.GetCharAt (i))) { |
|
|
|
@ -336,39 +398,39 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
FormatAttributedNode (propertyDeclaration); |
|
|
|
FormatAttributedNode (propertyDeclaration); |
|
|
|
bool oneLine = false; |
|
|
|
bool oneLine = false; |
|
|
|
switch (policy.PropertyFormatting) { |
|
|
|
switch (policy.PropertyFormatting) { |
|
|
|
case PropertyFormatting.AllowOneLine: |
|
|
|
case PropertyFormatting.AllowOneLine: |
|
|
|
bool isSimple = IsSimpleAccessor (propertyDeclaration.Getter) && IsSimpleAccessor (propertyDeclaration.Setter); |
|
|
|
bool isSimple = IsSimpleAccessor (propertyDeclaration.Getter) && IsSimpleAccessor (propertyDeclaration.Setter); |
|
|
|
if (!isSimple || propertyDeclaration.LBraceToken.StartLocation.Line != propertyDeclaration.RBraceToken.StartLocation.Line) { |
|
|
|
if (!isSimple || propertyDeclaration.LBraceToken.StartLocation.Line != propertyDeclaration.RBraceToken.StartLocation.Line) { |
|
|
|
EnforceBraceStyle (policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken); |
|
|
|
EnforceBraceStyle (policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ForceSpacesBefore (propertyDeclaration.Getter, true); |
|
|
|
ForceSpacesBefore (propertyDeclaration.Getter, true); |
|
|
|
ForceSpacesBefore (propertyDeclaration.Setter, true); |
|
|
|
ForceSpacesBefore (propertyDeclaration.Setter, true); |
|
|
|
ForceSpacesBefore (propertyDeclaration.RBraceToken, true); |
|
|
|
ForceSpacesBefore (propertyDeclaration.RBraceToken, true); |
|
|
|
oneLine = true; |
|
|
|
oneLine = true; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case PropertyFormatting.ForceNewLine: |
|
|
|
case PropertyFormatting.ForceNewLine: |
|
|
|
EnforceBraceStyle (policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case PropertyFormatting.ForceOneLine: |
|
|
|
|
|
|
|
isSimple = IsSimpleAccessor (propertyDeclaration.Getter) && IsSimpleAccessor (propertyDeclaration.Setter); |
|
|
|
|
|
|
|
if (isSimple) { |
|
|
|
|
|
|
|
int offset = this.document.GetOffset (propertyDeclaration.LBraceToken.StartLocation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int start = SearchWhitespaceStart (offset); |
|
|
|
|
|
|
|
int end = SearchWhitespaceEnd (offset); |
|
|
|
|
|
|
|
AddChange (start, offset - start, " "); |
|
|
|
|
|
|
|
AddChange (offset + 1, end - offset - 2, " "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offset = this.document.GetOffset (propertyDeclaration.RBraceToken.StartLocation); |
|
|
|
|
|
|
|
start = SearchWhitespaceStart (offset); |
|
|
|
|
|
|
|
AddChange (start, offset - start, " "); |
|
|
|
|
|
|
|
oneLine = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
EnforceBraceStyle (policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken); |
|
|
|
EnforceBraceStyle (policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken); |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case PropertyFormatting.ForceOneLine: |
|
|
|
|
|
|
|
isSimple = IsSimpleAccessor (propertyDeclaration.Getter) && IsSimpleAccessor (propertyDeclaration.Setter); |
|
|
|
|
|
|
|
if (isSimple) { |
|
|
|
|
|
|
|
int offset = this.document.GetOffset (propertyDeclaration.LBraceToken.StartLocation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int start = SearchWhitespaceStart (offset); |
|
|
|
|
|
|
|
int end = SearchWhitespaceEnd (offset); |
|
|
|
|
|
|
|
AddChange (start, offset - start, " "); |
|
|
|
|
|
|
|
AddChange (offset + 1, end - offset - 2, " "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offset = this.document.GetOffset (propertyDeclaration.RBraceToken.StartLocation); |
|
|
|
|
|
|
|
start = SearchWhitespaceStart (offset); |
|
|
|
|
|
|
|
AddChange (start, offset - start, " "); |
|
|
|
|
|
|
|
oneLine = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
EnforceBraceStyle (policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (policy.IndentPropertyBody) |
|
|
|
if (policy.IndentPropertyBody) |
|
|
|
IndentLevel++; |
|
|
|
IndentLevel++; |
|
|
|
@ -686,7 +748,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
ForceSpacesBefore (constructorDeclaration.RParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); |
|
|
|
ForceSpacesBefore (constructorDeclaration.RParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); |
|
|
|
} |
|
|
|
} |
|
|
|
FormatCommas (constructorDeclaration, policy.SpaceBeforeConstructorDeclarationParameterComma, policy.SpaceAfterConstructorDeclarationParameterComma); |
|
|
|
FormatCommas (constructorDeclaration, policy.SpaceBeforeConstructorDeclarationParameterComma, policy.SpaceAfterConstructorDeclarationParameterComma); |
|
|
|
|
|
|
|
|
|
|
|
object result = null; |
|
|
|
object result = null; |
|
|
|
if (!constructorDeclaration.Body.IsNull) { |
|
|
|
if (!constructorDeclaration.Body.IsNull) { |
|
|
|
EnforceBraceStyle (policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken, constructorDeclaration.Body.RBraceToken); |
|
|
|
EnforceBraceStyle (policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken, constructorDeclaration.Body.RBraceToken); |
|
|
|
@ -809,53 +871,53 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
int originalLevel = curIndent.Level; |
|
|
|
int originalLevel = curIndent.Level; |
|
|
|
bool isBlock = node is BlockStatement; |
|
|
|
bool isBlock = node is BlockStatement; |
|
|
|
switch (braceForcement) { |
|
|
|
switch (braceForcement) { |
|
|
|
case BraceForcement.DoNotChange: |
|
|
|
case BraceForcement.DoNotChange: |
|
|
|
//nothing
|
|
|
|
//nothing
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceForcement.AddBraces: |
|
|
|
case BraceForcement.AddBraces: |
|
|
|
if (!isBlock) { |
|
|
|
if (!isBlock) { |
|
|
|
AstNode n = node.Parent.GetCSharpNodeBefore (node); |
|
|
|
AstNode n = node.Parent.GetCSharpNodeBefore (node); |
|
|
|
int start = document.GetOffset (n.EndLocation); |
|
|
|
int start = document.GetOffset (n.EndLocation); |
|
|
|
var next = n.GetNextNode (); |
|
|
|
var next = n.GetNextNode (); |
|
|
|
int offset = document.GetOffset (next.StartLocation); |
|
|
|
int offset = document.GetOffset (next.StartLocation); |
|
|
|
string startBrace = ""; |
|
|
|
string startBrace = ""; |
|
|
|
switch (braceStyle) { |
|
|
|
switch (braceStyle) { |
|
|
|
case BraceStyle.EndOfLineWithoutSpace: |
|
|
|
case BraceStyle.EndOfLineWithoutSpace: |
|
|
|
startBrace = "{"; |
|
|
|
startBrace = "{"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.EndOfLine: |
|
|
|
case BraceStyle.EndOfLine: |
|
|
|
startBrace = " {"; |
|
|
|
startBrace = " {"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.NextLine: |
|
|
|
case BraceStyle.NextLine: |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "{"; |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "{"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "{"; |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "{"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (IsLineIsEmptyUpToEol (document.GetOffset (node.StartLocation))) |
|
|
|
|
|
|
|
startBrace += this.EolMarker + GetIndentation (node.StartLocation.Line); |
|
|
|
|
|
|
|
AddChange (start, offset - start, startBrace); |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsLineIsEmptyUpToEol (document.GetOffset (node.StartLocation))) |
|
|
|
break; |
|
|
|
startBrace += this.EolMarker + GetIndentation (node.StartLocation.Line); |
|
|
|
case BraceForcement.RemoveBraces: |
|
|
|
AddChange (start, offset - start, startBrace); |
|
|
|
if (isBlock) { |
|
|
|
} |
|
|
|
BlockStatement block = node as BlockStatement; |
|
|
|
break; |
|
|
|
if (block.Statements.Count () == 1) { |
|
|
|
case BraceForcement.RemoveBraces: |
|
|
|
int offset1 = document.GetOffset (node.StartLocation); |
|
|
|
if (isBlock) { |
|
|
|
int start = SearchWhitespaceStart (offset1); |
|
|
|
BlockStatement block = node as BlockStatement; |
|
|
|
|
|
|
|
if (block.Statements.Count () == 1) { |
|
|
|
int offset2 = document.GetOffset (node.EndLocation); |
|
|
|
int offset1 = document.GetOffset (node.StartLocation); |
|
|
|
int end = SearchWhitespaceStart (offset2 - 1); |
|
|
|
int start = SearchWhitespaceStart (offset1); |
|
|
|
|
|
|
|
|
|
|
|
AddChange (start, offset1 - start + 1, null); |
|
|
|
int offset2 = document.GetOffset (node.EndLocation); |
|
|
|
AddChange (end + 1, offset2 - end, null); |
|
|
|
int end = SearchWhitespaceStart (offset2 - 1); |
|
|
|
node = block.FirstChild; |
|
|
|
|
|
|
|
isBlock = false; |
|
|
|
AddChange (start, offset1 - start + 1, null); |
|
|
|
} |
|
|
|
AddChange (end + 1, offset2 - end, null); |
|
|
|
|
|
|
|
node = block.FirstChild; |
|
|
|
|
|
|
|
isBlock = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (isBlock) { |
|
|
|
if (isBlock) { |
|
|
|
BlockStatement block = node as BlockStatement; |
|
|
|
BlockStatement block = node as BlockStatement; |
|
|
|
@ -873,42 +935,42 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (policy.IndentBlocks && |
|
|
|
if (policy.IndentBlocks && |
|
|
|
!(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || |
|
|
|
!(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || |
|
|
|
policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) |
|
|
|
policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) |
|
|
|
curIndent.Level++; |
|
|
|
curIndent.Level++; |
|
|
|
object result = isBlock ? base.VisitBlockStatement ((BlockStatement)node, null) : node.AcceptVisitor (this, null); |
|
|
|
object result = isBlock ? base.VisitBlockStatement ((BlockStatement)node, null) : node.AcceptVisitor (this, null); |
|
|
|
curIndent.Level = originalLevel; |
|
|
|
curIndent.Level = originalLevel; |
|
|
|
switch (braceForcement) { |
|
|
|
switch (braceForcement) { |
|
|
|
case BraceForcement.DoNotChange: |
|
|
|
case BraceForcement.DoNotChange: |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceForcement.AddBraces: |
|
|
|
case BraceForcement.AddBraces: |
|
|
|
if (!isBlock) { |
|
|
|
if (!isBlock) { |
|
|
|
int offset = document.GetOffset (node.EndLocation); |
|
|
|
int offset = document.GetOffset (node.EndLocation); |
|
|
|
if (!char.IsWhiteSpace (document.GetCharAt (offset))) |
|
|
|
if (!char.IsWhiteSpace (document.GetCharAt (offset))) |
|
|
|
offset++; |
|
|
|
offset++; |
|
|
|
string startBrace = ""; |
|
|
|
string startBrace = ""; |
|
|
|
switch (braceStyle) { |
|
|
|
switch (braceStyle) { |
|
|
|
case BraceStyle.DoNotChange: |
|
|
|
case BraceStyle.DoNotChange: |
|
|
|
startBrace = null; |
|
|
|
startBrace = null; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.EndOfLineWithoutSpace: |
|
|
|
case BraceStyle.EndOfLineWithoutSpace: |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "}"; |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "}"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.EndOfLine: |
|
|
|
case BraceStyle.EndOfLine: |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "}"; |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "}"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.NextLine: |
|
|
|
case BraceStyle.NextLine: |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "}"; |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + "}"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "}"; |
|
|
|
startBrace = this.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "}"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (startBrace != null) |
|
|
|
|
|
|
|
AddChange (offset, 0, startBrace); |
|
|
|
} |
|
|
|
} |
|
|
|
if (startBrace != null) |
|
|
|
break; |
|
|
|
AddChange (offset, 0, startBrace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -928,39 +990,39 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
string startIndent = ""; |
|
|
|
string startIndent = ""; |
|
|
|
string endIndent = ""; |
|
|
|
string endIndent = ""; |
|
|
|
switch (braceStyle) { |
|
|
|
switch (braceStyle) { |
|
|
|
case BraceStyle.DoNotChange: |
|
|
|
case BraceStyle.DoNotChange: |
|
|
|
startIndent = endIndent = null; |
|
|
|
startIndent = endIndent = null; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.EndOfLineWithoutSpace: |
|
|
|
case BraceStyle.EndOfLineWithoutSpace: |
|
|
|
startIndent = ""; |
|
|
|
startIndent = ""; |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString : this.EolMarker + curIndent.IndentString; |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString : this.EolMarker + curIndent.IndentString; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BraceStyle.EndOfLine: |
|
|
|
case BraceStyle.EndOfLine: |
|
|
|
var prevNode = lbrace.GetPrevNode (); |
|
|
|
var prevNode = lbrace.GetPrevNode (); |
|
|
|
if (prevNode is Comment) { |
|
|
|
if (prevNode is Comment) { |
|
|
|
// delete old bracket
|
|
|
|
// delete old bracket
|
|
|
|
AddChange (whitespaceStart, lbraceOffset - whitespaceStart + 1, ""); |
|
|
|
AddChange (whitespaceStart, lbraceOffset - whitespaceStart + 1, ""); |
|
|
|
|
|
|
|
|
|
|
|
while (prevNode is Comment) { |
|
|
|
while (prevNode is Comment) { |
|
|
|
prevNode = prevNode.GetPrevNode (); |
|
|
|
prevNode = prevNode.GetPrevNode (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
whitespaceStart = document.GetOffset (prevNode.EndLocation); |
|
|
|
|
|
|
|
lbraceOffset = whitespaceStart; |
|
|
|
|
|
|
|
startIndent = " {"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
startIndent = " "; |
|
|
|
} |
|
|
|
} |
|
|
|
whitespaceStart = document.GetOffset (prevNode.EndLocation); |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString : this.EolMarker + curIndent.IndentString; |
|
|
|
lbraceOffset = whitespaceStart; |
|
|
|
break; |
|
|
|
startIndent = " {"; |
|
|
|
case BraceStyle.NextLine: |
|
|
|
} else { |
|
|
|
startIndent = this.EolMarker + curIndent.IndentString; |
|
|
|
startIndent = " "; |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString : this.EolMarker + curIndent.IndentString; |
|
|
|
} |
|
|
|
break; |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString : this.EolMarker + curIndent.IndentString; |
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
break; |
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
case BraceStyle.NextLine: |
|
|
|
startIndent = this.EolMarker + curIndent.IndentString + curIndent.SingleIndent; |
|
|
|
startIndent = this.EolMarker + curIndent.IndentString; |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString + curIndent.SingleIndent : this.EolMarker + curIndent.IndentString + curIndent.SingleIndent; |
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString : this.EolMarker + curIndent.IndentString; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
|
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
|
|
|
|
startIndent = this.EolMarker + curIndent.IndentString + curIndent.SingleIndent; |
|
|
|
|
|
|
|
endIndent = IsLineIsEmptyUpToEol (rbraceOffset) ? curIndent.IndentString + curIndent.SingleIndent : this.EolMarker + curIndent.IndentString + curIndent.SingleIndent; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (lbraceOffset > 0 && startIndent != null) |
|
|
|
if (lbraceOffset > 0 && startIndent != null) |
|
|
|
@ -971,35 +1033,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
void AddChange (int offset, int removedChars, string insertedText) |
|
|
|
void AddChange (int offset, int removedChars, string insertedText) |
|
|
|
{ |
|
|
|
{ |
|
|
|
script.Replace(offset, removedChars, insertedText); |
|
|
|
changes.Add(new TextReplaceAction(offset, removedChars, insertedText)); |
|
|
|
// if (changes.Any (c => c.Offset == offset && c.RemovedChars == removedChars
|
|
|
|
|
|
|
|
// && c.InsertedText == insertedText))
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// string currentText = document.GetText (offset, removedChars);
|
|
|
|
|
|
|
|
// if (currentText == insertedText)
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// if (currentText.Any (c => !(char.IsWhiteSpace (c) || c == '\r' || c == '\t' || c == '{' || c == '}')))
|
|
|
|
|
|
|
|
// throw new InvalidOperationException ("Tried to remove non ws chars: '" + currentText + "'");
|
|
|
|
|
|
|
|
// foreach (var change in changes) {
|
|
|
|
|
|
|
|
// if (change.Offset == offset) {
|
|
|
|
|
|
|
|
// if (removedChars > 0 && insertedText == change.InsertedText) {
|
|
|
|
|
|
|
|
// change.RemovedChars = removedChars;
|
|
|
|
|
|
|
|
//// change.InsertedText = insertedText;
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!string.IsNullOrEmpty (change.InsertedText)) {
|
|
|
|
|
|
|
|
// change.InsertedText += insertedText;
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// change.InsertedText = insertedText;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// change.RemovedChars = System.Math.Max (removedChars, change.RemovedChars);
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// //Console.WriteLine ("offset={0}, removedChars={1}, insertedText={2}", offset, removedChars, insertedText == null ? "<null>" : insertedText.Replace ("\n", "\\n").Replace ("\r", "\\r").Replace ("\t", "\\t").Replace (" ", "."));
|
|
|
|
|
|
|
|
// //Console.WriteLine (Environment.StackTrace);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// changes.Add (factory.CreateTextReplaceAction (offset, removedChars, insertedText));
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool IsLineIsEmptyUpToEol (TextLocation startLocation) |
|
|
|
public bool IsLineIsEmptyUpToEol (TextLocation startLocation) |
|
|
|
@ -1169,7 +1203,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
if (policy.IndentCaseBody) |
|
|
|
if (policy.IndentCaseBody) |
|
|
|
curIndent.Level--; |
|
|
|
curIndent.Level--; |
|
|
|
|
|
|
|
|
|
|
|
if (policy.IndentSwitchBody) |
|
|
|
if (policy.IndentSwitchBody) |
|
|
|
curIndent.Level--; |
|
|
|
curIndent.Level--; |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -1322,41 +1356,41 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool forceSpaces = false; |
|
|
|
bool forceSpaces = false; |
|
|
|
switch (binaryOperatorExpression.Operator) { |
|
|
|
switch (binaryOperatorExpression.Operator) { |
|
|
|
case BinaryOperatorType.Equality: |
|
|
|
case BinaryOperatorType.Equality: |
|
|
|
case BinaryOperatorType.InEquality: |
|
|
|
case BinaryOperatorType.InEquality: |
|
|
|
forceSpaces = policy.SpaceAroundEqualityOperator; |
|
|
|
forceSpaces = policy.SpaceAroundEqualityOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.GreaterThan: |
|
|
|
case BinaryOperatorType.GreaterThan: |
|
|
|
case BinaryOperatorType.GreaterThanOrEqual: |
|
|
|
case BinaryOperatorType.GreaterThanOrEqual: |
|
|
|
case BinaryOperatorType.LessThan: |
|
|
|
case BinaryOperatorType.LessThan: |
|
|
|
case BinaryOperatorType.LessThanOrEqual: |
|
|
|
case BinaryOperatorType.LessThanOrEqual: |
|
|
|
forceSpaces = policy.SpaceAroundRelationalOperator; |
|
|
|
forceSpaces = policy.SpaceAroundRelationalOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.ConditionalAnd: |
|
|
|
case BinaryOperatorType.ConditionalAnd: |
|
|
|
case BinaryOperatorType.ConditionalOr: |
|
|
|
case BinaryOperatorType.ConditionalOr: |
|
|
|
forceSpaces = policy.SpaceAroundLogicalOperator; |
|
|
|
forceSpaces = policy.SpaceAroundLogicalOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.BitwiseAnd: |
|
|
|
case BinaryOperatorType.BitwiseAnd: |
|
|
|
case BinaryOperatorType.BitwiseOr: |
|
|
|
case BinaryOperatorType.BitwiseOr: |
|
|
|
case BinaryOperatorType.ExclusiveOr: |
|
|
|
case BinaryOperatorType.ExclusiveOr: |
|
|
|
forceSpaces = policy.SpaceAroundBitwiseOperator; |
|
|
|
forceSpaces = policy.SpaceAroundBitwiseOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.Add: |
|
|
|
case BinaryOperatorType.Add: |
|
|
|
case BinaryOperatorType.Subtract: |
|
|
|
case BinaryOperatorType.Subtract: |
|
|
|
forceSpaces = policy.SpaceAroundAdditiveOperator; |
|
|
|
forceSpaces = policy.SpaceAroundAdditiveOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.Multiply: |
|
|
|
case BinaryOperatorType.Multiply: |
|
|
|
case BinaryOperatorType.Divide: |
|
|
|
case BinaryOperatorType.Divide: |
|
|
|
case BinaryOperatorType.Modulus: |
|
|
|
case BinaryOperatorType.Modulus: |
|
|
|
forceSpaces = policy.SpaceAroundMultiplicativeOperator; |
|
|
|
forceSpaces = policy.SpaceAroundMultiplicativeOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.ShiftLeft: |
|
|
|
case BinaryOperatorType.ShiftLeft: |
|
|
|
case BinaryOperatorType.ShiftRight: |
|
|
|
case BinaryOperatorType.ShiftRight: |
|
|
|
forceSpaces = policy.SpaceAroundShiftOperator; |
|
|
|
forceSpaces = policy.SpaceAroundShiftOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BinaryOperatorType.NullCoalescing: |
|
|
|
case BinaryOperatorType.NullCoalescing: |
|
|
|
forceSpaces = policy.SpaceAroundNullCoalescingOperator; |
|
|
|
forceSpaces = policy.SpaceAroundNullCoalescingOperator; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
ForceSpacesAround (binaryOperatorExpression.OperatorToken, forceSpaces); |
|
|
|
ForceSpacesAround (binaryOperatorExpression.OperatorToken, forceSpaces); |
|
|
|
|
|
|
|
|
|
|
|
@ -1554,7 +1588,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void FixSemicolon (CSharpTokenNode semicolon) |
|
|
|
public void FixSemicolon (CSharpTokenNode semicolon) |
|
|
|
@ -1569,7 +1603,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
if (offset < endOffset) { |
|
|
|
if (offset < endOffset) { |
|
|
|
AddChange (offset, endOffset - offset, null); |
|
|
|
AddChange (offset, endOffset - offset, null); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PlaceOnNewLine (bool newLine, AstNode keywordNode) |
|
|
|
void PlaceOnNewLine (bool newLine, AstNode keywordNode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -1611,7 +1645,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
Console.WriteLine (Environment.StackTrace); |
|
|
|
Console.WriteLine (Environment.StackTrace); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string lineIndent = GetIndentation (location.Line); |
|
|
|
string lineIndent = GetIndentation (location.Line); |
|
|
|
string indentString = this.curIndent.IndentString; |
|
|
|
string indentString = this.curIndent.IndentString; |
|
|
|
if (indentString != lineIndent && location.Column - 1 + relOffset == lineIndent.Length) { |
|
|
|
if (indentString != lineIndent && location.Column - 1 + relOffset == lineIndent.Length) { |
|
|
|
@ -1625,10 +1659,10 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
string indentString = this.curIndent.IndentString; |
|
|
|
string indentString = this.curIndent.IndentString; |
|
|
|
if (location.Column - 1 == lineIndent.Length) { |
|
|
|
if (location.Column - 1 == lineIndent.Length) { |
|
|
|
AddChange (document.GetOffset (location.Line, 1), lineIndent.Length, indentString); |
|
|
|
AddChange (document.GetOffset (location.Line, 1), lineIndent.Length, indentString); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
int offset = document.GetOffset (location); |
|
|
|
int offset = document.GetOffset (location); |
|
|
|
int start = SearchWhitespaceLineStart (offset); |
|
|
|
int start = SearchWhitespaceLineStart (offset); |
|
|
|
if (start > 0) { |
|
|
|
if (start > 0) { |
|
|
|
char ch = document.GetCharAt (start - 1); |
|
|
|
char ch = document.GetCharAt (start - 1); |
|
|
|
if (ch == '\n') { |
|
|
|
if (ch == '\n') { |
|
|
|
start--; |
|
|
|
start--; |
|
|
|
|