Update item cache on save (#189)
* Added onSave event listener for HoverProvider. Signed-off-by: Jerome Luckenbach <github@luckenba.ch> * Refreshed changelog. Signed-off-by: Jerome Luckenbach <github@luckenba.ch> * Added some delay before item refresh. Signed-off-by: Jerome Luckenbach <github@luckenba.ch>pull/191/head
parent
09bdbc5cce
commit
07ad877900
|
@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## [1.0.0] - tba
|
||||
## [0.7.0] - tba
|
||||
|
||||
### Changed
|
||||
- Added newly used material icons to notice file (#187)
|
||||
- HoverProvider: Itemcache is refreshed on save of items files (#189)
|
||||
|
||||
### Fixed
|
||||
- Fix treeview icons with dynamically generated path (#188)
|
||||
|
||||
## [0.6.0] - 2019-11-13
|
||||
|
||||
### Added
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { Hover } from 'vscode'
|
||||
import { MarkdownString } from 'vscode'
|
||||
import {
|
||||
Hover,
|
||||
MarkdownString
|
||||
} from 'vscode'
|
||||
|
||||
import * as utils from '../Utils'
|
||||
import * as request from 'request-promise-native'
|
||||
|
@ -18,15 +20,10 @@ export class HoverProvider {
|
|||
private static _currentProvider: HoverProvider | undefined
|
||||
|
||||
/**
|
||||
*
|
||||
* Array of known Items from the openHAB environment
|
||||
*/
|
||||
private knownItems:String[]
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private lastItemsUpdate : Number;
|
||||
|
||||
/**
|
||||
* Only allow the class to call the constructor
|
||||
*/
|
||||
|
@ -84,9 +81,9 @@ export class HoverProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update known Items array and store the last time it has been updated.
|
||||
* Update known Items array
|
||||
*/
|
||||
private updateItems() : Boolean {
|
||||
public updateItems() : Boolean {
|
||||
|
||||
request(`${utils.getHost()}/rest/items/`)
|
||||
.then((response) => {
|
||||
|
@ -99,8 +96,7 @@ export class HoverProvider {
|
|||
this.knownItems.push(item.name)
|
||||
});
|
||||
|
||||
this.lastItemsUpdate = Date.now()
|
||||
|
||||
console.log(`Updates Items for HoverProvider`)
|
||||
return true
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
|
@ -159,4 +159,13 @@ export function appendToOutput(message: string){
|
|||
if(!extensionOutput) { extensionOutput = window.createOutputChannel("openHAB Extension") }
|
||||
|
||||
extensionOutput.appendLine(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleep for some time
|
||||
*
|
||||
* @param sleepTime wanted time in milliseconds
|
||||
*/
|
||||
export async function sleep(sleepTime: number){
|
||||
return new Promise(resolve => setTimeout(resolve, sleepTime))
|
||||
}
|
|
@ -29,6 +29,7 @@ import { HoverProvider } from './HoverProvider/HoverProvider';
|
|||
import * as _ from 'lodash'
|
||||
import * as ncp from 'copy-paste'
|
||||
import * as path from 'path'
|
||||
import { SSL_OP_EPHEMERAL_RSA } from 'constants';
|
||||
|
||||
let _extensionPath: string
|
||||
let ohStatusBarItem: StatusBarItem
|
||||
|
@ -192,6 +193,20 @@ async function init(disposables: Disposable[], config, context): Promise<void> {
|
|||
})
|
||||
|
||||
)
|
||||
|
||||
// Listen for document save events, to update the cached items
|
||||
workspace.onDidSaveTextDocument((savedDocument) => {
|
||||
let fileEnding = savedDocument.fileName.split(".").slice(-1)[0]
|
||||
|
||||
if(fileEnding === "items"){
|
||||
console.log(`Items file was saved.\nRefreshing cached items for HoverProvider`);
|
||||
|
||||
// Give item registry some time to reflect the file changes.
|
||||
utils.sleep(1500).then(() => {
|
||||
ohHoverProvider.updateItems();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (config.remoteLspEnabled) {
|
||||
|
|
Loading…
Reference in New Issue