Skip to content

Commit 3ef180a

Browse files
committed
Avoid error when exclude entry is a clause
1 parent d061bcf commit 3ef180a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

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

Lines changed: 14 additions & 7 deletions
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,32 @@ 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
// }
147148
List<string> excludeFilePatterns = new();
148149
if (incomingSettings.Files?.Exclude is not null)
149150
{
150-
foreach (KeyValuePair<string, bool> patternEntry in incomingSettings.Files.Exclude)
151+
foreach (KeyValuePair<string, object> patternEntry in incomingSettings.Files.Exclude)
151152
{
152-
if (patternEntry.Value) { excludeFilePatterns.Add(patternEntry.Key); }
153+
if (patternEntry.Value is bool v && v)
154+
{
155+
excludeFilePatterns.Add(patternEntry.Key);
156+
}
153157
}
154158
}
155159
if (incomingSettings.Search?.Exclude is not null)
156160
{
157-
foreach (KeyValuePair<string, bool> patternEntry in incomingSettings.Search.Exclude)
161+
foreach (KeyValuePair<string, object> patternEntry in incomingSettings.Search.Exclude)
158162
{
159-
if (patternEntry.Value && !excludeFilePatterns.Contains(patternEntry.Key)) { excludeFilePatterns.Add(patternEntry.Key); }
163+
if (patternEntry.Value is bool v && v && !excludeFilePatterns.Contains(patternEntry.Key))
164+
{
165+
excludeFilePatterns.Add(patternEntry.Key);
166+
}
160167
}
161168
}
162169
_workspaceService.ExcludeFilesGlob = excludeFilePatterns;

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ internal class EditorFileSettings
406406
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
407407
/// 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>
@@ -419,7 +419,7 @@ internal class EditorSearchSettings
419419
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
420420
/// the glob is in effect.
421421
/// </summary>
422-
public Dictionary<string, bool> Exclude { get; set; }
422+
public Dictionary<string, object> Exclude { get; set; }
423423
/// <summary>
424424
/// Whether to follow symlinks when searching
425425
/// </summary>

0 commit comments

Comments
 (0)