Skip to content

Commit d799a88

Browse files
author
Kapil Borle
committed
Add CodeFormattingSettings type
1 parent c4e8866 commit d799a88

File tree

1 file changed

+92
-6
lines changed

1 file changed

+92
-6
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
using System.IO;
77
using Microsoft.PowerShell.EditorServices.Utility;
8+
using System;
9+
using System.Reflection;
10+
using System.Collections;
811

912
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
1013
{
@@ -14,6 +17,8 @@ public class LanguageServerSettings
1417

1518
public ScriptAnalysisSettings ScriptAnalysis { get; set; }
1619

20+
public CodeFormattingSettings CodeFormatting { get; set; }
21+
1722
public LanguageServerSettings()
1823
{
1924
this.ScriptAnalysis = new ScriptAnalysisSettings();
@@ -31,6 +36,7 @@ public void Update(
3136
settings.ScriptAnalysis,
3237
workspaceRootPath,
3338
logger);
39+
this.CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
3440
}
3541
}
3642
}
@@ -86,12 +92,92 @@ public void Update(
8692
}
8793
}
8894

89-
public class LanguageServerSettingsWrapper
95+
public class CodeFormattingSettings
9096
{
91-
// NOTE: This property is capitalized as 'Powershell' because the
92-
// mode name sent from the client is written as 'powershell' and
93-
// JSON.net is using camelCasing.
97+
/// <summary>
98+
/// Default constructor.
99+
/// </summary>
100+
public CodeFormattingSettings()
101+
{
102+
103+
}
104+
105+
/// <summary>
106+
/// Copy constructor.
107+
/// </summary>
108+
/// <param name="codeFormattingSettings">An instance of type CodeFormattingSettings.</param>
109+
public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings)
110+
{
111+
if (codeFormattingSettings == null)
112+
{
113+
throw new ArgumentNullException(nameof(codeFormattingSettings));
114+
}
94115

95-
public LanguageServerSettings Powershell { get; set; }
116+
foreach (var prop in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
117+
{
118+
prop.SetValue(this, prop.GetValue(codeFormattingSettings));
119+
}
120+
}
121+
122+
public bool OpenBraceOnSameLine { get; set; }
123+
public bool NewLineAfterOpenBrace { get; set; }
124+
public bool NewLineAfterCloseBrace { get; set; }
125+
public bool WhitespaceBeforeOpenBrace { get; set; }
126+
public bool WhitespaceBeforeOpenParen { get; set; }
127+
public bool WhitespaceAroundOperator { get; set; }
128+
public bool WhitespaceAfterSeparator { get; set; }
129+
public bool IgnoreOneLineBlock { get; set; }
130+
public bool AlignPropertyValuePairs { get; set; }
131+
132+
public Hashtable GetPSSASettingsHashTable(int tabSize, bool insertSpaces)
133+
{
134+
return new Hashtable
135+
{
136+
{"IncludeRules", new string[] {
137+
"PSPlaceCloseBrace",
138+
"PSPlaceOpenBrace",
139+
"PSUseConsistentWhitespace",
140+
"PSUseConsistentIndentation",
141+
"PSAlignAssignmentStatement"
142+
}},
143+
{"Rules", new Hashtable {
144+
{"PSPlaceOpenBrace", new Hashtable {
145+
{"Enable", true},
146+
{"OnSameLine", OpenBraceOnSameLine},
147+
{"NewLineAfter", NewLineAfterOpenBrace},
148+
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
149+
}},
150+
{"PSPlaceCloseBrace", new Hashtable {
151+
{"Enable", true},
152+
{"NewLineAfter", NewLineAfterCloseBrace},
153+
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
154+
}},
155+
{"PSUseConsistentIndentation", new Hashtable {
156+
{"Enable", true},
157+
{"IndentationSize", tabSize}
158+
}},
159+
{"PSUseConsistentWhitespace", new Hashtable {
160+
{"Enable", true},
161+
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
162+
{"CheckOpenParen", WhitespaceBeforeOpenParen},
163+
{"CheckOperator", WhitespaceAroundOperator},
164+
{"CheckSeparator", WhitespaceAfterSeparator}
165+
}},
166+
{"PSAlignAssignmentStatement", new Hashtable {
167+
{"Enable", true},
168+
{"CheckHashtable", AlignPropertyValuePairs}
169+
}},
170+
}}
171+
};
172+
}
173+
}
174+
175+
public class LanguageServerSettingsWrapper
176+
{
177+
// NOTE: This property is capitalized as 'Powershell' because the
178+
// mode name sent from the client is written as 'powershell' and
179+
// JSON.net is using camelCasing.
180+
181+
public LanguageServerSettings Powershell { get; set; }
182+
}
96183
}
97-
}

0 commit comments

Comments
 (0)