Skip to content

Commit f99f9ee

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 92f54c5 commit f99f9ee

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

732762
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;
@@ -331,12 +332,51 @@ public void Update(
331332
}
332333
}
333334

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.
335+
/// <summary>
336+
/// Additional settings from the Language Client that affect Language Server operations but
337+
/// do not exist under the 'powershell' section
338+
/// </summary>
339+
public class EditorFileSettings
340+
{
341+
/// <summary>
342+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
343+
/// the glob is in effect.
344+
/// </summary>
345+
public Dictionary<string, bool> Exclude { get; set; }
346+
}
339347

340-
public LanguageServerSettings Powershell { get; set; }
341-
}
348+
/// <summary>
349+
/// Additional settings from the Language Client that affect Language Server operations but
350+
/// do not exist under the 'powershell' section
351+
/// </summary>
352+
public class EditorSearchSettings
353+
{
354+
/// <summary>
355+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
356+
/// the glob is in effect.
357+
/// </summary>
358+
public Dictionary<string, bool> Exclude { get; set; }
359+
/// <summary>
360+
/// Whether to follow symlinks when searching
361+
/// </summary>
362+
public bool FollowSymlinks { get; set; } = true;
363+
}
364+
365+
public class LanguageServerSettingsWrapper
366+
{
367+
// NOTE: This property is capitalized as 'Powershell' because the
368+
// mode name sent from the client is written as 'powershell' and
369+
// JSON.net is using camelCasing.
370+
public LanguageServerSettings Powershell { get; set; }
371+
372+
// NOTE: This property is capitalized as 'Files' because the
373+
// mode name sent from the client is written as 'files' and
374+
// JSON.net is using camelCasing.
375+
public EditorFileSettings Files { get; set; }
376+
377+
// NOTE: This property is capitalized as 'Search' because the
378+
// mode name sent from the client is written as 'search' and
379+
// JSON.net is using camelCasing.
380+
public EditorSearchSettings Search { get; set; }
342381
}
382+
}

0 commit comments

Comments
 (0)