Skip to content

Commit 62c4b75

Browse files
author
Kapil Borle
committed
Format space around braces, parens and binary operators
1 parent 05b75cb commit 62c4b75

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/features/DocumentFormatter.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
139139
private readonly ruleOrder: string[] = [
140140
"PSPlaceCloseBrace",
141141
"PSPlaceOpenBrace",
142+
"PSUseWhitespace",
142143
"PSUseConsistentIndentation"];
143144

144145
// Allows edits to be undone and redone is a single step.
@@ -232,12 +233,13 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
232233
});
233234

234235
// We cannot handle multiple edits at the same point hence we
235-
// filter the markers so that there is only one edit per line
236-
// This ideally should not happen but it is good to have some additional safeguard
236+
// filter the markers so that there is only one edit per region
237237
if (edits.length > 0) {
238238
uniqueEdits.push(edits[0]);
239239
for (let edit of edits.slice(1)) {
240-
if (editComparer(uniqueEdits[uniqueEdits.length - 1], edit) !== 0) {
240+
let lastEdit: ScriptRegion = uniqueEdits[uniqueEdits.length - 1];
241+
if (lastEdit.startLineNumber !== edit.startLineNumber
242+
|| (edit.startColumnNumber + edit.text.length) < lastEdit.startColumnNumber) {
241243
uniqueEdits.push(edit);
242244
}
243245
}
@@ -332,6 +334,11 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
332334
ruleSettings["IndentationSize"] = vscode.workspace.getConfiguration("editor").get<number>("tabSize");
333335
break;
334336

337+
case "PSUseWhitespace":
338+
ruleSettings["CheckOpenBrace"] = true;
339+
ruleSettings["CheckOpenParen"] = true;
340+
ruleSettings["CheckOperator"] = true;
341+
335342
default:
336343
break;
337344
}

0 commit comments

Comments
 (0)