Skip to content

Commit cedbd6a

Browse files
committed
(GH-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 9d72473 commit cedbd6a

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

Diff for: src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+29
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,35 @@ await this.RunScriptDiagnosticsAsync(
726726
this.editorSession,
727727
eventContext);
728728
}
729+
730+
// Convert the editor file glob patterns into an array for the Workspace
731+
// TODO Is this thread-safe? this is hardly an atomic operation. But intermediate objects
732+
// are costly. Given it's a config only change maybe a race condition won't occur?
733+
editorSession.Workspace.ExcludeFilesGlob.Clear();
734+
if (configChangeParams.Settings.Files != null && configChangeParams.Settings.Files.Exclude != null)
735+
{
736+
foreach(string pattern in configChangeParams.Settings.Files.Exclude.Keys)
737+
{
738+
if (configChangeParams.Settings.Files.Exclude[pattern] && !editorSession.Workspace.ExcludeFilesGlob.Contains(pattern))
739+
{
740+
editorSession.Workspace.ExcludeFilesGlob.Add(pattern);
741+
}
742+
}
743+
}
744+
if (configChangeParams.Settings.Search != null && configChangeParams.Settings.Search.Exclude != null)
745+
{
746+
foreach(string pattern in configChangeParams.Settings.Search.Exclude.Keys)
747+
{
748+
if (configChangeParams.Settings.Search.Exclude[pattern] && !editorSession.Workspace.ExcludeFilesGlob.Contains(pattern))
749+
{
750+
editorSession.Workspace.ExcludeFilesGlob.Add(pattern);
751+
}
752+
}
753+
}
754+
if (configChangeParams.Settings.Search != null && configChangeParams.Settings.Search.FollowSymlinks != null)
755+
{
756+
editorSession.Workspace.FollowSymlinks = configChangeParams.Settings.Search.FollowSymlinks;
757+
}
729758
}
730759

731760
protected async Task HandleDefinitionRequestAsync(

Diff for: src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

+46-7
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,51 @@ public void Update(
300300
}
301301
}
302302

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.
303+
/// <summary>
304+
/// Additional settings from the Language Client that affect Language Server operations but
305+
/// do not exist under the 'powershell' section
306+
/// </summary>
307+
public class EditorFileSettings
308+
{
309+
/// <summary>
310+
/// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the
311+
/// the glob is in effect.
312+
/// </summary>
313+
public System.Collections.Generic.Dictionary<string, Boolean> Exclude { get; set; }
314+
}
308315

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

0 commit comments

Comments
 (0)