Skip to content

Commit 6428b25

Browse files
committed
working experience minus PATH
1 parent ae70322 commit 6428b25

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

debugpy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /bin/bash
2+
python /Users/eleanorboyd/vscode-python-debugger/bundled/libs/debugpy --listen 0 --wait-for-client $@

script_tester_configless.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
if __name__ == "__main__":
2+
print("Hello, World!")
3+
import sys
4+
import os
5+
import json
6+
7+
print(os.environ["DEBUGPY_ADAPTER_ENDPOINTS"])
8+
file_path = "/Users/eleanorboyd/vscode-python-debugger/comms-file.txt"
9+
if os.path.exists(file_path):
10+
with open(file_path, "r") as file:
11+
print("FILE CONTENTS: \n")
12+
contents = file.read()
13+
c_thing = json.loads(contents)
14+
if c_thing.get("client"):
15+
# print("CLIENT: ", c_thing["client"])
16+
if c_thing.get("client").get("port"):
17+
print("Port: ", c_thing.get("client").get("port"))
18+
# print(contents)
19+
else:
20+
print(f"{file_path} does not exist.")

src/extension/configlessDebugInit.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
import { IExtensionContext } from './common/types';
4+
import { DebugSessionOptions, debug, RelativePattern, workspace } from 'vscode';
5+
6+
const PATH_VARIABLE = 'PATH';
7+
8+
export async function registerConfiglessDebug(context: IExtensionContext): Promise<void> {
9+
const collection = context.environmentVariableCollection;
10+
// constants
11+
const debuggerAdapterEndpointFolderPath = path.join(context.extensionPath, 'src/extension/configlessCommunication');
12+
const debuggerAdapterEndpointPath = path.join(debuggerAdapterEndpointFolderPath, 'debuggerAdapterEndpoint.txt');
13+
14+
// Add env vars for DEBUGPY_ADAPTER_ENDPOINTS and PATH
15+
collection.replace('DEBUGPY_ADAPTER_ENDPOINTS', debuggerAdapterEndpointPath);
16+
// TODO: append for path
17+
18+
// const pathVariableChange = path.delimiter + '/Users/eleanorboyd/vscode-python-debugger';
19+
// if (context.environmentVariableCollection.get(PATH_VARIABLE)) {
20+
// context.environmentVariableCollection.delete(PATH_VARIABLE);
21+
// } else if (context.environmentVariableCollection.get(PATH_VARIABLE)?.value !== pathVariableChange) {
22+
// context.environmentVariableCollection.description = 'enable config-less debug';
23+
// context.environmentVariableCollection.delete(PATH_VARIABLE);
24+
// context.environmentVariableCollection.append(PATH_VARIABLE, pathVariableChange);
25+
// }
26+
27+
// create file system watcher for the debuggerAdapterEndpointFolder for when the communication port is written
28+
context.subscriptions.push(
29+
workspace
30+
.createFileSystemWatcher(new RelativePattern(debuggerAdapterEndpointFolderPath, '**/*'))
31+
.onDidCreate((uri) => {
32+
console.log(`File created: ${uri.fsPath}`);
33+
const filePath = uri.fsPath;
34+
fs.readFile(filePath, 'utf8', (err, data) => {
35+
if (err) {
36+
console.error(`Error reading file: ${err}`);
37+
return;
38+
}
39+
try {
40+
// parse the client port
41+
const jsonData = JSON.parse(data);
42+
const clientPort = jsonData.client?.port;
43+
console.log(`Client port: ${clientPort}`);
44+
45+
const options: DebugSessionOptions = {
46+
noDebug: false,
47+
};
48+
49+
// start debug session with the client port
50+
debug
51+
.startDebugging(
52+
undefined,
53+
{
54+
type: 'python',
55+
request: 'attach',
56+
name: 'Attach to Python',
57+
port: clientPort,
58+
host: 'localhost',
59+
},
60+
options,
61+
)
62+
.then(
63+
(started) => {
64+
if (started) {
65+
console.log('Debug session started successfully');
66+
} else {
67+
console.error('Failed to start debug session');
68+
}
69+
},
70+
(error) => {
71+
console.error(`Error starting debug session: ${error}`);
72+
},
73+
);
74+
} catch (parseErr) {
75+
console.error(`Error parsing JSON: ${parseErr}`);
76+
}
77+
});
78+
JSON.parse;
79+
}),
80+
);
81+
}

src/extension/extensionInit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { IExtensionApi } from './apiTypes';
5353
import { registerHexDebugVisualizationTreeProvider } from './debugger/visualizers/inlineHexDecoder';
5454
import { PythonInlineValueProvider } from './debugger/inlineValue/pythonInlineValueProvider';
5555
import { traceLog } from './common/log/logging';
56+
import { registerConfiglessDebug } from './configlessDebugInit';
5657

5758
export async function registerDebugger(context: IExtensionContext): Promise<IExtensionApi> {
5859
const childProcessAttachService = new ChildProcessAttachService();
@@ -247,5 +248,7 @@ export async function registerDebugger(context: IExtensionContext): Promise<IExt
247248
window.activeTextEditor?.document.languageId === 'python',
248249
);
249250

251+
registerConfiglessDebug(context);
252+
250253
return buildApi();
251254
}

0 commit comments

Comments
 (0)