Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit f9dc94a

Browse files
committed
add thread support
1 parent 3558496 commit f9dc94a

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

src/main.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,11 @@ class MockDebugSession extends DebugSession {
113113
for (var i = 0; i < clientLines.length; i++) {
114114
var l = this.convertClientLineToDebugger(clientLines[i]);
115115
var verified = false;
116+
116117
if (l < lines.length) {
117-
const line = lines[l-1].trim();
118-
// if a line is empty or starts with '+' we don't allow to set a breakpoint but move the breakpoint down
119-
if (line.length == 0 || line.indexOf("+") == 0)
120-
l++;
121-
// if a line starts with '-' we don't allow to set a breakpoint but move the breakpoint up
122-
if (line.indexOf("-") == 0)
123-
l--;
124-
// don't set 'verified' to true if the line contains the word 'lazy'
125-
// in this case the breakpoint will be verified 'lazy' after hitting it once.
126-
if (line.indexOf("lazy") < 0) {
127-
verified = true; // this breakpoint has been validated
128-
}
118+
verified = true; // this breakpoint has been validated
129119
}
120+
130121
const bp = <DebugProtocol.Breakpoint> new Breakpoint(verified, this.convertDebuggerLineToClient(l));
131122
bp.id = this._breakpointId++;
132123
var command = ["break", "test.rb:"+bp.line];
@@ -144,13 +135,23 @@ class MockDebugSession extends DebugSession {
144135

145136
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
146137

147-
// return the default thread
148-
response.body = {
149-
threads: [
150-
new Thread(MockDebugSession.THREAD_ID, "thread 1")
151-
]
152-
};
153-
this.sendResponse(response);
138+
this.rubyProcess.Enqueue("thread list\n").then((xml: XMLDocument) => {
139+
if (xml.documentElement.nodeName !== "threads") {
140+
return;
141+
}
142+
143+
var threads = new Array<Thread>();
144+
for(let i= 0; i < xml.documentElement.childNodes.length; i++) {
145+
var threadNode = xml.documentElement.childNodes.item(i);
146+
var threadId = threadNode.attributes.getNamedItem("id");
147+
148+
threads.push(new Thread(+threadId.value, "thread_"+threadId.value));
149+
}
150+
response.body = {
151+
threads: threads
152+
};
153+
this.sendResponse(response);
154+
});
154155
}
155156

156157
// Called by VS Code after a StoppedEvent

src/ruby.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export class RubyProcess extends EventEmitter {
9999
(/^<variables>/.test(chunk) && !/<\/variables>$/.test(chunk)) ||
100100
(/^<variable .*?\/>$/.test(chunk) && this.buffer !== "") ||
101101
(/^<breakpoints>/.test(chunk) && !/<\/breakpoints>$/.test(chunk)) ||
102-
(/^<breakpoint .*?\/>$/.test(chunk) && this.buffer !== "")
102+
(/^<breakpoint .*?\/>$/.test(chunk) && this.buffer !== "") ||
103+
(/^<threads>/.test(chunk) && !/\/threads>$/.test(chunk))
103104
) {
104105
that.buffer += chunk;
105106
return;
@@ -110,10 +111,17 @@ export class RubyProcess extends EventEmitter {
110111
that.buffer += chunk;
111112
return;
112113
}
114+
else if (
115+
(/^<thread .*?>$/.test(chunk) && !/<\/threads>$/.test(chunk)) ||
116+
/<\/thread>$/.test(chunk)
117+
) {
118+
that.buffer += chunk;
119+
}
113120
else if (
114121
/<\/frames>$/.test(chunk) ||
115122
/<\/variables>$/.test(chunk) ||
116-
/<\/breakpoints>$/.test(chunk)
123+
/<\/breakpoints>$/.test(chunk) ||
124+
/<\/threads>$/.test(chunk)
117125
) {
118126
that.buffer = that.buffer + chunk;
119127
if (/<\/frames>$/.test(chunk)) {
@@ -124,6 +132,10 @@ export class RubyProcess extends EventEmitter {
124132
document = that.parser.parseFromString(that.buffer, 'application/xml');
125133
that.FinishCmd(document);
126134
}
135+
else if (/<\/threads>$/.test(chunk)) {
136+
document = that.parser.parseFromString(that.buffer, 'application/xml');
137+
that.FinishCmd(document);
138+
}
127139
that.buffer = "";
128140
}
129141
});

0 commit comments

Comments
 (0)