Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect ident configuration when formatting #24

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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