11
11
using Microsoft . PowerShell . EditorServices . Logging ;
12
12
using Microsoft . PowerShell . EditorServices . Services ;
13
13
using Microsoft . PowerShell . EditorServices . Services . Configuration ;
14
+ using Microsoft . PowerShell . EditorServices . Services . Extension ;
15
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
14
16
using Newtonsoft . Json . Linq ;
15
17
using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
16
18
using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
17
19
using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
18
20
using OmniSharp . Extensions . LanguageServer . Protocol . Workspace ;
19
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
20
- using Microsoft . PowerShell . EditorServices . Services . Extension ;
21
-
22
21
23
22
namespace Microsoft . PowerShell . EditorServices . Handlers
24
23
{
@@ -31,7 +30,7 @@ internal class PsesConfigurationHandler : DidChangeConfigurationHandlerBase
31
30
private readonly PsesInternalHost _psesHost ;
32
31
private readonly ILanguageServerFacade _languageServer ;
33
32
private bool _profilesLoaded ;
34
- private bool _extensionServiceInitialized ;
33
+ private readonly bool _extensionServiceInitialized ;
35
34
private bool _cwdSet ;
36
35
37
36
public PsesConfigurationHandler (
@@ -56,10 +55,10 @@ public PsesConfigurationHandler(
56
55
public override async Task < Unit > Handle ( DidChangeConfigurationParams request , CancellationToken cancellationToken )
57
56
{
58
57
LanguageServerSettingsWrapper incomingSettings = request . Settings . ToObject < LanguageServerSettingsWrapper > ( ) ;
59
- this . _logger . LogTrace ( "Handling DidChangeConfiguration" ) ;
58
+ _logger . LogTrace ( "Handling DidChangeConfiguration" ) ;
60
59
if ( incomingSettings is null || incomingSettings . Powershell is null )
61
60
{
62
- this . _logger . LogTrace ( "Incoming settings were null" ) ;
61
+ _logger . LogTrace ( "Incoming settings were null" ) ;
63
62
return await Unit . Task . ConfigureAwait ( false ) ;
64
63
}
65
64
@@ -102,32 +101,30 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
102
101
}
103
102
104
103
// TODO: Load profiles when the host is already running
105
-
106
- if ( ! this . _cwdSet )
104
+ if ( ! _cwdSet )
107
105
{
108
106
if ( ! string . IsNullOrEmpty ( _configurationService . CurrentSettings . Cwd )
109
107
&& Directory . Exists ( _configurationService . CurrentSettings . Cwd ) )
110
108
{
111
- this . _logger . LogTrace ( $ "Setting CWD (from config) to { _configurationService . CurrentSettings . Cwd } ") ;
109
+ _logger . LogTrace ( $ "Setting CWD (from config) to { _configurationService . CurrentSettings . Cwd } ") ;
112
110
await _psesHost . SetInitialWorkingDirectoryAsync (
113
111
_configurationService . CurrentSettings . Cwd ,
114
112
CancellationToken . None ) . ConfigureAwait ( false ) ;
115
-
116
113
}
117
- else if ( _workspaceService . WorkspacePath != null
114
+ else if ( _workspaceService . WorkspacePath is not null
118
115
&& Directory . Exists ( _workspaceService . WorkspacePath ) )
119
116
{
120
- this . _logger . LogTrace ( $ "Setting CWD (from workspace) to { _workspaceService . WorkspacePath } ") ;
117
+ _logger . LogTrace ( $ "Setting CWD (from workspace) to { _workspaceService . WorkspacePath } ") ;
121
118
await _psesHost . SetInitialWorkingDirectoryAsync (
122
119
_workspaceService . WorkspacePath ,
123
120
CancellationToken . None ) . ConfigureAwait ( false ) ;
124
121
}
125
122
else
126
123
{
127
- this . _logger . LogTrace ( "Tried to set CWD but in bad state" ) ;
124
+ _logger . LogTrace ( "Tried to set CWD but in bad state" ) ;
128
125
}
129
126
130
- this . _cwdSet = true ;
127
+ _cwdSet = true ;
131
128
}
132
129
133
130
if ( ! _extensionServiceInitialized )
@@ -136,35 +133,46 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
136
133
}
137
134
138
135
// Run any events subscribed to configuration updates
139
- this . _logger . LogTrace ( "Running configuration update event handlers" ) ;
136
+ _logger . LogTrace ( "Running configuration update event handlers" ) ;
140
137
ConfigurationUpdated ? . Invoke ( this , _configurationService . CurrentSettings ) ;
141
138
142
139
// Convert the editor file glob patterns into an array for the Workspace
143
140
// Both the files.exclude and search.exclude hash tables look like (glob-text, is-enabled):
141
+ //
144
142
// "files.exclude" : {
145
143
// "Makefile": true,
146
144
// "*.html": true,
145
+ // "**/*.js": { "when": "$(basename).ts" },
147
146
// "build/*": true
148
147
// }
149
- var excludeFilePatterns = new List < string > ( ) ;
150
- if ( incomingSettings . Files ? . Exclude != null )
148
+ //
149
+ // TODO: We only support boolean values. The clause predicates are ignored, but perhaps
150
+ // they shouldn't be. At least it doesn't crash!
151
+ List < string > excludeFilePatterns = new ( ) ;
152
+ if ( incomingSettings . Files ? . Exclude is not null )
151
153
{
152
- foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Files . Exclude )
154
+ foreach ( KeyValuePair < string , object > patternEntry in incomingSettings . Files . Exclude )
153
155
{
154
- if ( patternEntry . Value ) { excludeFilePatterns . Add ( patternEntry . Key ) ; }
156
+ if ( patternEntry . Value is bool v && v )
157
+ {
158
+ excludeFilePatterns . Add ( patternEntry . Key ) ;
159
+ }
155
160
}
156
161
}
157
- if ( incomingSettings . Search ? . Exclude != null )
162
+ if ( incomingSettings . Search ? . Exclude is not null )
158
163
{
159
- foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Search . Exclude )
164
+ foreach ( KeyValuePair < string , object > patternEntry in incomingSettings . Search . Exclude )
160
165
{
161
- if ( patternEntry . Value && ! excludeFilePatterns . Contains ( patternEntry . Key ) ) { excludeFilePatterns . Add ( patternEntry . Key ) ; }
166
+ if ( patternEntry . Value is bool v && v && ! excludeFilePatterns . Contains ( patternEntry . Key ) )
167
+ {
168
+ excludeFilePatterns . Add ( patternEntry . Key ) ;
169
+ }
162
170
}
163
171
}
164
172
_workspaceService . ExcludeFilesGlob = excludeFilePatterns ;
165
173
166
174
// Convert the editor file search options to Workspace properties
167
- if ( incomingSettings . Search ? . FollowSymlinks != null )
175
+ if ( incomingSettings . Search ? . FollowSymlinks is not null )
168
176
{
169
177
_workspaceService . FollowSymlinks = incomingSettings . Search . FollowSymlinks ;
170
178
}
@@ -176,11 +184,11 @@ private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingS
176
184
{
177
185
if ( incomingSettings is null )
178
186
{
179
- this . _logger . LogTrace ( "Incoming settings were null" ) ;
187
+ _logger . LogTrace ( "Incoming settings were null" ) ;
180
188
return ;
181
189
}
182
190
183
- var configChanges = new Dictionary < string , bool > ( ) ;
191
+ Dictionary < string , bool > configChanges = new ( ) ;
184
192
// Send telemetry if the user opted-out of ScriptAnalysis
185
193
if ( incomingSettings . Powershell . ScriptAnalysis . Enable == false &&
186
194
_configurationService . CurrentSettings . ScriptAnalysis . Enable != incomingSettings . Powershell . ScriptAnalysis . Enable )
0 commit comments