-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBreakpointManager.cs
More file actions
84 lines (71 loc) · 3.07 KB
/
Copy pathBreakpointManager.cs
File metadata and controls
84 lines (71 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
namespace SampleDebugAdapter
{
internal class BreakpointManager
{
private SampleDebugAdapter adapter;
private HashSet<int> breakpoints;
internal BreakpointManager(SampleDebugAdapter adapter)
{
this.adapter = adapter;
this.breakpoints = new HashSet<int>();
}
internal bool HasLineBreakpoint(int line)
{
return this.breakpoints.Contains(line);
}
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);
}
private int? ResolveBreakpoint(int lineNumber)
{
if (lineNumber < 0)
return null;
// Breakpoint can only bind on a non-comment line that has text.
for (int i = lineNumber; i < this.adapter.Lines.Count; i++)
{
if (!String.IsNullOrEmpty(this.adapter.Lines[i]) &&
!this.adapter.Lines[i].Trim().StartsWith("#", StringComparison.Ordinal))
return i;
}
return null;
}
}
}