Skip to content

Commit

Permalink
[VSC-1552] Resolve folder when using launch config from code-workspace (
Browse files Browse the repository at this point in the history
#1397)

* update env var collection resolve undefined folder

* add current workspace as global state
  • Loading branch information
brianignacio5 authored Feb 6, 2025
1 parent 2fe9b8d commit fbe6800
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cdtDebugAdapter/debugConfProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
CancellationToken,
DebugConfiguration,
DebugConfigurationProvider,
Uri,
WorkspaceFolder,
window,
workspace,
} from "vscode";
import { readParameter } from "../idfConfiguration";
import { getIdfTargetFromSdkconfig, getProjectName } from "../workspaceConfig";
Expand All @@ -31,6 +34,7 @@ import { OpenOCDManager } from "../espIdf/openOcd/openOcdManager";
import { Logger } from "../logger/logger";
import { getToolchainPath } from "../utils";
import { createNewIdfMonitor } from "../espIdf/monitor/command";
import { ESP } from "../config";

export class CDTDebugConfigurationProvider
implements DebugConfigurationProvider {
Expand All @@ -40,6 +44,20 @@ export class CDTDebugConfigurationProvider
token?: CancellationToken
): Promise<DebugConfiguration> {
try {
if (!folder) {
const workspaceFolderUri = ESP.GlobalConfiguration.store.get<Uri>(
ESP.GlobalConfiguration.SELECTED_WORKSPACE_FOLDER
);
folder = workspace.getWorkspaceFolder(workspaceFolderUri);
if (!folder) {
folder = await window.showWorkspaceFolderPick({
placeHolder: "Pick a workspace folder to start a debug session.",
});
if (!folder) {
throw new Error("No folder was selected to start debug session");
}
}
}
if (!config.program) {
const buildDirPath = readParameter("idf.buildPath", folder) as string;
const projectName = await getProjectName(buildDirPath);
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export namespace ESP {
export namespace GlobalConfiguration {
export let store: ExtensionConfigStore;
export const IDF_SETUPS = "IDF_SETUPS";
export const SELECTED_WORKSPACE_FOLDER = "SELECTED_WORKSPACE_FOLDER";
}

export const platformDepConfigurations: string[] = [
Expand Down
16 changes: 16 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ export async function activate(context: vscode.ExtensionContext) {
if (PreCheck.isWorkspaceFolderOpen()) {
await createCmdsStatusBarItems(vscode.workspace.workspaceFolders[0].uri);
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
ESP.GlobalConfiguration.store.set(
ESP.GlobalConfiguration.SELECTED_WORKSPACE_FOLDER,
workspaceRoot
);
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
if (statusBarItems && statusBarItems["port"]) {
statusBarItems["port"].text =
Expand Down Expand Up @@ -408,6 +412,10 @@ export async function activate(context: vscode.ExtensionContext) {
for (const ws of e.removed) {
if (workspaceRoot && ws.uri === workspaceRoot) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
ESP.GlobalConfiguration.store.set(
ESP.GlobalConfiguration.SELECTED_WORKSPACE_FOLDER,
workspaceRoot
);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
Expand Down Expand Up @@ -451,6 +459,10 @@ export async function activate(context: vscode.ExtensionContext) {
}
if (typeof workspaceRoot === undefined) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
ESP.GlobalConfiguration.store.set(
ESP.GlobalConfiguration.SELECTED_WORKSPACE_FOLDER,
workspaceRoot
);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
Expand Down Expand Up @@ -965,6 +977,10 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}
workspaceRoot = option.uri;
ESP.GlobalConfiguration.store.set(
ESP.GlobalConfiguration.SELECTED_WORKSPACE_FOLDER,
workspaceRoot
);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
Expand Down

0 comments on commit fbe6800

Please sign in to comment.