-
Notifications
You must be signed in to change notification settings - Fork 61
Configless debug #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Configless debug #557
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a5b2355
working experience minus PATH
eleanorjboyd 4e636da
working with path insert
eleanorjboyd 0809f40
add test
eleanorjboyd 1d36b7a
switch to trace logging, add final test
eleanorjboyd fa4c53d
make scripts executable
eleanorjboyd 58600b1
fix paths and path sep
eleanorjboyd d0ff6c5
add folder and fix debugpy path
eleanorjboyd d7a8695
minor edits
eleanorjboyd 54dfc07
add mit license
eleanorjboyd 51edcaf
suggested fixes
eleanorjboyd ea77f6c
additional fix
eleanorjboyd 5c23abb
updates based on comments feedback
eleanorjboyd 49fb265
remove initial endpoint design
eleanorjboyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#! /bin/bash | ||
# Bash script | ||
python $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@ | ||
echo "Executed: python $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
:: Bat script | ||
python %BUNDLED_DEBUGPY_PATH% --listen 0 --wait-for-client %* | ||
eleanorjboyd marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Fish script | ||
python $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $argv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# PowerShell script | ||
python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
eleanorjboyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Licensed under the MIT License. | ||
|
||
This folder is necessary as it is the location where the debug adapter | ||
will create the debuggerAdapterEndpoint.txt to communicate the endpoint. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { IExtensionContext } from './common/types'; | ||
import { DebugSessionOptions, RelativePattern } from 'vscode'; | ||
import { createFileSystemWatcher, debugStartDebugging } from './utils'; | ||
import { traceError, traceVerbose } from './common/log/logging'; | ||
|
||
/** | ||
* Registers the configuration-less debugging setup for the extension. | ||
* | ||
* This function sets up environment variables and a file system watcher to | ||
* facilitate debugging without requiring a pre-configured launch.json file. | ||
* | ||
* @param context - The extension context which provides access to the environment variable collection and subscriptions. | ||
* | ||
* Environment Variables: | ||
* - `DEBUGPY_ADAPTER_ENDPOINTS`: Path to the file containing the debugger adapter endpoint. | ||
* - `BUNDLED_DEBUGPY_PATH`: Path to the bundled debugpy library. | ||
* - `PATH`: Appends the path to the noConfigScripts directory. | ||
*/ | ||
export async function registerNoConfigDebug(context: IExtensionContext): Promise<void> { | ||
eleanorjboyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const collection = context.environmentVariableCollection; | ||
|
||
// Add env vars for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH | ||
const debugAdapterEndpointDir = path.join(context.extensionPath, 'noConfigDebugAdapterEndpoints'); | ||
const debuggerAdapterEndpointPath = path.join(debugAdapterEndpointDir, 'debuggerAdapterEndpoint.txt'); | ||
collection.replace('DEBUGPY_ADAPTER_ENDPOINTS', debuggerAdapterEndpointPath); | ||
|
||
const noConfigScriptsDir = path.join(context.extensionPath, 'bundled', 'scripts', 'noConfigScripts'); | ||
const pathSeparator = process.platform === 'win32' ? ';' : ':'; | ||
collection.append('PATH', `${pathSeparator}${noConfigScriptsDir}`); | ||
|
||
const bundledDebugPath = path.join(context.extensionPath, 'bundled', 'libs', 'debugpy'); | ||
collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath); | ||
|
||
// create file system watcher for the debuggerAdapterEndpointFolder for when the communication port is written | ||
const fileSystemWatcher = createFileSystemWatcher(new RelativePattern(debugAdapterEndpointDir, '**/*')); | ||
const fileCreationEvent = fileSystemWatcher.onDidCreate(async (uri) => { | ||
const filePath = uri.fsPath; | ||
fs.readFile(filePath, (err, data) => { | ||
const dataParse = data.toString(); | ||
if (err) { | ||
traceError(`Error reading debuggerAdapterEndpoint.txt file: ${err}`); | ||
return; | ||
} | ||
try { | ||
// parse the client port | ||
const jsonData = JSON.parse(dataParse); | ||
const clientPort = jsonData.client?.port; | ||
traceVerbose(`Parsed client port: ${clientPort}`); | ||
|
||
const options: DebugSessionOptions = { | ||
noDebug: false, | ||
}; | ||
|
||
// start debug session with the client port | ||
debugStartDebugging( | ||
undefined, | ||
{ | ||
type: 'python', | ||
request: 'attach', | ||
name: 'Attach to Python', | ||
connect: { | ||
port: clientPort, | ||
host: 'localhost', | ||
}, | ||
}, | ||
options, | ||
).then( | ||
(started) => { | ||
if (started) { | ||
traceVerbose('Successfully started debug session'); | ||
} else { | ||
traceError('Error starting debug session, session not started.'); | ||
} | ||
}, | ||
(error) => { | ||
traceError(`Error starting debug session: ${error}`); | ||
}, | ||
); | ||
} catch (parseErr) { | ||
traceError(`Error parsing JSON: ${parseErr}`); | ||
} | ||
}); | ||
JSON.parse; | ||
}); | ||
context.subscriptions.push(fileCreationEvent); | ||
context.subscriptions.push(fileSystemWatcher); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
workspace, | ||
debug, | ||
WorkspaceFolder, | ||
DebugConfiguration, | ||
DebugSession, | ||
DebugSessionOptions, | ||
FileSystemWatcher, | ||
} from 'vscode'; | ||
|
||
export function createFileSystemWatcher(args: any): FileSystemWatcher { | ||
return workspace.createFileSystemWatcher(args); | ||
} | ||
|
||
export async function debugStartDebugging( | ||
folder: WorkspaceFolder | undefined, | ||
nameOrConfiguration: string | DebugConfiguration, | ||
parentSessionOrOptions?: DebugSession | DebugSessionOptions, | ||
): Promise<boolean> { | ||
return debug.startDebugging(folder, nameOrConfiguration, parentSessionOrOptions); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.