Skip to content

Commit c60d8d4

Browse files
committed
Use verbatim strings consistently for qualified modules
1 parent cb0487c commit c60d8d4

File tree

10 files changed

+16
-16
lines changed

10 files changed

+16
-16
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private void RemovePSReadLineForStartup()
301301
{
302302
_logger.Log(PsesLogLevel.Verbose, "Removing PSReadLine");
303303
using SMA.PowerShell pwsh = SMA.PowerShell.Create(RunspaceMode.CurrentRunspace);
304-
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
304+
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo(@"Microsoft.PowerShell.Core\Get-Module", typeof(GetModuleCommand)))
305305
.AddParameter("Name", "PSReadLine")
306306
.Invoke()
307307
.Count > 0;
@@ -310,7 +310,7 @@ private void RemovePSReadLineForStartup()
310310
{
311311
pwsh.Commands.Clear();
312312

313-
pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Remove-Module", typeof(RemoveModuleCommand)))
313+
pwsh.AddCommand(new CmdletInfo(@"Microsoft.PowerShell.Core\Remove-Module", typeof(RemoveModuleCommand)))
314314
.AddParameter("Name", "PSReadLine")
315315
.AddParameter("ErrorAction", "SilentlyContinue");
316316

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ await _executionService.ExecutePSCommandAsync(
378378
if (request.RunspaceName != null)
379379
{
380380
PSCommand getRunspaceIdCommand = new PSCommand()
381-
.AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace")
381+
.AddCommand(@"Microsoft.PowerShell.Utility\Get-Runspace")
382382
.AddParameter("Name", request.RunspaceName)
383-
.AddCommand("Microsoft.PowerShell.Utility\\Select-Object")
383+
.AddCommand(@"Microsoft.PowerShell.Utility\Select-Object")
384384
.AddParameter("ExpandProperty", "Id");
385385

386386
try

src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
9292
if (!isDscInstalled.HasValue)
9393
{
9494
PSCommand psCommand = new PSCommand()
95-
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
95+
.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
9696
.AddParameter("-Name", "PSDesiredStateConfiguration")
9797
.AddParameter("PassThru")
9898
.AddParameter("ErrorAction", ActionPreference.Ignore);

src/PowerShellEditorServices/Services/PowerShell/Handlers/GetCommandHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public async Task<List<PSCommandMessage>> Handle(GetCommandParams request, Cance
4242
// Executes the following:
4343
// Get-Command -CommandType Function,Cmdlet,ExternalScript | Sort-Object -Property Name
4444
psCommand
45-
.AddCommand("Microsoft.PowerShell.Core\\Get-Command")
45+
.AddCommand(@"Microsoft.PowerShell.Core\Get-Command")
4646
.AddParameter("CommandType", new[] { "Function", "Cmdlet", "ExternalScript" })
47-
.AddCommand("Microsoft.PowerShell.Utility\\Sort-Object")
47+
.AddCommand(@"Microsoft.PowerShell.Utility\Sort-Object")
4848
.AddParameter("Property", "Name");
4949

5050
IEnumerable<CommandInfo> result = await _executionService.ExecutePSCommandAsync<CommandInfo>(psCommand, cancellationToken).ConfigureAwait(false);

src/PowerShellEditorServices/Services/PowerShell/Handlers/PSHostProcessAndRunspaceHandlers.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public async Task<RunspaceResponse[]> Handle(GetRunspaceParams request, Cancella
7474
rs.Open();
7575
ps.Runspace = rs;
7676
// Returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.
77-
runspaces = ps.AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace").Invoke<PSObject>();
77+
runspaces = ps.AddCommand(@"Microsoft.PowerShell.Utility\Get-Runspace").Invoke<PSObject>();
7878
}
7979
else
8080
{
81-
PSCommand psCommand = new PSCommand().AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace");
81+
PSCommand psCommand = new PSCommand().AddCommand(@"Microsoft.PowerShell.Utility\Get-Runspace");
8282
// returns (not deserialized) Runspaces. For simpler code, we use PSObject and rely on dynamic later.
8383
runspaces = await _executionService.ExecutePSCommandAsync<PSObject>(psCommand, cancellationToken).ConfigureAwait(false);
8484
}

src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public static async Task<AliasMap> GetAliasesAsync(
237237
// our PSRL on idle handler.
238238
IReadOnlyList<CommandInfo> aliases = await executionService.ExecutePSCommandAsync<CommandInfo>(
239239
new PSCommand()
240-
.AddCommand("Microsoft.PowerShell.Core\\Get-Command")
240+
.AddCommand(@"Microsoft.PowerShell.Core\Get-Command")
241241
.AddParameter("ListImported", true)
242242
.AddParameter("CommandType", CommandTypes.Alias),
243243
cancellationToken).ConfigureAwait(false);

src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static void SetCorrectExecutionPolicy(this PowerShell pwsh, ILogger logge
139139
// We want to get the list hierarchy of execution policies
140140
// Calling the cmdlet is the simplest way to do that
141141
IReadOnlyList<PSObject> policies = pwsh
142-
.AddCommand("Microsoft.PowerShell.Security\\Get-ExecutionPolicy")
142+
.AddCommand(@"Microsoft.PowerShell.Security\Get-ExecutionPolicy")
143143
.AddParameter("-List")
144144
.InvokeAndClear<PSObject>();
145145

@@ -181,7 +181,7 @@ public static void SetCorrectExecutionPolicy(this PowerShell pwsh, ILogger logge
181181
logger.LogTrace("Setting execution policy to {Policy}", policyToSet);
182182
try
183183
{
184-
pwsh.AddCommand("Microsoft.PowerShell.Security\\Set-ExecutionPolicy")
184+
pwsh.AddCommand(@"Microsoft.PowerShell.Security\Set-ExecutionPolicy")
185185
.AddParameter("Scope", ExecutionPolicyScope.Process)
186186
.AddParameter("ExecutionPolicy", policyToSet)
187187
.AddParameter("Force")
@@ -222,7 +222,7 @@ public static void LoadProfiles(this PowerShell pwsh, ProfilePathInfo profilePat
222222

223223
public static void ImportModule(this PowerShell pwsh, string moduleNameOrPath)
224224
{
225-
pwsh.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
225+
pwsh.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
226226
.AddParameter("-Name", moduleNameOrPath)
227227
.InvokeAndClear();
228228
}

src/PowerShellEditorServices/Services/Template/TemplateService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ await _executionService.ExecutePSCommandAsync<PSObject>(
8989

9090
psCommand = new PSCommand();
9191
psCommand
92-
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
92+
.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
9393
.AddParameter("ModuleInfo", (PSModuleInfo)moduleObject[0].ImmediateBaseObject)
9494
.AddParameter("PassThru")
9595
.AddParameter("ErrorAction", ActionPreference.Ignore);

src/PowerShellEditorServices/Services/Workspace/RemoteFileManagerService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public async Task<string> FetchRemoteFileAsync(
316316
{
317317
// Load the file contents from the remote machine and create the buffer
318318
PSCommand command = new PSCommand()
319-
.AddCommand("Microsoft.PowerShell.Management\\Get-Content")
319+
.AddCommand(@"Microsoft.PowerShell.Management\Get-Content")
320320
.AddParameter("Path", remoteFilePath)
321321
.AddParameter("Raw");
322322

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ await debugService.SetCommandBreakpointsAsync(
11401140
VariableDetailsBase var = Array.Find(variables, v => v.Name == "$file");
11411141
VariableDetailsBase[] childVars = await debugService.GetVariables(var.Id, CancellationToken.None).ConfigureAwait(true);
11421142
Assert.Contains(childVars, i => i.Name is "PSPath");
1143-
Assert.Contains(childVars, i => i.Name is "PSProvider" && i.ValueString is "Microsoft.PowerShell.Core\\FileSystem");
1143+
Assert.Contains(childVars, i => i.Name is "PSProvider" && i.ValueString is @"Microsoft.PowerShell.Core\FileSystem");
11441144
Assert.Contains(childVars, i => i.Name is "Exists" && i.ValueString is "$true");
11451145
Assert.Contains(childVars, i => i.Name is "LastAccessTime");
11461146
}

0 commit comments

Comments
 (0)