Skip to content

Commit 364a879

Browse files
committed
refactor: integrate hints status bar item with main status bar system
- Move hints status bar creation to createCmdsStatusBarItems function - Change id from "idfErrorHints" to "espIdf.errorHints" - Use "registerIDFCommand" instead of "vscode.commands.registerCommand"
1 parent 92dcc58 commit 364a879

File tree

3 files changed

+39
-62
lines changed

3 files changed

+39
-62
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@
312312
"views": {
313313
"espIdfHints": [
314314
{
315-
"id": "idfErrorHints",
315+
"id": "espIdf.errorHints",
316316
"name": "%view.idf.errorHints%",
317-
"title": "%view.idf.errorHints% ($idfErrorHints.count$)"
317+
"title": "%view.idf.errorHints% ($espIdf.errorHints.count$)"
318318
}
319319
],
320320
"debug": [
@@ -402,13 +402,13 @@
402402
"view/title": [
403403
{
404404
"command": "espIdf.errorHints.clearAll",
405-
"when": "view == idfErrorHints",
405+
"when": "view == espIdf.errorHints",
406406
"group": "navigation"
407407
},
408408
{
409409
"command": "espIdf.searchError",
410410
"group": "navigation",
411-
"when": "view == idfErrorHints"
411+
"when": "view == espIdf.errorHints"
412412
},
413413
{
414414
"command": "espIdf.partition.table.refresh",
@@ -458,11 +458,11 @@
458458
"view/item/context": [
459459
{
460460
"command": "espIdf.errorHints.clearBuildErrors",
461-
"when": "view == idfErrorHints && viewItem == buildError"
461+
"when": "view == espIdf.errorHints && viewItem == buildError"
462462
},
463463
{
464464
"command": "espIdf.errorHints.clearOpenOCDErrors",
465-
"when": "view == idfErrorHints && viewItem == openocdError"
465+
"when": "view == espIdf.errorHints && viewItem == openocdError"
466466
},
467467
{
468468
"command": "esp.rainmaker.backend.logout",

src/extension.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ import {
185185
} from "./cdtDebugAdapter/hexViewProvider";
186186
import { configureClangSettings } from "./clang";
187187
import { OpenOCDErrorMonitor } from "./espIdf/hints/openocdhint";
188-
import {
189-
createHintsStatusBarItem,
190-
updateHintsStatusBarItem,
191-
} from "./statusBar";
188+
import { updateHintsStatusBarItem } from "./statusBar";
192189

193190
// Global variables shared by commands
194191
let workspaceRoot: vscode.Uri;
@@ -3785,7 +3782,7 @@ export async function activate(context: vscode.ExtensionContext) {
37853782
if (PreCheck.isWorkspaceFolderOpen()) {
37863783
const treeDataProvider = new ErrorHintProvider(context);
37873784

3788-
const treeView = vscode.window.createTreeView("idfErrorHints", {
3785+
const treeView = vscode.window.createTreeView("espIdf.errorHints", {
37893786
treeDataProvider: treeDataProvider,
37903787
showCollapseAll: true,
37913788
});
@@ -3796,26 +3793,20 @@ export async function activate(context: vscode.ExtensionContext) {
37963793
context.subscriptions.push(treeView);
37973794

37983795
// Register commands for clearing error hints
3799-
vscode.commands.registerCommand("espIdf.errorHints.clearAll", () => {
3796+
registerIDFCommand("espIdf.errorHints.clearAll", () => {
38003797
treeDataProvider.clearErrorHints(true); // Clear both build and OpenOCD errors
38013798
updateHintsStatusBarItem(false);
38023799
});
38033800

3804-
vscode.commands.registerCommand(
3805-
"espIdf.errorHints.clearBuildErrors",
3806-
() => {
3807-
treeDataProvider.clearErrorHints(false); // Clear only build errors
3808-
updateHintsStatusBarItem(false);
3809-
}
3810-
);
3801+
registerIDFCommand("espIdf.errorHints.clearBuildErrors", () => {
3802+
treeDataProvider.clearErrorHints(false); // Clear only build errors
3803+
updateHintsStatusBarItem(false);
3804+
});
38113805

3812-
vscode.commands.registerCommand(
3813-
"espIdf.errorHints.clearOpenOCDErrors",
3814-
() => {
3815-
treeDataProvider.clearOpenOCDErrorsOnly(); // Clear only OpenOCD errors
3816-
updateHintsStatusBarItem(false);
3817-
}
3818-
);
3806+
registerIDFCommand("espIdf.errorHints.clearOpenOCDErrors", () => {
3807+
treeDataProvider.clearOpenOCDErrorsOnly(); // Clear only OpenOCD errors
3808+
updateHintsStatusBarItem(false);
3809+
});
38193810

38203811
const openOCDErrorMonitor = OpenOCDErrorMonitor.init(
38213812
treeDataProvider,
@@ -3831,13 +3822,13 @@ export async function activate(context: vscode.ExtensionContext) {
38313822
});
38323823

38333824
// Register command to manually search for errors
3834-
vscode.commands.registerCommand("espIdf.searchError", async () => {
3825+
registerIDFCommand("espIdf.searchError", async () => {
38353826
const errorMsg = await vscode.window.showInputBox({
38363827
placeHolder: "Enter the error message",
38373828
});
38383829
if (errorMsg) {
38393830
treeDataProvider.searchError(errorMsg, workspaceRoot);
3840-
await vscode.commands.executeCommand("idfErrorHints.focus");
3831+
await vscode.commands.executeCommand("espIdf.errorHints.focus");
38413832
}
38423833
});
38433834

@@ -3887,10 +3878,6 @@ export async function activate(context: vscode.ExtensionContext) {
38873878
)
38883879
);
38893880

3890-
// --- Hints Status Bar Item ---
3891-
const hintsStatusBarItem = createHintsStatusBarItem();
3892-
context.subscriptions.push(hintsStatusBarItem);
3893-
38943881
// Subscribe to changes in the hints tree and update the status bar item
38953882
treeDataProvider.onDidChangeTreeData(() => {
38963883
updateHintsStatusBarItem(treeDataProvider.hasHints());

src/statusBar/index.ts

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ export async function createCmdsStatusBarItems(workspaceFolder: Uri) {
236236
89,
237237
commandDictionary[CommandKeys.CustomTask].checkboxState
238238
);
239+
statusBarItems["hints"] = createStatusBarItem(
240+
l10n.t("💡 New ESP-IDF Hints!"),
241+
l10n.t("ESP-IDF: Hints available. Click to view."),
242+
"espIdf.errorHints.focus",
243+
1000,
244+
TreeItemCheckboxState.Unchecked
245+
);
246+
statusBarItems["hints"].hide();
239247
return statusBarItems;
240248
}
241249

@@ -258,49 +266,31 @@ export function createStatusBarItem(
258266
return statusBarItem;
259267
}
260268

261-
// --- ESP-IDF Hints Status Bar Item ---
262-
let hintsStatusBarItem: StatusBarItem | undefined;
263-
264-
/**
265-
* Create the ESP-IDF Hints status bar item using createStatusBarItem
266-
*/
267-
export function createHintsStatusBarItem() {
268-
if (!hintsStatusBarItem) {
269-
hintsStatusBarItem = createStatusBarItem(
270-
l10n.t("💡 New ESP-IDF Hints!"),
271-
l10n.t("ESP-IDF: Hints available. Click to view."),
272-
"idfErrorHints.focus",
273-
1000, // Highest priority to appear first
274-
TreeItemCheckboxState.Checked
275-
);
276-
hintsStatusBarItem.hide(); // Hide by default until hints are available
277-
}
278-
return hintsStatusBarItem;
279-
}
280-
281269
/**
282270
* Show the hints status bar item with an alert icon if hints are available
283271
* @param {boolean} hasHints - Whether hints are available
284272
*/
285273
export function updateHintsStatusBarItem(hasHints: boolean) {
286-
if (!hintsStatusBarItem) return;
274+
if (!statusBarItems["hints"]) return;
287275
if (hasHints) {
288-
hintsStatusBarItem.text = l10n.t("💡 New ESP-IDF Hints!");
289-
hintsStatusBarItem.tooltip = l10n.t("ESP-IDF: Hints available. Click to view.");
290-
hintsStatusBarItem.backgroundColor = "statusBarItem.warningBackground";
291-
hintsStatusBarItem.show();
276+
statusBarItems["hints"].text = l10n.t("💡 New ESP-IDF Hints!");
277+
statusBarItems["hints"].tooltip = l10n.t(
278+
"ESP-IDF: Hints available. Click to view."
279+
);
280+
statusBarItems["hints"].backgroundColor = "statusBarItem.warningBackground";
281+
statusBarItems["hints"].show();
292282
} else {
293-
hintsStatusBarItem.hide();
294-
hintsStatusBarItem.color = undefined;
283+
statusBarItems["hints"].hide();
284+
statusBarItems["hints"].color = undefined;
295285
}
296286
}
297287

298288
/**
299289
* Dispose the hints status bar item
300290
*/
301291
export function disposeHintsStatusBarItem() {
302-
if (hintsStatusBarItem) {
303-
hintsStatusBarItem.dispose();
304-
hintsStatusBarItem = undefined;
292+
if (statusBarItems["hints"]) {
293+
statusBarItems["hints"].dispose();
294+
statusBarItems["hints"] = undefined;
305295
}
306296
}

0 commit comments

Comments
 (0)