Skip to content

Commit c1ca84b

Browse files
author
Kapil Borle
committed
Add ability to set indentation size
1 parent bd8c9d7 commit c1ca84b

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@
275275
"type":"boolean",
276276
"default": true,
277277
"description": "Places open brace on the same line as its associated statement."
278+
},
279+
"powershell.codeformatting.indentationSize":{
280+
"type":"number",
281+
"default": 4,
282+
"description": "The indentation size in number of Space characters."
278283
}
279284
}
280285
}

src/features/DocumentFormatter.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
8686
// can be undone and redone in a single step
8787

8888
// sort in decending order of the edits
89-
result.markers.sort(function(a: ScriptFileMarker, b: ScriptFileMarker): number {
89+
result.markers.sort(function (a: ScriptFileMarker, b: ScriptFileMarker): number {
9090
let leftOperand: number = a.correction.edits[0].startLineNumber,
9191
rightOperand: number = b.correction.edits[0].startLineNumber;
9292
if (leftOperand < rightOperand) {
@@ -136,12 +136,29 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
136136

137137
getSettings(rule: string): string {
138138
let settings: Settings.ISettings = Settings.load(Utils.PowerShellLanguageId);
139+
let ruleProperty: string;
140+
switch (rule) {
141+
case "PSPlaceOpenBrace":
142+
ruleProperty = `${rule} = @{
143+
OnSameLine = \$${settings.codeformatting.openBraceOnSameLine}
144+
}`;
145+
break;
146+
147+
case "PSUseConsistentIndentation":
148+
ruleProperty = `${rule} = @{
149+
IndentationSize = ${settings.codeformatting.indentationSize}
150+
}`;
151+
break;
152+
153+
default:
154+
ruleProperty = "";
155+
break;
156+
}
157+
139158
return `@{
140159
IncludeRules = @('${rule}')
141160
Rules = @{
142-
PSPlaceOpenBrace = @{
143-
OnSameLine = \$${settings.codeformatting.openBraceOnSameLine}
144-
}
161+
${ruleProperty}
145162
}
146163
}`;
147164
}

src/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import vscode = require('vscode');
88

99
export interface ICodeFormattingSettings {
1010
openBraceOnSameLine: boolean;
11+
indentationSize: number;
1112
}
1213

1314
export interface IScriptAnalysisSettings {
@@ -46,7 +47,8 @@ export function load(myPluginId: string): ISettings {
4647
};
4748

4849
let defaultCodeFormattingSettings: ICodeFormattingSettings = {
49-
openBraceOnSameLine: true
50+
openBraceOnSameLine: true,
51+
indentationSize: 4
5052
};
5153

5254
return {

0 commit comments

Comments
 (0)