Skip to content

Commit

Permalink
Merge pull request #24 from edgardmessias/ident
Browse files Browse the repository at this point in the history
Respect ident configuration when formatting
  • Loading branch information
foxundermoon committed Jan 28, 2019
2 parents 66518e9 + be39ed2 commit c8efea4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/shFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class Formatter {
static formatCommand = "shfmt";

public formatDocument(
document: vscode.TextDocument
document: vscode.TextDocument,
options?: vscode.FormattingOptions
): Thenable<vscode.TextEdit[]> {
const start = new vscode.Position(0, 0);
const end = new vscode.Position(
Expand All @@ -40,12 +41,13 @@ export class Formatter {
);
const range = new vscode.Range(start, end);
const content = document.getText(range);
return this.formatDocumentWithContent(content, document.fileName);
return this.formatDocumentWithContent(content, document.fileName, options);
}

public formatDocumentWithContent(
content: string,
filename: string
filename: string,
options?: vscode.FormattingOptions
): Thenable<vscode.TextEdit[]> {
return new Promise((resolve, reject) => {
try {
Expand Down Expand Up @@ -81,6 +83,9 @@ export class Formatter {
}
}
}
if (options && options.insertSpaces) {
formatFlags.push("-i", options.tabSize);
}
let fmtSpawn = cp.spawn(Formatter.formatCommand, formatFlags);
let output: Buffer[] = [];
let errorOutput: Buffer[] = [];
Expand Down Expand Up @@ -166,7 +171,7 @@ export class ShellDocumentFormattingEditProvider
// if (!onSave) {
// console.log(onSave);
// }
return this.formatter.formatDocument(document);
return this.formatter.formatDocument(document, options);
}
}

Expand Down

0 comments on commit c8efea4

Please sign in to comment.