Skip to content

Commit

Permalink
Merge pull request #161 from satabol/fix_0001_Append_a_setting_justMy…
Browse files Browse the repository at this point in the history
…Code_to_the_list_of_Addon_settings

Add a `justMyCode` setting to support better debugging when using additional libraries in an addon.
  • Loading branch information
JacquesLucke committed May 1, 2024
2 parents c49972f + 7ce897b commit 6786cb4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Added
- New `blender.addon.justMyCode` option. True (On) - allow debug a user python code of addon only. False (Off) - allow debug a user python code of addon and external libraries code too. Restart Blender debug session after switch this option.

## [0.0.19] - 2023-12-05

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
"default": false,
"description": "Reload addon in Blender when a document is saved."
},
"blender.addon.justMyCode": {
"type": "boolean",
"scope": "resource",
"default": true,
"description": "True - debug addon code only, False - allow debug external python library code."
},
"blender.addon.buildTaskName": {
"type": "string",
"scope": "resource",
Expand Down
3 changes: 1 addition & 2 deletions pythonFiles/include/blender_vscode/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def start_debug_server():
pass
return port


# Server
#########################################

Expand Down Expand Up @@ -105,7 +104,7 @@ def send_connection_information(path_mappings):
"debugpyPort" : DEBUGPY_PORT,
"blenderPath" : str(blender_path),
"scriptsFolder" : str(scripts_folder),
"addonPathMappings" : path_mappings,
"addonPathMappings" : path_mappings
})

def send_dict_as_json(data):
Expand Down
4 changes: 4 additions & 0 deletions src/addon_folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class AddonWorkspaceFolder {
return <boolean>this.getConfig().get('addon.reloadOnSave');
}

get justMyCode() {
return <boolean>this.getConfig().get('addon.justMyCode');
}

public async hasAddonEntryPoint() {
try {
let sourceDir = await this.getSourceDirectory();
Expand Down
11 changes: 8 additions & 3 deletions src/communication.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as http from 'http';
import * as vscode from 'vscode';
import * as request from 'request';
import { getConfig } from './utils';
import { attachPythonDebuggerToBlender } from './python_debugging';

const RESPONSIVE_LIMIT_MS = 1000;
Expand All @@ -14,15 +15,17 @@ export type AddonPathMapping = { src: string, load: string };
export class BlenderInstance {
blenderPort: number;
debugpyPort: number;
justMyCode: boolean;
path: string;
scriptsFolder: string;
addonPathMappings: AddonPathMapping[];
connectionErrors: Error[];

constructor(blenderPort: number, debugpyPort: number, path: string,
constructor(blenderPort: number, debugpyPort: number, justMyCode: boolean, path: string,
scriptsFolder: string, addonPathMappings: AddonPathMapping[]) {
this.blenderPort = blenderPort;
this.debugpyPort = debugpyPort;
this.justMyCode = justMyCode;
this.path = path;
this.scriptsFolder = scriptsFolder;
this.addonPathMappings = addonPathMappings;
Expand All @@ -49,7 +52,7 @@ export class BlenderInstance {
}

attachDebugger() {
attachPythonDebuggerToBlender(this.debugpyPort, this.path, this.scriptsFolder, this.addonPathMappings);
attachPythonDebuggerToBlender(this.debugpyPort, this.path, this.justMyCode, this.scriptsFolder, this.addonPathMappings);
}

get address() {
Expand Down Expand Up @@ -130,7 +133,9 @@ function SERVER_handleRequest(request: any, response: any) {

switch (req.type) {
case 'setup': {
let instance = new BlenderInstance(req.blenderPort, req.debugpyPort, req.blenderPath, req.scriptsFolder, req.addonPathMappings);
let config = getConfig();
let justMyCode: boolean = <boolean>config.get('addon.justMyCode')
let instance = new BlenderInstance(req.blenderPort, req.debugpyPort, justMyCode, req.blenderPath, req.scriptsFolder, req.addonPathMappings);
instance.attachDebugger();
RunningBlenders.register(instance);
response.end('OK');
Expand Down
7 changes: 4 additions & 3 deletions src/python_debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import { AddonPathMapping } from './communication';
type PathMapping = { localRoot: string, remoteRoot: string };

export async function attachPythonDebuggerToBlender(
port: number, blenderPath: string, scriptsFolder: string,
port: number, blenderPath: string, justMyCode: boolean, scriptsFolder: string,
addonPathMappings: AddonPathMapping[]) {

let mappings = await getPythonPathMappings(scriptsFolder, addonPathMappings);
attachPythonDebugger(port, mappings);
attachPythonDebugger(port, justMyCode, mappings);
}

function attachPythonDebugger(port: number, pathMappings: PathMapping[] = []) {
function attachPythonDebugger(port: number, justMyCode: boolean, pathMappings: PathMapping[] = []) {
let configuration = {
name: `Python at Port ${port}`,
request: "attach",
type: 'python',
port: port,
host: 'localhost',
pathMappings: pathMappings,
justMyCode: justMyCode
};
vscode.debug.startDebugging(undefined, configuration);
}
Expand Down

0 comments on commit 6786cb4

Please sign in to comment.