Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6809 from mono/master-vsts753551
Browse files Browse the repository at this point in the history
Fixes VSTS Bug 753551: Using statement indenting
  • Loading branch information
mkrueger committed Jan 11, 2019
2 parents cc9a5ac + 65d6bf3 commit 1727c46
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
using Microsoft.CodeAnalysis.Shared.Extensions;
using System.Threading;
using MonoDevelop.Ide;
using Microsoft.CodeAnalysis.LanguageServices;
using MonoDevelop.Core.Text;
using Microsoft.CodeAnalysis.CSharp.Extensions;

namespace MonoDevelop.CSharp.Formatting
{
Expand Down Expand Up @@ -69,7 +72,22 @@ public override string GetIndentationString (int lineNumber)
if (indentation.HasValue && indentation.Value > 0) {
return CalculateIndentationString (indentation.Value);
}
return editor.GetLineIndent (lineNumber) + CalculateIndentationString (editor.Options.IndentationSize);

var line = editor.GetLine (lineNumber);
if (line == null)
return editor.GetLineIndent (lineNumber);
try {
if (line.Contains (editor.CaretOffset)) {
var syntaxRoot = doc.GetSyntaxRootSynchronously (default);
var token = syntaxRoot.FindTokenOnLeftOfPosition (editor.CaretOffset);
if (token.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.CommaToken))
return line.GetIndentation (editor) + CalculateIndentationString (editor.Options.IndentationSize);
}
} catch (Exception e) {
LoggingService.LogError ("Error while calculating the indentation string.", e);
}

return line.GetIndentation (editor);
}

string CalculateIndentationString (int spaceCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,5 +624,22 @@ public class MyClass
Assert.AreEqual ("\t\t\t", indent);
}
}

/// <summary>
/// Bug 753551: Using statement indenting
/// </summary>
[Test]
public async Task TestVSTS753551 ()
{
using (var data = await Create (@"
// Test
using System;
$
", createWithProject: true)) {
var tracker = new CSharpIndentationTracker (data.Document.Editor, data.Document);
var indent = tracker.GetIndentationString (data.Document.Editor.CaretLine);
Assert.AreEqual ("", indent);
}
}
}
}

0 comments on commit 1727c46

Please sign in to comment.