Skip to content

Commit 8d0eba2

Browse files
committed
Avoid error when exclude entry is a clause
1 parent d061bcf commit 8d0eba2

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
using Microsoft.PowerShell.EditorServices.Logging;
1212
using Microsoft.PowerShell.EditorServices.Services;
1313
using Microsoft.PowerShell.EditorServices.Services.Configuration;
14+
using Microsoft.PowerShell.EditorServices.Services.Extension;
15+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1416
using Newtonsoft.Json.Linq;
1517
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1618
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1719
using OmniSharp.Extensions.LanguageServer.Protocol.Window;
1820
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
19-
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
20-
using Microsoft.PowerShell.EditorServices.Services.Extension;
2121

2222
namespace Microsoft.PowerShell.EditorServices.Handlers
2323
{
@@ -110,7 +110,6 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
110110
await _psesHost.SetInitialWorkingDirectoryAsync(
111111
_configurationService.CurrentSettings.Cwd,
112112
CancellationToken.None).ConfigureAwait(false);
113-
114113
}
115114
else if (_workspaceService.WorkspacePath is not null
116115
&& Directory.Exists(_workspaceService.WorkspacePath))
@@ -139,24 +138,35 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
139138

140139
// Convert the editor file glob patterns into an array for the Workspace
141140
// Both the files.exclude and search.exclude hash tables look like (glob-text, is-enabled):
141+
//
142142
// "files.exclude" : {
143143
// "Makefile": true,
144144
// "*.html": true,
145+
// "**/*.js": { "when": "$(basename).ts" },
145146
// "build/*": true
146147
// }
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!
147151
List<string> excludeFilePatterns = new();
148152
if (incomingSettings.Files?.Exclude is not null)
149153
{
150-
foreach (KeyValuePair<string, bool> patternEntry in incomingSettings.Files.Exclude)
154+
foreach (KeyValuePair<string, object> patternEntry in incomingSettings.Files.Exclude)
151155
{
152-
if (patternEntry.Value) { excludeFilePatterns.Add(patternEntry.Key); }
156+
if (patternEntry.Value is bool v && v)
157+
{
158+
excludeFilePatterns.Add(patternEntry.Key);
159+
}
153160
}
154161
}
155162
if (incomingSettings.Search?.Exclude is not null)
156163
{
157-
foreach (KeyValuePair<string, bool> patternEntry in incomingSettings.Search.Exclude)
164+
foreach (KeyValuePair<string, object> patternEntry in incomingSettings.Search.Exclude)
158165
{
159-
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+
}
160170
}
161171
}
162172
_workspaceService.ExcludeFilesGlob = excludeFilePatterns;

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,10 @@ public void Update(
403403
internal class EditorFileSettings
404404
{
405405
/// <summary>
406-
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
407-
/// the glob is in effect.
406+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value
407+
/// OR object with a predicate clause to indicate if the glob is in effect.
408408
/// </summary>
409-
public Dictionary<string, bool> Exclude { get; set; }
409+
public Dictionary<string, object> Exclude { get; set; }
410410
}
411411

412412
/// <summary>
@@ -416,10 +416,11 @@ internal class EditorFileSettings
416416
internal class EditorSearchSettings
417417
{
418418
/// <summary>
419-
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
420-
/// the glob is in effect.
419+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value
420+
/// OR object with a predicate clause to indicate if the glob is in effect.
421421
/// </summary>
422-
public Dictionary<string, bool> Exclude { get; set; }
422+
public Dictionary<string, object> Exclude { get; set; }
423+
423424
/// <summary>
424425
/// Whether to follow symlinks when searching
425426
/// </summary>

0 commit comments

Comments
 (0)