improved error feedback and fix completion issue

This commit is contained in:
2026-04-23 23:00:01 +02:00
parent a7846b54e5
commit 8454cc95f5
5 changed files with 26 additions and 4 deletions

View File

@@ -86,6 +86,10 @@
"title": "AppDaemon: Refresh Entity List",
"icon": "$(sync)"
},
{
"command": "appdaemon.handleErrors",
"title": "AppDaemon: Handle Errors"
},
{
"command": "appdaemon.clearErrors",
"title": "AppDaemon: Clear Error Diagnostics"

View File

@@ -37,7 +37,10 @@ export class EntityCompletionProvider implements vscode.CompletionItemProvider {
const domain = dotMatch[1];
const partial = dotMatch[2];
if (this.cachedDomains.has(domain)) {
const items = this.buildDomainItems(entities, domain, partial);
// Range covers "domain.partial" so the full entity_id replaces it
const replaceStart = position.translate(0, -(domain.length + 1 + partial.length));
const replaceRange = new vscode.Range(replaceStart, position);
const items = this.buildDomainItems(entities, domain, partial, replaceRange);
if (items.length > 0) {
return new vscode.CompletionList(items, false);
}
@@ -80,7 +83,8 @@ export class EntityCompletionProvider implements vscode.CompletionItemProvider {
private buildDomainItems(
entities: HAEntity[],
domain: string,
partial: string
partial: string,
replaceRange: vscode.Range
): vscode.CompletionItem[] {
const items: vscode.CompletionItem[] = [];
const prefix = `${domain}.`;
@@ -105,6 +109,7 @@ export class EntityCompletionProvider implements vscode.CompletionItemProvider {
item.documentation = new vscode.MarkdownString(formatEntityMarkdown(entity));
item.filterText = entity.entity_id;
item.sortText = entity.entity_id;
item.range = replaceRange;
items.push(item);
}
return items;

View File

@@ -285,7 +285,18 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('appdaemon.showErrors', () => {
errorViewer.show();
}),
vscode.commands.registerCommand('appdaemon.handleErrors', async () => {
const pick = await vscode.window.showErrorMessage(
'AppDaemon errors detected',
'Show log',
'Clear'
);
if (pick === 'Show log') {
errorViewer.show();
} else if (pick === 'Clear') {
errorViewer.clearDiagnostics();
}
}),
vscode.commands.registerCommand('appdaemon.refreshEntities', async () => {
const entities = await haClient.fetchEntities();
vscode.window.showInformationMessage(`AppDaemon: ${entities.length} entities loaded`);

View File

@@ -78,11 +78,13 @@ export class StatusBarManager {
if (count > 0) {
this.errorItem.text = `$(warning) AD Errors (${count})`;
this.errorItem.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground');
this.errorItem.tooltip = `${count} error(s) in AppDaemon log — click to view`;
this.errorItem.tooltip = `${count} error(s) — click to show or clear`;
this.errorItem.command = 'appdaemon.handleErrors';
} else {
this.errorItem.text = '$(check) AD Errors';
this.errorItem.backgroundColor = undefined;
this.errorItem.tooltip = 'No AppDaemon errors — click to view log';
this.errorItem.command = 'appdaemon.showErrors';
}
}