|
8 | 8 | using System;
|
9 | 9 | using System.Reflection;
|
10 | 10 | using System.Collections;
|
| 11 | +using System.Linq; |
| 12 | +using System.Collections.Generic; |
11 | 13 |
|
12 | 14 | namespace Microsoft.PowerShell.EditorServices.Protocol.Server
|
13 | 15 | {
|
@@ -93,18 +95,33 @@ public void Update(
|
93 | 95 | }
|
94 | 96 | }
|
95 | 97 |
|
| 98 | + /// <summary> |
| 99 | + /// code formatting presets |
| 100 | + /// </summary> |
96 | 101 | public enum CodeFormattingPreset
|
97 | 102 | {
|
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Use the formatting settings as-is. |
| 106 | + /// </summary> |
98 | 107 | Custom,
|
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Configure the formatting settings to resemble the one true brace style variant of KR indent/brace style. |
| 111 | + /// </summary> |
99 | 112 | OTBS,
|
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Configure the formatting settings to resemble the Allman indent/brace style. |
| 116 | + /// </summary> |
100 | 117 | Allman
|
101 | 118 | }
|
102 | 119 |
|
103 | 120 | public class CodeFormattingSettings
|
104 | 121 | {
|
105 | 122 | /// <summary>
|
106 | 123 | /// Default constructor.
|
107 |
| - /// </summary> |
| 124 | + /// </summary>> |
108 | 125 | public CodeFormattingSettings()
|
109 | 126 | {
|
110 | 127 |
|
@@ -138,7 +155,43 @@ public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings)
|
138 | 155 | public bool IgnoreOneLineBlock { get; set; }
|
139 | 156 | public bool AlignPropertyValuePairs { get; set; }
|
140 | 157 |
|
141 |
| - public Hashtable GetPSSASettingsHashTable(int tabSize, bool insertSpaces) |
| 158 | + |
| 159 | + /// <summary> |
| 160 | + /// Get the settings hashtable that will be consumed by PSScriptAnalyzer. |
| 161 | + /// </summary> |
| 162 | + /// <param name="tabSize">The tab size in the number spaces.</param> |
| 163 | + /// <param name="insertSpaces">If true, insert spaces otherwise insert tabs for indentation.</param> |
| 164 | + /// <returns></returns> |
| 165 | + public Hashtable GetPSSASettingsHashtable( |
| 166 | + int tabSize, |
| 167 | + bool insertSpaces) |
| 168 | + { |
| 169 | + var settings = GetCustomPSSASettingsHashtable(tabSize, insertSpaces); |
| 170 | + var ruleSettings = (Hashtable)(settings["Rules"]); |
| 171 | + var closeBraceSettings = (Hashtable)ruleSettings["PSPlaceCloseBrace"]; |
| 172 | + var openBraceSettings = (Hashtable)ruleSettings["PSPlaceOpenBrace"]; |
| 173 | + switch(Preset) |
| 174 | + { |
| 175 | + case CodeFormattingPreset.Allman: |
| 176 | + openBraceSettings["OnSameLine"] = false; |
| 177 | + openBraceSettings["NewLineAfter"] = true; |
| 178 | + closeBraceSettings["NewLineAfter"] = true; |
| 179 | + break; |
| 180 | + |
| 181 | + case CodeFormattingPreset.OTBS: |
| 182 | + openBraceSettings["OnSameLine"] = true; |
| 183 | + openBraceSettings["NewLineAfter"] = true; |
| 184 | + closeBraceSettings["NewLineAfter"] = false; |
| 185 | + break; |
| 186 | + |
| 187 | + default: |
| 188 | + break; |
| 189 | + } |
| 190 | + |
| 191 | + return settings; |
| 192 | + } |
| 193 | + |
| 194 | + private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces) |
142 | 195 | {
|
143 | 196 | return new Hashtable
|
144 | 197 | {
|
|
0 commit comments