Permalink
Browse files

Fix formatting on save

  • Loading branch information...
1 parent 89d0ecc commit 7a5a2e63d3903d78d178a6d22463d3ec7cab868d Hooky committed Nov 29, 2016
Showing with 22 additions and 3 deletions.
  1. +6 −0 CHANGELOG.md
  2. +15 −2 extension.js
  3. +1 −1 package.json
View
@@ -1,3 +1,9 @@
+### 0.6.2: 28 Nov 2016
+* Force eol to document setting in editor.
+
+### 0.6.1: 28 Nov 2016
+* Put back redundant call on save until the textEdit fix is in VS Code (hopefully 1.8.0)
+
### 0.6.0: 26 Nov 2016
* Remove ***onSaveIgnore*** setting as it won't work with the VS Code formatOnSave setting
* Remove redundant format call on save
View
@@ -21,6 +21,18 @@ const getBeautifyType = () => {
}, () => 0));
};
+// This is a fudge work around that shouldn't be required
+const fixEol = (doc, config) => {
+ // getText will always give us the
+ // line endings as set in the editor
+ const txt = doc.getText();
+ const lfPos = txt.indexOf('\n', 1);
+ // if there isn't one, the safest setting is LF
+ if (lfPos < 0 || txt[lfPos - 1] !== '\r') config.eol = '\n';
+ else config.eol = '\r\n';
+ return config;
+};
+
const beautifyDoc = (doc, range, type, formattingOptions) => {
if (!doc) {
vscode.window.showInformationMessage(
@@ -29,8 +41,8 @@ const beautifyDoc = (doc, range, type, formattingOptions) => {
}
return Promise.resolve(type ? type : getBeautifyType())
.then(type => options(doc, type, formattingOptions)
- .then(config => beautify[type](doc.getText(range), config)))
- .then(txt => txt);
+ .then(config => fixEol(doc, config))
+ .then(config => beautify[type](doc.getText(range), config)));
};
const documentEdit = (range, newText) => [vscode.TextEdit.replace(range, newText)];
@@ -169,6 +181,7 @@ const formatActiveDocument = ranged => {
return beautifyDoc(active.document, range, type)
.then(newText => active.edit(editor => editor.replace(range, newText)), dumpError);
};
+
//register on activation
exports.activate = (context) => {
let sub = context.subscriptions;
View
@@ -2,7 +2,7 @@
"name": "beautify",
"displayName": "beautify",
"description": "Beautify code in place for VS Code",
- "version": "0.6.0",
+ "version": "0.6.2",
"publisher": "HookyQR",
"engines": { "vscode": "^1.6.0" },
"categories": ["Other", "Languages", "Formatters"],

0 comments on commit 7a5a2e6

Please sign in to comment.