Skip to content

Commit

Permalink
Fixed issues with non-root workspaces (#64)
Browse files Browse the repository at this point in the history
Closes #62

Also added new release notes

Signed-off-by: Kuba Wolanin <hi@kubawolanin.com>
  • Loading branch information
kubawolanin authored Nov 25, 2017
1 parent 56c9b4d commit 91be810
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 39 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# openHAB VS Code Extension Change Log

## 0.3.5 - 2017-11-25
- Fixed issues with non-root workspaces (#62)
- Fixed issues with REST connection (#58)
- Added some Type Conversion snippets (#60)
- Added 'Open Karaf console' feature (#59)
- Optionally open Classic UI for sitemap preview (#54)

## 0.3.0 - 2017-11-15
- Introduced openHAB **Things Explorer** view in the sidebar!
- Create Items directly from Thing's channels.
Expand Down
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ The extension is designed with openHAB 2.x in mind - most snippets and design pa

## Features

* Code snippets for openHAB, including [Design Patterns](https://community.openhab.org/tags/designpattern) by Rich Koshak
* Syntax highlighting for the [openHAB DSL](http://docs.openhab.org/configuration/index.html) (rules, items, scripts and sitemaps).
* Code snippets for openHAB, including [Design Patterns](https://community.openhab.org/tags/designpattern) by Rich Koshak
* Integrated quick search of [openHAB Docs page](http://docs.openhab.org) (`Alt + Shift + O`)
* Integrated quick search of [openHAB Community](https://community.openhab.org)
* Integrated Basic UI browser window (`Ctrl + Alt + O` or editor title icon)
* Integrated Basic UI (or Classic UI) browser window (`Ctrl + Alt + O` or editor title icon)
* Integrated Paper UI preview for the Items and Things
* Integration with openHAB REST API
* List of all Items accessible from the tree view
* Code completions
* Language Server Protocol support
* Language Server Protocol support - syntax validation
* Dynamic Items creation from Thing's channels
* Quick Karaf console access
* Add Items to Sitemap with one click

![openHAB2 code snippets](images/openhab-demo.gif)

Expand Down Expand Up @@ -73,10 +77,9 @@ You may need to reload the VSCode window to take effect.
## Validating the Rules

This extension comes with Language Server Protocol support.
Language servers allow you to add your own validation logic to files open in VS Code.
Language servers allow you to add your own validation logic to files open in VS Code.
openHAB from version `openHAB 2.2.0 Build #1065` (SNAPSHOT) has the Language Server exposed on `5007` port.
In order to enable this feature in VSCode, please make sure that `misc-lsp`
(Misc / Language Server Support) add-on is installed on your openHAB instance.
openHAB 2.2 since build #1084 has LSP feature enabled in the runtime, so there are no additional steps for you to make it work.

In the unlikely case that your language server is running on a port other than the default one this is how it can be changed in the configuration:

Expand All @@ -86,20 +89,58 @@ In the unlikely case that your language server is running on a port other than t
}
```

If you don't want to have your openHAB files validated by Language Server, simply disable it in the extension:
```json
{
"openhab.lspEnabled": false
}
```

## Sitemap preview with Basic UI

openHAB VS Code Extension allows you to preview the [sitemap structure](http://docs.openhab.org/configuration/sitemaps.html) in the [Basic UI](http://docs.openhab.org/addons/uis/basic/readme.html) running on your openHAB server instance.

If you have a sitemap file active in your editor and open Basic UI (`Ctrl + Alt + O` or editor title icon), you'll land directly on the sitemap you're working on.

You can optionally set `openhab.sitemapPreviewUI` parameter to `classicui` if you prefer Classic UI instead:
```json
{
"openhab.sitemapPreviewUI": "classicui"
}
```

![Intelligent sitemap preview](images/openhab-sitemap.gif)

You need to have openHAB server running in order to preview changes. The extension assumes that you access your openHAB config files from either:

Samba share (e.g. `\\OPENHABIANPI\openHAB-conf\`)
Local folder (e.g. `c:\openhab\configuration`)

## Quick Karaf console access

![Quick Karaf console access](images/openhab-karaf.gif)

This extension allows you to run openHAB Karaf console directly from the editor.
Note that you need to have:

* `ssh` installed on your environment
* Karaf exposed to the external interface
* `openhab.host` configuration parameter set properly

This feature allows you to modify the new param and e.g. show the openHAB logs immediately:

```
"openhab.karafCommand": "ssh openhab@%openhabhost% -p 8101 -t 'log:tail'",
```

## Things Explorer demo

![Things Explorer](images/openhab-things.gif)

## Sitemap Insert demo

![Quick insert Items into Sitemap](images/openhab-sitemap-insert.gif)

## Known Issues

Check out [existing issues](https://github.com/openhab/openhab-vscode/issues) in the repository.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "openhab",
"displayName": "openHAB",
"description": "Robust tool for openHAB textual configurations. Includes code snippets, syntax highlighting, language server integration and more.",
"version": "0.3.0",
"version": "0.3.5",
"publisher": "openhab",
"icon": "openhab.png",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion snippets/openhabrules.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
"prefix": "hexFromString",
"body": "val itemvalue = new java.math.BigDecimal(Integer::parseInt(${1:hexValue}, 16))",
"description": "Gets a hexvalue from a string and turns it into a bigdecimal"
},
},

"switch to numeric": {
"prefix": "switchNum",
Expand Down
16 changes: 0 additions & 16 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {

import * as _ from 'lodash'
import * as fs from 'fs'
import * as path from 'path'
import * as request from 'request-promise-native'

export function getHost() {
Expand Down Expand Up @@ -48,21 +47,6 @@ export function getBuildVersion(): Thenable<string> {
})
}

export function pathExists(p: string): boolean {
try {
fs.accessSync(p)
} catch (err) {
return false
}

return true
}

export function isOpenHABWorkspace(): boolean {
let folders = ['items', 'rules']
return _.some(folders, (folder) => pathExists(path.join(workspace.rootPath, folder)))
}

export function hasExtension(name: string): Thenable<boolean> {
return new Promise((resolve, reject) => {
request(getHost() + '/rest/extensions')
Expand Down
27 changes: 12 additions & 15 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import {

import {
getHost,
isOpenHABWorkspace,
hasExtension,
getBuildVersion,
openBrowser,
openHtml,
openUI,
pathExists
openUI
} from './Utils'

import { ItemsExplorer } from './ItemsExplorer/ItemsExplorer'
Expand All @@ -50,6 +48,7 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
let config = workspace.getConfiguration('openhab')
const itemsExplorer = new ItemsExplorer(getHost())
const thingsExplorer = new ThingsExplorer(getHost())
const itemsCompletion = new ItemsCompletion(getHost())

disposables.push(commands.registerCommand('openhab.basicUI', () => {
let editor = window.activeTextEditor
Expand Down Expand Up @@ -144,20 +143,18 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
disposables.push(commands.registerCommand('openhab.command.things.copyUID', (query) =>
ncp.copy(query.UID || query.uid)))

if (isOpenHABWorkspace()) {
if (config.useRestApi) {
disposables.push(window.registerTreeDataProvider('openhabItems', itemsExplorer))
disposables.push(window.registerTreeDataProvider('openhabThings', thingsExplorer))
}
if (config.useRestApi) {
disposables.push(window.registerTreeDataProvider('openhabItems', itemsExplorer))
disposables.push(window.registerTreeDataProvider('openhabThings', thingsExplorer))
}

if (config.lspEnabled) {
let languageClientProvider = new LanguageClientProvider()
disposables.push(languageClientProvider.connect())
}
if (config.lspEnabled) {
let languageClientProvider = new LanguageClientProvider()
disposables.push(languageClientProvider.connect())
}

if (config.useRestApi && config.restCompletions) {
disposables.push(languages.registerCompletionItemProvider('openhab', new ItemsCompletion(getHost())))
}
if (config.useRestApi && config.restCompletions) {
disposables.push(languages.registerCompletionItemProvider('openhab', itemsCompletion))
}
}
export function activate(context: ExtensionContext) {
Expand Down

0 comments on commit 91be810

Please sign in to comment.