add StatusBarItem support
This commit is contained in:
parent
63209916cc
commit
02b6067a98
3 changed files with 58 additions and 2 deletions
|
@ -20,6 +20,7 @@ import { fork, getTempFile, IForkOptions, makeRandomHexString } from './utils/pr
|
||||||
import Tracer from './utils/tracer'
|
import Tracer from './utils/tracer'
|
||||||
import { inferredProjectConfig } from './utils/tsconfig'
|
import { inferredProjectConfig } from './utils/tsconfig'
|
||||||
import { TypeScriptVersion, TypeScriptVersionProvider } from './utils/versionProvider'
|
import { TypeScriptVersion, TypeScriptVersionProvider } from './utils/versionProvider'
|
||||||
|
import VersionStatus from './utils/versionStatus'
|
||||||
import { ICallback, Reader } from './utils/wireProtocol'
|
import { ICallback, Reader } from './utils/wireProtocol'
|
||||||
|
|
||||||
interface CallbackItem {
|
interface CallbackItem {
|
||||||
|
@ -152,6 +153,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
private cancellationPipeName: string | null = null
|
private cancellationPipeName: string | null = null
|
||||||
private requestQueue: RequestQueue
|
private requestQueue: RequestQueue
|
||||||
private callbacks: CallbackMap
|
private callbacks: CallbackMap
|
||||||
|
private versionStatus: VersionStatus
|
||||||
private readonly _onTsServerStarted = new Emitter<API>()
|
private readonly _onTsServerStarted = new Emitter<API>()
|
||||||
private readonly _onProjectLanguageServiceStateChanged = new Emitter<Proto.ProjectLanguageServiceStateEventBody>()
|
private readonly _onProjectLanguageServiceStateChanged = new Emitter<Proto.ProjectLanguageServiceStateEventBody>()
|
||||||
private readonly _onDidBeginInstallTypings = new Emitter<Proto.BeginInstallTypesEventBody>()
|
private readonly _onDidBeginInstallTypings = new Emitter<Proto.BeginInstallTypesEventBody>()
|
||||||
|
@ -175,6 +177,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
this.versionProvider = new TypeScriptVersionProvider(this._configuration)
|
this.versionProvider = new TypeScriptVersionProvider(this._configuration)
|
||||||
this._apiVersion = API.defaultVersion
|
this._apiVersion = API.defaultVersion
|
||||||
this.tracer = new Tracer(this.logger)
|
this.tracer = new Tracer(this.logger)
|
||||||
|
this.versionStatus = new VersionStatus(this.normalizePath.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onDiagnosticsReceived = new Emitter<TsDiagnostics>()
|
private _onDiagnosticsReceived = new Emitter<TsDiagnostics>()
|
||||||
|
@ -315,6 +318,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
}
|
}
|
||||||
workspace.showMessage(`Using tsserver from: ${currentVersion.path}`) // tslint:disable-line
|
workspace.showMessage(`Using tsserver from: ${currentVersion.path}`) // tslint:disable-line
|
||||||
this._apiVersion = currentVersion.version
|
this._apiVersion = currentVersion.version
|
||||||
|
this.versionStatus.onDidChangeTypeScriptVersion(currentVersion)
|
||||||
this.requestQueue = new RequestQueue()
|
this.requestQueue = new RequestQueue()
|
||||||
this.callbacks = new CallbackMap()
|
this.callbacks = new CallbackMap()
|
||||||
this.lastError = null
|
this.lastError = null
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import { Disposable } from 'vscode-languageserver-protocol'
|
import { Disposable } from 'vscode-languageserver-protocol'
|
||||||
import { ITypeScriptServiceClient } from '../typescriptService'
|
import { ITypeScriptServiceClient } from '../typescriptService'
|
||||||
import { workspace } from 'coc.nvim'
|
import { workspace, StatusBarItem } from 'coc.nvim'
|
||||||
|
|
||||||
const typingsInstallTimeout = 30 * 1000
|
const typingsInstallTimeout = 30 * 1000
|
||||||
|
|
||||||
|
@ -64,8 +64,10 @@ export class AtaProgressReporter {
|
||||||
private _promises = new Map<number, Function>()
|
private _promises = new Map<number, Function>()
|
||||||
private _disposable: Disposable
|
private _disposable: Disposable
|
||||||
private _invalid = false
|
private _invalid = false
|
||||||
|
private statusItem: StatusBarItem
|
||||||
|
|
||||||
constructor(client: ITypeScriptServiceClient) {
|
constructor(client: ITypeScriptServiceClient) {
|
||||||
|
this.statusItem = workspace.createStatusBarItem(10, { progress: true })
|
||||||
const disposables: Disposable[] = []
|
const disposables: Disposable[] = []
|
||||||
disposables.push(client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)))
|
disposables.push(client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)))
|
||||||
disposables.push(client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)))
|
disposables.push(client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)))
|
||||||
|
@ -95,10 +97,12 @@ export class AtaProgressReporter {
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
workspace.showMessage('Fetching data for better TypeScript IntelliSense')
|
this.statusItem.text = 'Fetching data for better TypeScript IntelliSense'
|
||||||
|
this.statusItem.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onEndOrTimeout(eventId: number): void {
|
private _onEndOrTimeout(eventId: number): void {
|
||||||
|
this.statusItem.hide()
|
||||||
const resolve = this._promises.get(eventId)
|
const resolve = this._promises.get(eventId)
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
this._promises.delete(eventId)
|
this._promises.delete(eventId)
|
||||||
|
@ -107,6 +111,7 @@ export class AtaProgressReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onTypesInstallerInitializationFailed() { // tslint:disable-line
|
private onTypesInstallerInitializationFailed() { // tslint:disable-line
|
||||||
|
this.statusItem.hide()
|
||||||
if (!this._invalid) {
|
if (!this._invalid) {
|
||||||
workspace.showMessage('Could not install typings files for JavaScript language features. Please ensure that NPM is installed', 'error')
|
workspace.showMessage('Could not install typings files for JavaScript language features. Please ensure that NPM is installed', 'error')
|
||||||
}
|
}
|
||||||
|
|
47
src/server/utils/versionStatus.ts
Normal file
47
src/server/utils/versionStatus.ts
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import { StatusBarItem, workspace, events } from 'coc.nvim'
|
||||||
|
import { Disposable } from 'vscode-languageserver-protocol'
|
||||||
|
import Uri from 'vscode-uri'
|
||||||
|
import { TypeScriptVersion } from './versionProvider'
|
||||||
|
|
||||||
|
export default class VersionStatus {
|
||||||
|
private readonly _onChangeEditorSub: Disposable
|
||||||
|
private readonly _versionBarEntry: StatusBarItem
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly _normalizePath: (resource: Uri) => string | null
|
||||||
|
) {
|
||||||
|
this._versionBarEntry = workspace.createStatusBarItem(99)
|
||||||
|
this._onChangeEditorSub = events.on('BufEnter', this.showHideStatus, this)
|
||||||
|
this._versionBarEntry.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
public dispose(): void {
|
||||||
|
this._versionBarEntry.dispose()
|
||||||
|
this._onChangeEditorSub.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
public onDidChangeTypeScriptVersion(version: TypeScriptVersion): void {
|
||||||
|
this._versionBarEntry.text = `TSC ${version.versionString}`
|
||||||
|
this.showHideStatus().catch(_e => {
|
||||||
|
// noop
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private async showHideStatus(): Promise<void> {
|
||||||
|
let document = await workspace.document
|
||||||
|
if (!document) {
|
||||||
|
this._versionBarEntry.hide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['typescript', 'typescriptreact'].indexOf(document.filetype) !== -1) {
|
||||||
|
if (this._normalizePath(Uri.parse(document.uri))) {
|
||||||
|
this._versionBarEntry.show()
|
||||||
|
} else {
|
||||||
|
this._versionBarEntry.hide()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this._versionBarEntry.hide()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue