From 2b102cb081af1f498b4272aed6fdf00996c54aca Mon Sep 17 00:00:00 2001 From: Kuba Wolanin Date: Fri, 27 Oct 2017 20:18:52 +0200 Subject: [PATCH] Error handling enhancement. Closes #42 Resolves #18 (#44) Signed-off-by: Kuba Wolanin --- src/ItemsExplorer/ItemsModel.ts | 9 +++++---- src/Utils.ts | 9 +++++++++ syntaxes/openhab.tmLanguage.json | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ItemsExplorer/ItemsModel.ts b/src/ItemsExplorer/ItemsModel.ts index 1a3179e..332772a 100644 --- a/src/ItemsExplorer/ItemsModel.ts +++ b/src/ItemsExplorer/ItemsModel.ts @@ -64,12 +64,13 @@ export class ItemsModel { }.bind(this)) .catch(async err => { let config = workspace.getConfiguration('openhab') - const openSettings = 'Open Settings' + const setHost = 'Set openHAB host' const disableRest = 'Disable REST API' - const result = await window.showErrorMessage('Error while connecting to openHAB REST API. ', openSettings, disableRest) + const result = await window.showErrorMessage('Error while connecting to openHAB REST API. ', setHost, disableRest) switch (result) { - case openSettings: - commands.executeCommand('workbench.action.openGlobalSettings') + case setHost: + config.update('host', 'localhost') + commands.executeCommand('workbench.action.openWorkspaceSettings') break case disableRest: config.update('useRestApi', false) diff --git a/src/Utils.ts b/src/Utils.ts index 2cea5f9..5898dfb 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -74,6 +74,15 @@ export function hasExtension(name: string): Thenable { }) } +export function getSitemaps(): Thenable { + return new Promise((resolve, reject) => { + request(getHost() + '/rest/sitemaps') + .then((response) => { + resolve(JSON.parse(response)) + }).catch(() => reject([])) + }) +} + export function openHtml(uri: Uri, title) { return commands.executeCommand('vscode.previewHtml', uri, ViewColumn.Two, title) .then((success) => { diff --git a/syntaxes/openhab.tmLanguage.json b/syntaxes/openhab.tmLanguage.json index cb90983..fe139dc 100644 --- a/syntaxes/openhab.tmLanguage.json +++ b/syntaxes/openhab.tmLanguage.json @@ -433,7 +433,7 @@ "name": "keyword.control.openhab" }, { - "match": "\\b(return|break|case|continue|default|do|while|for|switch|if|else)\\b", + "match": "\\b((?!<)(return|break|case|continue|default|do|while|for|switch|if|else)(?!>))\\b", "name": "keyword.control.openhab" }, {