Skip to content

Commit d6b6554

Browse files
fix set target preview targets (#1652)
* fix set target preview targets * add types for quick pick items * fix show set target output * add openocd empty board validation ignore for linux
1 parent 2565fd8 commit d6b6554

File tree

6 files changed

+85
-41
lines changed

6 files changed

+85
-41
lines changed

src/cdtDebugAdapter/debugConfProvider.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ export class CDTDebugConfigurationProvider
110110
| "esp32c3"
111111
| "esp32c6"
112112
| "esp32h2"
113-
| "esp32p4";
113+
| "esp32p4"
114+
| "esp32c4"
115+
| "esp32c5"
116+
| "esp32c61";
114117
// Mapping of idfTarget to corresponding CPU watchpoint numbers
115118
const idfTargetWatchpointMap: Record<IdfTarget, number> = {
116119
esp32: 2,
@@ -121,11 +124,14 @@ export class CDTDebugConfigurationProvider
121124
esp32c6: 4,
122125
esp32h2: 4,
123126
esp32p4: 3,
127+
esp32c4: 2,
128+
esp32c5: 4,
129+
esp32c61: 4,
124130
};
125131
config.initCommands = config.initCommands.map((cmd: string) =>
126132
cmd.replace(
127133
"{IDF_TARGET_CPU_WATCHPOINT_NUM}",
128-
idfTargetWatchpointMap[idfTarget]
134+
idfTargetWatchpointMap[idfTarget] || 2
129135
)
130136
);
131137
}

