From 3f4a45e48e68152af00754a6fd4d1cadfab76cf8 Mon Sep 17 00:00:00 2001 From: JackN Date: Mon, 5 Feb 2024 13:26:41 -0500 Subject: [PATCH 1/3] Assign default `cwd` correctly. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aa7602a..d4b1a01 100644 --- a/package.json +++ b/package.json @@ -549,4 +549,4 @@ } ] } -} +} \ No newline at end of file From 1dacdb288e5510791e161c0f6984ccd7db37a4ca Mon Sep 17 00:00:00 2001 From: JackN Date: Mon, 5 Feb 2024 13:31:07 -0500 Subject: [PATCH 2/3] Fix prettier --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d4b1a01..aa7602a 100644 --- a/package.json +++ b/package.json @@ -549,4 +549,4 @@ } ] } -} \ No newline at end of file +} From 75725e8423ed3acc26c2298067e61416321a7bbf Mon Sep 17 00:00:00 2001 From: JackN Date: Tue, 6 Feb 2024 12:07:47 -0500 Subject: [PATCH 3/3] Add DebugConfigurationProvider for configuration defaults --- package.json | 2 +- src/extension.ts | 90 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index aa7602a..f73763e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "probe-rs-debugger", "displayName": "Debugger for probe-rs", - "version": "0.22.3", + "version": "0.22.4", "publisher": "probe-rs", "description": "probe-rs Debug Adapter for VS Code.", "author": { diff --git a/src/extension.ts b/src/extension.ts index d126e56..ca793ef 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,13 +9,23 @@ import {existsSync} from 'fs'; import getPort from 'get-port'; import * as os from 'os'; import * as vscode from 'vscode'; -import {DebugAdapterTracker, DebugAdapterTrackerFactory} from 'vscode'; +import { + CancellationToken, + DebugAdapterTracker, + DebugAdapterTrackerFactory, + DebugConfiguration, + DebugConfigurationProvider, + ProviderResult, + WorkspaceFolder, +} from 'vscode'; export async function activate(context: vscode.ExtensionContext) { const descriptorFactory = new ProbeRSDebugAdapterServerDescriptorFactory(); + const configProvider = new ProbeRSConfigurationProvider(); context.subscriptions.push( vscode.debug.registerDebugAdapterDescriptorFactory('probe-rs-debug', descriptorFactory), + vscode.debug.registerDebugConfigurationProvider('probe-rs-debug', configProvider), vscode.debug.onDidReceiveDebugSessionCustomEvent( descriptorFactory.receivedCustomEvent.bind(descriptorFactory), ), @@ -296,7 +306,26 @@ class ProbeRSDebugAdapterServerDescriptorFactory implements vscode.DebugAdapterD } var debuggerStatus: DebuggerStatus = DebuggerStatus.starting; - var debugServer = new String('127.0.0.1:50000').split(':', 2); // ... provide default server host and port for "launch" configurations, where this is NOT a mandatory config + //Provide default server host and port for "launch" configurations, where this is NOT a mandatory config + var debugServer = new String('127.0.0.1:50000').split(':', 2); + + // Validate that the `cwd` folder exists. + if (!existsSync(session.configuration.cwd)) { + logToConsole( + `${ + ConsoleLogSources.error + }: ${ConsoleLogSources.console.toLowerCase()}: The 'cwd' folder does not exist: ${JSON.stringify( + session.configuration.cwd, + null, + 2, + )}`, + ); + vscode.window.showErrorMessage( + `The 'cwd' folder does not exist: ${JSON.stringify(session.configuration.cwd, null, 2)}`, + ); + return undefined; + } + if (session.configuration.hasOwnProperty('server')) { debugServer = new String(session.configuration.server).split(':', 2); logToConsole( @@ -309,31 +338,6 @@ class ProbeRSDebugAdapterServerDescriptorFactory implements vscode.DebugAdapterD ); debuggerStatus = DebuggerStatus.running; // If this is not true as expected, then the user will be notified later. } else { - // Assign the default `cwd` for the project. - if (!session.configuration.hasOwnProperty('cwd')) { - session.configuration.cwd = session.workspaceFolder?.uri.fsPath; - } - - // Validate that the `cwd` folder exists. - if (!existsSync(session.configuration.cwd)) { - logToConsole( - `${ - ConsoleLogSources.error - }: ${ConsoleLogSources.console.toLowerCase()}: The 'cwd' folder does not exist: ${JSON.stringify( - session.configuration.cwd, - null, - 2, - )}`, - ); - vscode.window.showErrorMessage( - `The 'cwd' folder does not exist: ${JSON.stringify( - session.configuration.cwd, - null, - 2, - )}`, - ); - return undefined; - } // Find and use the first available port and spawn a new probe-rs dap-server process try { var port: number = await getPort(); @@ -565,6 +569,38 @@ class ProbeRsDebugAdapterTrackerFactory implements DebugAdapterTrackerFactory { } } +class ProbeRSConfigurationProvider implements DebugConfigurationProvider { + /** + * Ensure the provided configuration has the essential defaults applied. + */ + resolveDebugConfiguration( + folder: WorkspaceFolder | undefined, + config: DebugConfiguration, + token?: CancellationToken, + ): ProviderResult { + // TODO: Once we can detect the chip, we can probably provide a working config from defauts. + // if launch.json is missing or empty + // if (!config.type && !config.request && !config.name) { + // const editor = vscode.window.activeTextEditor; + // if (editor && editor.document.languageId === 'rust') { + // config.type = 'probe-rs-debug'; + // config.name = 'Launch'; + // config.request = 'launch'; + // ... + // } + // } + + // Assign the default `cwd` for the project. + // TODO: We can update probe-rs dap-server to provide defaults that we can fill in here, + // and ensure the extension defaults are consistent with those of the server. + if (!config.cwd) { + config.cwd = '${workspaceFolder}'; + } + + return config; + } +} + class ProbeRsDebugAdapterTracker implements DebugAdapterTracker { onWillReceiveMessage(message: any) { if (consoleLogLevel === toCamelCase(ConsoleLogSources.debug)) {