/// <summary> /// Sets the list of line breakpoints for the current debugging session. /// </summary> /// <param name="scriptFile">The ScriptFile in which breakpoints will be set.</param> /// <param name="breakpoints">BreakpointDetails for each breakpoint that will be set.</param> /// <param name="clearExisting">If true, causes all existing breakpoints to be cleared before setting new ones.</param> /// <returns>An awaitable Task that will provide details about the breakpoints that were set.</returns> public async Task <BreakpointDetails[]> SetLineBreakpointsAsync( ScriptFile scriptFile, BreakpointDetails[] breakpoints, bool clearExisting = true) { var dscBreakpoints = this.powerShellContext .CurrentRunspace .GetCapability <DscBreakpointCapability>(); string scriptPath = scriptFile.FilePath; // Make sure we're using the remote script path if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote && this.remoteFileManager != null) { if (!this.remoteFileManager.IsUnderRemoteTempPath(scriptPath)) { this.logger.LogTrace( $"Could not set breakpoints for local path '{scriptPath}' in a remote session."); return(Array.Empty <BreakpointDetails>()); } string mappedPath = this.remoteFileManager.GetMappedPath( scriptPath, this.powerShellContext.CurrentRunspace); scriptPath = mappedPath; } else if ( this.temporaryScriptListingPath != null && this.temporaryScriptListingPath.Equals(scriptPath, StringComparison.CurrentCultureIgnoreCase)) { this.logger.LogTrace( $"Could not set breakpoint on temporary script listing path '{scriptPath}'."); return(Array.Empty <BreakpointDetails>()); } // Fix for issue #123 - file paths that contain wildcard chars [ and ] need to // quoted and have those wildcard chars escaped. string escapedScriptPath = PowerShellContextService.WildcardEscapePath(scriptPath); if (dscBreakpoints == null || !dscBreakpoints.IsDscResourcePath(escapedScriptPath)) { if (clearExisting) { await _breakpointService.RemoveAllBreakpointsAsync(scriptFile.FilePath).ConfigureAwait(false); } return((await _breakpointService.SetBreakpointsAsync(escapedScriptPath, breakpoints).ConfigureAwait(false)).ToArray()); } return(await dscBreakpoints.SetLineBreakpointsAsync( this.powerShellContext, escapedScriptPath, breakpoints).ConfigureAwait(false)); }
public void CorrectlyWildcardEscapesPaths_Spaces(string unescapedPath, string escapedPath) { string extensionEscapedPath = PowerShellContextService.WildcardEscapePath(unescapedPath, escapeSpaces: true); Assert.Equal(escapedPath, extensionEscapedPath); }