Skip to content

Commit 08c0f88

Browse files
drivehappyKevinRansom
authored andcommitted
Fixed the insertion of an open declaration that assumed the document had Environment.NewLine line breaks. This would cause a unix-line ending source file to incorrectly be populated with CRLF when working under Windows. (#4487)
1 parent 3846384 commit 08c0f88

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,15 @@ module internal OpenDeclarationHelper =
171171
let mutable minPos = None
172172

173173
let insert line lineStr (sourceText: SourceText) : SourceText =
174-
let pos = sourceText.Lines.[line].Start
174+
let ln = sourceText.Lines.[line]
175+
let pos = ln.Start
175176
minPos <- match minPos with None -> Some pos | Some oldPos -> Some (min oldPos pos)
176-
sourceText.WithChanges(TextChange(TextSpan(pos, 0), lineStr + Environment.NewLine))
177+
178+
// find the line break characters on the previous line to use, Environment.NewLine should not be used
179+
// as it makes assumptions on the line endings in the source.
180+
let lineBreak = ln.Text.ToString(TextSpan(ln.End, ln.EndIncludingLineBreak - ln.End))
181+
182+
sourceText.WithChanges(TextChange(TextSpan(pos, 0), lineStr + lineBreak))
177183

178184
let getLineStr line = sourceText.Lines.[line].ToString().Trim()
179185
let pos = ParsedInput.adjustInsertionPoint getLineStr ctx

0 commit comments

Comments
 (0)