Skip to content

Commit 4cbd211

Browse files
committed
working with path insert
1 parent 6428b25 commit 4cbd211

File tree

8 files changed

+97
-84
lines changed

8 files changed

+97
-84
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/bash
2+
# Bash script
3+
python $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@
4+
echo "Executed: python $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
:: Bat script
3+
python %BUNDLED_DEBUGPY_PATH% --listen 0 --wait-for-client %*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Fish script
2+
python $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $argv
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# PowerShell script
2+
python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args

debugpy

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/extension/configlessDebugInit.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/extension/extensionInit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +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';
56+
import { registerConfiglessDebug } from './noConfigDebugInit';
5757

5858
export async function registerDebugger(context: IExtensionContext): Promise<IExtensionApi> {
5959
const childProcessAttachService = new ChildProcessAttachService();

src/extension/noConfigDebugInit.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
/**
7+
* Registers the configuration-less debugging setup for the extension.
8+
*
9+
* This function sets up environment variables and a file system watcher to
10+
* facilitate debugging without requiring a pre-configured launch.json file.
11+
*
12+
* @param context - The extension context which provides access to the environment variable collection and subscriptions.
13+
*
14+
* Environment Variables:
15+
* - `DEBUGPY_ADAPTER_ENDPOINTS`: Path to the file containing the debugger adapter endpoint.
16+
* - `BUNDLED_DEBUGPY_PATH`: Path to the bundled debugpy library.
17+
* - `PATH`: Appends the path to the noConfigScripts directory.
18+
*/
19+
export async function registerConfiglessDebug(context: IExtensionContext): Promise<void> {
20+
const collection = context.environmentVariableCollection;
21+
22+
// Add env vars for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH
23+
const debugAdapterEndpointDir = path.join(context.extensionPath, 'noConfigDebugAdapterEndpoints');
24+
const debuggerAdapterEndpointPath = path.join(debugAdapterEndpointDir, 'debuggerAdapterEndpoint.txt');
25+
collection.replace('DEBUGPY_ADAPTER_ENDPOINTS', debuggerAdapterEndpointPath);
26+
27+
const noConfigScriptsDir = path.join(context.extensionPath, 'bundled/scripts/noConfigScripts');
28+
collection.append('PATH', `:${noConfigScriptsDir}`);
29+
30+
const bundledDebugPath = path.join(context.extensionPath, 'bundled/libs/debugpy');
31+
collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath);
32+
33+
// create file system watcher for the debuggerAdapterEndpointFolder for when the communication port is written
34+
context.subscriptions.push(
35+
workspace.createFileSystemWatcher(new RelativePattern(debugAdapterEndpointDir, '**/*')).onDidCreate((uri) => {
36+
console.log(`File created: ${uri.fsPath}`);
37+
const filePath = uri.fsPath;
38+
fs.readFile(filePath, 'utf8', (err, data) => {
39+
if (err) {
40+
console.error(`Error reading file: ${err}`);
41+
return;
42+
}
43+
try {
44+
// parse the client port
45+
const jsonData = JSON.parse(data);
46+
const clientPort = jsonData.client?.port;
47+
console.log(`Client port: ${clientPort}`);
48+
49+
const options: DebugSessionOptions = {
50+
noDebug: false,
51+
};
52+
53+
// start debug session with the client port
54+
debug
55+
.startDebugging(
56+
undefined,
57+
{
58+
type: 'python',
59+
request: 'attach',
60+
name: 'Attach to Python',
61+
port: clientPort,
62+
host: 'localhost',
63+
},
64+
options,
65+
)
66+
.then(
67+
(started) => {
68+
if (started) {
69+
console.log('Debug session started successfully');
70+
} else {
71+
console.error('Failed to start debug session');
72+
}
73+
},
74+
(error) => {
75+
console.error(`Error starting debug session: ${error}`);
76+
},
77+
);
78+
} catch (parseErr) {
79+
console.error(`Error parsing JSON: ${parseErr}`);
80+
}
81+
});
82+
JSON.parse;
83+
}),
84+
);
85+
}

0 commit comments

Comments
 (0)