5
5
6
6
using System . IO ;
7
7
using Microsoft . PowerShell . EditorServices . Utility ;
8
+ using System ;
9
+ using System . Reflection ;
10
+ using System . Collections ;
8
11
9
12
namespace Microsoft . PowerShell . EditorServices . Protocol . Server
10
13
{
@@ -14,6 +17,8 @@ public class LanguageServerSettings
14
17
15
18
public ScriptAnalysisSettings ScriptAnalysis { get ; set ; }
16
19
20
+ public CodeFormattingSettings CodeFormatting { get ; set ; }
21
+
17
22
public LanguageServerSettings ( )
18
23
{
19
24
this . ScriptAnalysis = new ScriptAnalysisSettings ( ) ;
@@ -31,6 +36,7 @@ public void Update(
31
36
settings . ScriptAnalysis ,
32
37
workspaceRootPath ,
33
38
logger ) ;
39
+ this . CodeFormatting = new CodeFormattingSettings ( settings . CodeFormatting ) ;
34
40
}
35
41
}
36
42
}
@@ -86,12 +92,92 @@ public void Update(
86
92
}
87
93
}
88
94
89
- public class LanguageServerSettingsWrapper
95
+ public class CodeFormattingSettings
90
96
{
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
+ }
94
115
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
+ }
96
183
}
97
- }
0 commit comments