Bug 6678 - Incorrect formatting of calls with multiline string as last parameter
Summary: Incorrect formatting of calls with multiline string as last parameter
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: Trunk
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2012-08-24 07:49 UTC by Simon Lindgren
Modified: 2012-08-28 02:26 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Simon Lindgren 2012-08-24 07:49:39 UTC
This piece of code:

using System;

class Something
{
	public void DoStuff ()
	{
		Console.WriteLine (@"Stuff done
More stuff done");
	}
}

Is changed into

using System;

class Something
{
	public void DoStuff ()
	{
		Console.WriteLine (@"Stuff done
More stuff done"
		);
	}
}

By the formatter, which I consider incorrect. I did some digging, and I reached the following conclusion:
In AstFormattingVisitor around lines 1847-1854:

...
} else {
	bool sameLine = rParToken.GetPrevNode().EndLocation.Line == rParToken.StartLocation.Line;
	if (sameLine) {
		ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
	} else {
		FixStatementIndentation(rParToken.StartLocation);
	}
}
...

In the example above, sameLine will be false, since PrimitiveExpression.EndLocation returns a location on the same line as StartLocation:

...
TextLocation startLocation;
public override TextLocation StartLocation {
	get {
		return startLocation;
	}
}

string literalValue;
public override TextLocation EndLocation {
	get {
		return new TextLocation (StartLocation.Line, StartLocation.Column + literalValue.Length);
}
...

So, next I looked at the parser. The corresponding type in the mcs ast, Constant, only contains the start location and so do the relevant subclasses of Constant AFAICT.

Ok, I'll end the spew now, this looks like a mcs problem _and_ an NRefactory problem :)
Comment 1 Mike Krüger 2012-08-28 02:26:53 UTC
fixed.