protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpointsArguments arguments) { List <Breakpoint> result = new List <Breakpoint>(); var path = arguments.Source.Path.ToLower(); var pts = _points[path] = new List <BreakPoint>(); foreach (var bt in arguments.Breakpoints) { pts.Add(new BreakPoint(path, bt.Line)); result.Add(new Breakpoint(true) { Source = arguments.Source, Line = bt.Line }); } return(new SetBreakpointsResponse(result)); }
protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpointsArguments arguments) { try { if (session == null) { throw new InvalidOperationException(); } var breakpoints = session.SetBreakpoints(arguments.Source, arguments.Breakpoints).ToList(); return(new SetBreakpointsResponse(breakpoints)); } catch (Exception ex) { Log(ex.Message, LogCategory.DebugAdapterOutput); throw new ProtocolException(ex.Message, ex); } }
internal SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpointsArguments arguments) { if (arguments.Breakpoints == null) { throw new ProtocolException("No breakpoints set"); } List <Breakpoint> responseBreakpoints; if (String.Equals(arguments.Source.Path, this.adapter.Source.Path, StringComparison.OrdinalIgnoreCase)) { this.breakpoints.Clear(); responseBreakpoints = new List <Breakpoint>(arguments.Breakpoints.Count); foreach (var sourceBreakpoint in arguments.Breakpoints) { int?resolveLineNumber = this.ResolveBreakpoint(this.adapter.LineFromClient(sourceBreakpoint.Line)); if (resolveLineNumber.HasValue) { this.breakpoints.Add(resolveLineNumber.Value); } Breakpoint bp = (!resolveLineNumber.HasValue) ? new Breakpoint(verified: false, id: Int32.MaxValue, message: "No code on line.") : new Breakpoint( verified: true, id: resolveLineNumber, line: this.adapter.LineToClient(resolveLineNumber.Value), source: this.adapter.Source ); responseBreakpoints.Add(bp); } } else { // Breakpoints are not in this file - mark them all as failed responseBreakpoints = arguments.Breakpoints.Select(b => new Breakpoint(verified: false, id: Int32.MaxValue, message: "No code in file.")).ToList(); } return(new SetBreakpointsResponse(breakpoints: responseBreakpoints)); }
protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpointsArguments arguments) { List <Breakpoint> result = new List <Breakpoint>(); HashSet <VSCodeBreakPoint> validBPs = new HashSet <VSCodeBreakPoint>(); foreach (var i in arguments.Breakpoints) { try { VSCodeBreakPoint bp = debugged.FindBreakpoint(arguments.Source.Path, i.Line); if (bp != null) { if (bp.ConditionExpression != i.Condition) { debugged.SendSetBreakpointCondition(bp.GetHashCode(), string.IsNullOrEmpty(i.Condition) ? Runtime.Debugger.Protocol.BreakpointConditionStyle.None : Runtime.Debugger.Protocol.BreakpointConditionStyle.WhenTrue, i.Condition); } } else { bp = new VSCodeBreakPoint(debugged, arguments.Source, i.Line, i.Column.GetValueOrDefault(), i.Condition); } validBPs.Add(bp); if (!bp.IsBound && bp.TryBind()) { debugged.AddPendingBreakpoint(bp); result.Add(bp.BreakPoint); } } catch (Exception ex) { SendOutput(ex.ToString()); } } debugged.UpdateBreakpoints(arguments.Source.Path, validBPs); return(new SetBreakpointsResponse(result)); }
protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpointsArguments arguments) { var breakpoints = new List <Breakpoint>(); var addresses = new List <uint>(); foreach (var bp in arguments.Breakpoints) { bool foundLine = false; for (int i = 0; i < 4; i++) { var mapping = DebugMap?.GetMapping(arguments.Source.Path, bp.Line + i); if (mapping.HasValue) { foundLine = true; breakpoints.Add(new Breakpoint() { Line = mapping.Value.Line, Verified = true }); addresses.Add(mapping.Value.Address); break; } } if (!foundLine) { breakpoints.Add(new Breakpoint() { Line = bp.Line, Verified = false }); } } Controller.Breakpoints = addresses.ToImmutableArray(); return(new SetBreakpointsResponse(breakpoints)); }
public async Task <SetBreakpointsResponse> Handle(SetBreakpointsArguments request, CancellationToken cancellationToken) { ScriptFile scriptFile = null; // When you set a breakpoint in the right pane of a Git diff window on a PS1 file, // the Source.Path comes through as Untitled-X. That's why we check for IsUntitledPath. if (!ScriptFile.IsUntitledPath(request.Source.Path) && !_workspaceService.TryGetFile( request.Source.Path, out scriptFile)) { string message = _debugStateService.NoDebug ? string.Empty : "Source file could not be accessed, breakpoint not set."; var srcBreakpoints = request.Breakpoints .Select(srcBkpt => LspDebugUtils.CreateBreakpoint( srcBkpt, request.Source.Path, message, verified: _debugStateService.NoDebug)); // Return non-verified breakpoint message. return(new SetBreakpointsResponse { Breakpoints = new Container <Breakpoint>(srcBreakpoints) }); } // Verify source file is a PowerShell script file. string fileExtension = Path.GetExtension(scriptFile?.FilePath ?? "")?.ToLower(); if (string.IsNullOrEmpty(fileExtension) || ((fileExtension != ".ps1") && (fileExtension != ".psm1"))) { _logger.LogWarning( $"Attempted to set breakpoints on a non-PowerShell file: {request.Source.Path}"); string message = _debugStateService.NoDebug ? string.Empty : "Source is not a PowerShell script, breakpoint not set."; var srcBreakpoints = request.Breakpoints .Select(srcBkpt => LspDebugUtils.CreateBreakpoint( srcBkpt, request.Source.Path, message, verified: _debugStateService.NoDebug)); // Return non-verified breakpoint message. return(new SetBreakpointsResponse { Breakpoints = new Container <Breakpoint>(srcBreakpoints) }); } // At this point, the source file has been verified as a PowerShell script. BreakpointDetails[] breakpointDetails = request.Breakpoints .Select((srcBreakpoint) => BreakpointDetails.Create( scriptFile.FilePath, (int)srcBreakpoint.Line, (int?)srcBreakpoint.Column, srcBreakpoint.Condition, srcBreakpoint.HitCondition)) .ToArray(); // If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints. BreakpointDetails[] updatedBreakpointDetails = breakpointDetails; if (!_debugStateService.NoDebug) { _debugStateService.SetBreakpointInProgress = true; try { updatedBreakpointDetails = await _debugService.SetLineBreakpointsAsync( scriptFile, breakpointDetails); } catch (Exception e) { // Log whatever the error is _logger.LogException($"Caught error while setting breakpoints in SetBreakpoints handler for file {scriptFile?.FilePath}", e); } finally { _debugStateService.SetBreakpointInProgress = false; } } return(new SetBreakpointsResponse { Breakpoints = new Container <Breakpoint>(updatedBreakpointDetails .Select(LspDebugUtils.CreateBreakpoint)) }); }
public async Task <SetBreakpointsResponse> Handle(SetBreakpointsArguments request, CancellationToken cancellationToken) { if (!_workspaceService.TryGetFile(request.Source.Path, out ScriptFile scriptFile)) { string message = _debugStateService.NoDebug ? string.Empty : "Source file could not be accessed, breakpoint not set."; var srcBreakpoints = request.Breakpoints .Select(srcBkpt => LspDebugUtils.CreateBreakpoint( srcBkpt, request.Source.Path, message, verified: _debugStateService.NoDebug)); // Return non-verified breakpoint message. return(new SetBreakpointsResponse { Breakpoints = new Container <Breakpoint>(srcBreakpoints) }); } // Verify source file is a PowerShell script file. string fileExtension = Path.GetExtension(scriptFile?.FilePath ?? "")?.ToLower(); bool isUntitledPath = ScriptFile.IsUntitledPath(request.Source.Path); if ((!isUntitledPath && fileExtension != ".ps1" && fileExtension != ".psm1") || (!BreakpointApiUtils.SupportsBreakpointApis && isUntitledPath)) { _logger.LogWarning( $"Attempted to set breakpoints on a non-PowerShell file: {request.Source.Path}"); string message = _debugStateService.NoDebug ? string.Empty : "Source is not a PowerShell script, breakpoint not set."; var srcBreakpoints = request.Breakpoints .Select(srcBkpt => LspDebugUtils.CreateBreakpoint( srcBkpt, request.Source.Path, message, verified: _debugStateService.NoDebug)); // Return non-verified breakpoint message. return(new SetBreakpointsResponse { Breakpoints = new Container <Breakpoint>(srcBreakpoints) }); } // At this point, the source file has been verified as a PowerShell script. BreakpointDetails[] breakpointDetails = request.Breakpoints .Select((srcBreakpoint) => BreakpointDetails.Create( scriptFile.FilePath, srcBreakpoint.Line, srcBreakpoint.Column, srcBreakpoint.Condition, srcBreakpoint.HitCondition, srcBreakpoint.LogMessage)) .ToArray(); // If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints. BreakpointDetails[] updatedBreakpointDetails = breakpointDetails; if (!_debugStateService.NoDebug) { await _debugStateService.WaitForSetBreakpointHandleAsync().ConfigureAwait(false); try { updatedBreakpointDetails = await _debugService.SetLineBreakpointsAsync( scriptFile, breakpointDetails).ConfigureAwait(false); } catch (Exception e) { // Log whatever the error is _logger.LogException($"Caught error while setting breakpoints in SetBreakpoints handler for file {scriptFile?.FilePath}", e); } finally { _debugStateService.ReleaseSetBreakpointHandle(); } } return(new SetBreakpointsResponse { Breakpoints = new Container <Breakpoint>(updatedBreakpointDetails .Select(LspDebugUtils.CreateBreakpoint)) }); }
protected override SetBreakpointsResponse HandleSetBreakpointsRequest(SetBreakpointsArguments arguments) { return(this.BreakpointManager.HandleSetBreakpointsRequest(arguments)); }