Skip to content

Commit

Permalink
Fixed a bug where inconsistent linebreaks could break the formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
trixnz committed Jul 18, 2017
1 parent 612175a commit bde36f6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions server/src/services/formatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ function getEditsFromFormattedText(documentUri: string, originalText: string, fo
}

export function buildDocumentFormatEdits(documentUri: string, document: TextDocument): TextEdit[] {
const documentText = document.getText();
let documentText = document.getText();

const formatOptions: UserOptions = {
writeMode: WriteMode.Diff
};
const formattedText = formatText(documentText, formatOptions);
let formattedText = formatText(documentText, formatOptions);

// Normalize the line endings so jsdiff has a chance at providing minimal edits, otherwise the diffing result will
// be one giant edit, which isn't very friendly.
if (process.platform === 'win32') {
documentText = documentText.split('\r\n').join('\n');
formattedText = formattedText.split('\r\n').join('\n');
}

return getEditsFromFormattedText(documentUri, documentText, formattedText);
}
Expand Down

0 comments on commit bde36f6

Please sign in to comment.