-
Notifications
You must be signed in to change notification settings - Fork 222
Use the new line character to check if the CodeWriter buffer ends in a line feed. #616
Conversation
…a line feed. Fixes #577
@@ -114,7 +114,7 @@ public void Dispose() | |||
{ | |||
// Need to add an additional line at the end IF there wasn't one already written. | |||
// This is needed to work with the C# editor's handling of #line ... | |||
var endsWithNewline = _writer.GenerateCode().EndsWith("\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be buggy on CoreCLR \ Linux. https://github.com/dotnet/corefx/issues/4587
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect you can work around issue (and have better performance) by explicitly passing StringComparison.Ordinal to EndsWith.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for the Builder
to be empty at this point? If that's even a remote possibility, ...Builder.EndsWith("\n", StringComparison.Ordinal)
sounds better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringBuilder
doesn't have an EndsWith method. I think @ellismg was referring to the string we were producing. I added a bounds check for the char check.
|
@@ -18,6 +19,8 @@ public class CodeWriter : IDisposable | |||
private int _currentLineIndex; | |||
private int _currentLineCharacterIndex; | |||
|
|||
public StringBuilder Builder => _writer.GetStringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Could
CSharpLineMappingWriter
use the existingLastWrite
property instead? (Glad you've moved away from the weird writer ->string
implicit conversion.) - If not, does the new property need to be in
CodeWriter
?CSharpLineMappingWriter
knows it has aCSharpCodeWriter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There's a bunch of places we do
GenerateCode().Length
. It would be a lot nicer to simply doBuffer.Length
instead. I'll send that as a follow up. - Don't see why it's better to move it a derived type.
⌚ |
🆙 📅 |
|
1 similar comment
|
Fixes #577