improve check of statusItem

This commit is contained in:
chemzqm 2019-07-22 02:06:03 +08:00
parent ed538dc3b5
commit 56c60a2ef1

View file

@ -11,7 +11,7 @@ export default class VersionStatus {
private readonly enableJavascript: boolean private readonly enableJavascript: boolean
) { ) {
this._versionBarEntry = workspace.createStatusBarItem(99) this._versionBarEntry = workspace.createStatusBarItem(99)
this._onChangeEditorSub = events.on('BufEnter', this.showHideStatus, this) this._onChangeEditorSub = events.on('BufEnter', this.onBufEnter, this)
this._versionBarEntry.show() this._versionBarEntry.show()
} }
@ -22,34 +22,25 @@ export default class VersionStatus {
public onDidChangeTypeScriptVersion(_version: TypeScriptVersion): void { public onDidChangeTypeScriptVersion(_version: TypeScriptVersion): void {
this._versionBarEntry.text = `TSC` this._versionBarEntry.text = `TSC`
this.showHideStatus().catch(_e => {
// noop
})
} }
public set loading(isLoading: boolean) { public set loading(isLoading: boolean) {
this._versionBarEntry.isProgress = isLoading this._versionBarEntry.isProgress = isLoading
} }
private async showHideStatus(): Promise<void> { private checkFiletype(filetype: string): boolean {
let document = await workspace.document if (filetype.startsWith('javascript') && this.enableJavascript) {
if (!document) { return true
this._versionBarEntry.hide()
return
} }
let filetypes = ['typescript', 'typescriptreact'] return filetype.startsWith('typescript')
if (this.enableJavascript) {
filetypes.push('javascript', 'javascriptreact')
} }
if (filetypes.indexOf(document.filetype) !== -1) { private async onBufEnter(bufnr: number): Promise<void> {
if (this._normalizePath(Uri.parse(document.uri))) { let filetype = await workspace.nvim.call('getbufvar', [bufnr, '&filetype', ''])
if (this.checkFiletype(filetype)) {
this._versionBarEntry.show() this._versionBarEntry.show()
} else { } else {
this._versionBarEntry.hide() this._versionBarEntry.hide()
} }
return
}
this._versionBarEntry.hide()
} }
} }