src/espIdf/openOcd/boardConfiguration.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,26 @@ export async function selectOpenOcdConfigFiles(
124124
return;
125125
}
126126
}
127+
if (idfTarget === "linux") {
128+
return;
129+
}
127130
const currentOpenOcdConfigs = readParameter(
128131
"idf.openOcdConfigs",
129132
workspaceFolder
130133
) as string[];
131134
const boards = await getBoards(openOcdScriptsPath, idfTarget);
135+
const message = l10n.t(
136+
"No OpenOCD boards found for target {target}. Please check your OPENOCD_SCRIPTS environment variable.",
137+
{ target: idfTarget }
138+
);
139+
if (!boards || boards.length === 0) {
140+
Logger.errorNotify(
141+
message,
142+
new Error(message),
143+
"boardConfiguration selectOpenOcdConfigFiles"
144+
);
145+
return;
146+
}
132147
const choices = boards.map((b) => {
133148
return {
134149
description: `${b.description} (${b.configFiles})`,

src/espIdf/setTarget/index.ts

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,25 @@ import {
3434
import { Logger } from "../../logger/logger";
3535
import { OutputChannel } from "../../logger/outputChannel";
3636
import { selectOpenOcdConfigFiles } from "../openOcd/boardConfiguration";
37-
import { getTargetsFromEspIdf } from "./getTargets";
37+
import { getTargetsFromEspIdf, IdfTarget } from "./getTargets";
3838
import { setTargetInIDF } from "./setTargetInIdf";
3939
import { updateCurrentProfileIdfTarget } from "../../project-conf";
4040
import { DevkitsCommand } from "./DevkitsCommand";
4141

4242
export let isSettingIDFTarget = false;
4343

44+
export interface ISetTargetQuickPickItems {
45+
label: string;
46+
idfTarget?: IdfTarget;
47+
boardInfo?: {
48+
location: string;
49+
config_files: string[];
50+
};
51+
description?: string;
52+
isConnected?: boolean;
53+
kind?: QuickPickItemKind;
54+
}
55+
4456
export async function setIdfTarget(
4557
placeHolderMsg: string,
4658
workspaceFolder: WorkspaceFolder
@@ -73,30 +85,35 @@ export async function setIdfTarget(
7385
async (progress: Progress<{ message: string; increment: number }>) => {
7486
try {
7587
const targetsFromIdf = await getTargetsFromEspIdf(workspaceFolder.uri);
76-
let connectedBoards: any[] = [];
88+
let connectedBoards: ISetTargetQuickPickItems[] = [];
7789

7890
const isDebugging = debug.activeDebugSession !== undefined;
7991

8092
if (!isDebugging) {
8193
try {
8294
const devkitsCmd = new DevkitsCommand(workspaceFolder.uri);
8395
const scriptPath = await devkitsCmd.getScriptPath();
84-
96+
8597
if (scriptPath) {
8698
const devkitsOutput = await devkitsCmd.runDevkitsScript();
8799
if (devkitsOutput) {
88100
const parsed = JSON.parse(devkitsOutput);
89101
if (parsed && Array.isArray(parsed.boards)) {
90-
connectedBoards = parsed.boards.map((b: any) => ({
91-
label: b.name,
92-
target: b.target,
93-
description: b.description,
94-
detail: `Status: CONNECTED${
95-
b.location ? ` Location: ${b.location}` : ""
96-
}`,
97-
isConnected: true,
98-
boardInfo: b,
99-
}));
102+
connectedBoards = parsed.boards.map(
103+
(b: any) =>
104+
({
105+
label: b.name,
106+
idfTarget: targetsFromIdf.find(
107+
(t) => t.target === b.target
108+
),
109+
description: b.description,
110+
detail: `Status: CONNECTED${
111+
b.location ? ` Location: ${b.location}` : ""
112+
}`,
113+
isConnected: true,
114+
boardInfo: b,
115+
} as ISetTargetQuickPickItems)
116+
);
100117
}
101118
}
102119
} else {
@@ -115,26 +132,24 @@ export async function setIdfTarget(
115132
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually."
116133
);
117134
}
118-
let quickPickItems: any[] = [];
119-
if (connectedBoards.length > 0) {
120-
quickPickItems = [
121-
...connectedBoards,
122-
{ kind: QuickPickItemKind.Separator, label: "Default Boards" },
123-
...targetsFromIdf.map((t) => ({
124-
label: t.label,
125-
target: t.target,
126-
description: t.isPreview ? "Preview target" : undefined,
127-
isConnected: false,
128-
})),
129-
];
130-
} else {
131-
quickPickItems = targetsFromIdf.map((t) => ({
135+
let quickPickItems: ISetTargetQuickPickItems[] = [];
136+
const defaultBoards: ISetTargetQuickPickItems[] = targetsFromIdf.map(
137+
(t) => ({
132138
label: t.label,
133-
target: t.target,
139+
idfTarget: t,
134140
description: t.isPreview ? "Preview target" : undefined,
135141
isConnected: false,
136-
}));
137-
}
142+
})
143+
);
144+
145+
quickPickItems =
146+
connectedBoards.length > 0
147+
? [
148+
...connectedBoards,
149+
{ kind: QuickPickItemKind.Separator, label: "Default Boards" },
150+
...defaultBoards,
151+
]
152+
: defaultBoards;
138153
const selectedTarget = await window.showQuickPick(quickPickItems, {
139154
placeHolder: placeHolderMsg,
140155
});
@@ -171,24 +186,24 @@ export async function setIdfTarget(
171186
} else {
172187
await selectOpenOcdConfigFiles(
173188
workspaceFolder.uri,
174-
selectedTarget.target
189+
selectedTarget.idfTarget.target
175190
);
176191
}
177192

178-
await setTargetInIDF(workspaceFolder, selectedTarget);
193+
await setTargetInIDF(workspaceFolder, selectedTarget.idfTarget);
179194
const customExtraVars = readParameter(
180195
"idf.customExtraVars",
181196
workspaceFolder
182197
) as { [key: string]: string };
183-
customExtraVars["IDF_TARGET"] = selectedTarget.target;
198+
customExtraVars["IDF_TARGET"] = selectedTarget.idfTarget.target;
184199
await writeParameter(
185200
"idf.customExtraVars",
186201
customExtraVars,
187202
configurationTarget,
188203
workspaceFolder.uri
189204
);
190205
await updateCurrentProfileIdfTarget(
191-
selectedTarget.target,
206+
selectedTarget.idfTarget.target,
192207
workspaceFolder.uri
193208
);
194209
} catch (err) {

src/espIdf/setTarget/setTargetInIdf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export async function setTargetInIDF(
7979
const setTargetResult = await spawn(pythonBinPath, setTargetArgs, {
8080
cwd: workspaceFolder.uri.fsPath,
8181
env: modifiedEnv,
82+
silent: false,
8283
});
8384
Logger.info(setTargetResult.toString());
8485
const msg = vscode.l10n.t(

src/statusBar/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
Uri,
2727
window,
2828
l10n,
29+
ThemeIcon,
2930
} from "vscode";
3031
import { getCurrentIdfSetup } from "../versionSwitcher";
3132
import { readParameter } from "../idfConfiguration";
@@ -277,7 +278,9 @@ export function updateHintsStatusBarItem(hasHints: boolean) {
277278
statusBarItems["hints"].tooltip = l10n.t(
278279
"ESP-IDF: Hints available. Click to view."
279280
);
280-
statusBarItems["hints"].backgroundColor = "statusBarItem.warningBackground";
281+
statusBarItems["hints"].backgroundColor = new ThemeIcon(
282+
"statusBarItem.warningBackground"
283+
);
281284
statusBarItems["hints"].show();
282285
} else {
283286
statusBarItems["hints"].hide();

src/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,21 @@ export interface ISpawnOptions extends childProcess.SpawnOptions {
173173
export function spawn(
174174
command: string,
175175
args: string[] = [],
176-
options: ISpawnOptions = { outputString: "", silent: true }
176+
options: ISpawnOptions = {
177+
outputString: "",
178+
silent: false,
179+
appendMode: "appendLine",
180+
}
177181
): Promise<Buffer> {
178182
let buff = Buffer.alloc(0);
179183
const sendToOutputChannel = (data: Buffer) => {
180184
buff = Buffer.concat([buff, data]);
181185
options.outputString += buff.toString();
182186
if (!options.silent) {
183-
if (options.appendMode === "appendLine") {
184-
OutputChannel.appendLine(data.toString());
185-
} else if (options.appendMode === "append") {
187+
if (options.appendMode === "append") {
186188
OutputChannel.append(data.toString());
189+
} else {
190+
OutputChannel.appendLine(data.toString());
187191
}
188192
}
189193
};

0 commit comments

Comments
 (0)