Skip to content

Commit 4b0aead

Browse files
committed
(todo) Capture the editor settings and enforce file exclusions
1 parent 1efdfa0 commit 4b0aead

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

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

728757
// NEED TO CHECK FILE GLOBBING HERE!!

src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

Lines changed: 46 additions & 7 deletions
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)