Skip to content

Commit cb1b375

Browse files
committed
Add part 1 of tutorial.
1 parent a537dd4 commit cb1b375

File tree

6 files changed

+12666
-0
lines changed

6 files changed

+12666
-0
lines changed

part1/__debug_output__.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Debug output gotten from starting the debugger and then stopping it:
2+
3+
Starting. Args: X:/vscode-pydev/vscode-pydev/debugger/debug_adapter_main.py
4+
read line: >>Content-Length: 312\r\n<<
5+
read line: >>\r\n<<
6+
Process json: {
7+
"arguments": {
8+
"adapterID": "PyDev",
9+
"clientID": "vscode",
10+
"clientName": "Visual Studio Code",
11+
"columnsStartAt1": true,
12+
"linesStartAt1": true,
13+
"locale": "en-us",
14+
"pathFormat": "path",
15+
"supportsRunInTerminalRequest": true,
16+
"supportsVariablePaging": true,
17+
"supportsVariableType": true
18+
},
19+
"command": "initialize",
20+
"seq": 1,
21+
"type": "request"
22+
}
23+
Writing: {"request_seq": 1, "body": {"supportsConfigurationDoneRequest": true, "supportsConditionalBreakpoints": true}, "success": true, "seq": 0, "command": "initialize", "type": "response"}
24+
Writing: {"type": "event", "event": "initialized", "seq": 1}
25+
read line: >>Content-Length: 284\r\n<<
26+
read line: >>\r\n<<
27+
Process json: {
28+
"arguments": {
29+
"__sessionId": "a5a37776-8a8f-48e6-b50f-c5ad276d0586",
30+
"args": "",
31+
"console": "integratedTerminal",
32+
"cwd": "X:\\vscode_example",
33+
"name": "PyDev Debug (Launch)",
34+
"program": "X:/vscode_example/robots.py",
35+
"request": "launch",
36+
"type": "PyDev"
37+
},
38+
"command": "launch",
39+
"seq": 2,
40+
"type": "request"
41+
}
42+
read line: >>Content-Length: 56\r\n<<
43+
Writing: {"request_seq": 2, "command": "launch", "type": "response", "seq": 2, "success": true}
44+
read line: >>\r\n<<
45+
Process json: {
46+
"arguments": {},
47+
"command": "configurationDone",
48+
"seq": 3,
49+
"type": "request"
50+
}
51+
read line: >>Content-Length: 46\r\n<<
52+
Writing: {"request_seq": 3, "command": "configurationDone", "type": "response", "seq": 3, "success": true}
53+
read line: >>\r\n<<
54+
Process json: {
55+
"command": "threads",
56+
"seq": 4,
57+
"type": "request"
58+
}
59+
Writing: {"request_seq": 4, "body": {"threads": [{"id": 0, "name": "Main Thread"}, {"id": 1, "name": "Thread 1"}]}, "success": true, "seq": 4, "command": "threads", "type": "response"}
60+
read line: >>Content-Length: 79\r\n<<
61+
read line: >>\r\n<<
62+
Process json: {
63+
"arguments": {
64+
"restart": false
65+
},
66+
"command": "disconnect",
67+
"seq": 5,
68+
"type": "request"
69+
}
70+
Writing: {"request_seq": 5, "command": "disconnect", "type": "response", "seq": 5, "success": true}

part1/debugger/debug_adapter/__init__.py

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class BaseSchema(object):
2+
3+
def to_json(self):
4+
import json
5+
return json.dumps(self.to_dict())
6+
7+
8+
requests_to_types = {}
9+
all_messages = {}
10+
11+
12+
def register(cls):
13+
all_messages[cls.__name__] = cls
14+
return cls
15+
16+
17+
def register_request(request_command):
18+
19+
def do_register(cls):
20+
requests_to_types[request_command] = cls
21+
return cls
22+
23+
return do_register
24+
25+
26+
def from_dict(dct):
27+
msg_type = dct.get('type')
28+
if msg_type is None:
29+
raise ValueError('Unable to make sense of message: %s' % (dct,))
30+
if msg_type == 'request':
31+
cls = requests_to_types[dct['command']]
32+
return cls(**dct)
33+
34+
35+
def from_json(json_msg):
36+
import json
37+
return from_dict(json.loads(json_msg))
38+
39+
40+
def build_response(request, kwargs=None):
41+
if kwargs is None:
42+
kwargs = {}
43+
name = request.__class__.__name__
44+
assert name.endswith('Request')
45+
name = name[:-7] + 'Response'
46+
response_class = all_messages[name]
47+
kwargs.setdefault('seq', -1)
48+
return response_class(command=request.command, request_seq=request.seq, success=True, **kwargs)
49+

0 commit comments

Comments
 (0)