Skip to content

Commit 98bb377

Browse files
committed
(PowerShellGH-879) Capture the editor settings and enforce file exclusions
Previously the EnumeratePSFiles method was modified to be able to use globbing patterns to filter workspace files. This commit * Modifies the LanguageServerSettings class to capture the 'files' and 'search' Settings in order to determine the correct list of glob patterns to use when searching. Currently the 'files.exclude' and 'search.exclude' are merged together to generate the list of globs and then set the Workspace settings appropriately * Uses the 'search.followSymlinks' setting to determine whether to ignore reparse points Note that the LanguageClient must be configured to send these settings during the didChangeConfiguration events otherwise it will default to include everything.
1 parent db86d32 commit 98bb377

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+30
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,36 @@ await this.RunScriptDiagnosticsAsync(
726726
this.editorSession,
727727
eventContext);
728728
}
729+
730+
// Convert the editor file glob patterns into an array for the Workspace
731+
// Both the files.exclude anbd search.exclude hash tables look like (glob-text, is-enabled):
732+
// "files.exclude" : {
733+
// "Makefile": true,
734+
// "*.html": true,
735+
// "build/*": true
736+
// }
737+
var excludeFilePatterns = new List<string>();
738+
if (configChangeParams.Settings.Files?.Exclude != null)
739+
{
740+
foreach(KeyValuePair<string, bool> patternEntry in configChangeParams.Settings.Files.Exclude)
741+
{
742+
if (patternEntry.Value) { excludeFilePatterns.Add(patternEntry.Key); }
743+
}
744+
}
745+
if (configChangeParams.Settings.Search?.Exclude != null)
746+
{
747+
foreach(KeyValuePair<string, bool> patternEntry in configChangeParams.Settings.Files.Exclude)
748+
{
749+
if (patternEntry.Value && !excludeFilePatterns.Contains(patternEntry.Key)) { excludeFilePatterns.Add(patternEntry.Key); }
750+
}
751+
}
752+
editorSession.Workspace.ExcludeFilesGlob = excludeFilePatterns;
753+
754+
// Convert the editor file search options to Workspace properties
755+
if (configChangeParams.Settings.Search?.FollowSymlinks != null)
756+
{
757+
editorSession.Workspace.FollowSymlinks = configChangeParams.Settings.Search.FollowSymlinks;
758+
}
729759
}
730760

731761
protected async Task HandleDefinitionRequestAsync(

src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

+47-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.PowerShell.EditorServices.Utility;
77
using System;
88
using System.Collections;
9+
using System.Collections.Generic;
910
using System.IO;
1011
using System.Reflection;
1112
using System.Security;
@@ -300,12 +301,51 @@ public void Update(
300301
}
301302
}
302303

303-
public class LanguageServerSettingsWrapper
304-
{
305-
// NOTE: This property is capitalized as 'Powershell' because the
306-
// mode name sent from the client is written as 'powershell' and
307-
// JSON.net is using camelCasing.
304+
/// <summary>
305+
/// Additional settings from the Language Client that affect Language Server operations but
306+
/// do not exist under the 'powershell' section
307+
/// </summary>
308+
public class EditorFileSettings
309+
{
310+
/// <summary>
311+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
312+
/// the glob is in effect.
313+
/// </summary>
314+
public Dictionary<string, bool> Exclude { get; set; }
315+
}
308316

309-
public LanguageServerSettings Powershell { get; set; }
310-
}
317+
/// <summary>
318+
/// Additional settings from the Language Client that affect Language Server operations but
319+
/// do not exist under the 'powershell' section
320+
/// </summary>
321+
public class EditorSearchSettings
322+
{
323+
/// <summary>
324+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
325+
/// the glob is in effect.
326+
/// </summary>
327+
public Dictionary<string, bool> Exclude { get; set; }
328+
/// <summary>
329+
/// Whether to follow symlinks when searching
330+
/// </summary>
331+
public bool FollowSymlinks { get; set; } = true;
332+
}
333+
334+
public class LanguageServerSettingsWrapper
335+
{
336+
// NOTE: This property is capitalized as 'Powershell' because the
337+
// mode name sent from the client is written as 'powershell' and
338+
// JSON.net is using camelCasing.
339+
public LanguageServerSettings Powershell { get; set; }
340+
341+
// NOTE: This property is capitalized as 'Files' because the
342+
// mode name sent from the client is written as 'files' and
343+
// JSON.net is using camelCasing.
344+
public EditorFileSettings Files { get; set; }
345+
346+
// NOTE: This property is capitalized as 'Search' because the
347+
// mode name sent from the client is written as 'search' and
348+
// JSON.net is using camelCasing.
349+
public EditorSearchSettings Search { get; set; }
311350
}
351+
}

0 commit comments

Comments
 (0)