coc-tsserver/src/index.ts

48 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-09-11 00:51:17 +08:00
import { commands, ExtensionContext, services, workspace } from 'coc.nvim'
2018-09-07 20:40:51 +08:00
import TsserverService from './server'
import { AutoFixCommand, Command, ConfigurePluginCommand, FileReferencesCommand, OpenTsServerLogCommand, ReloadProjectsCommand, TypeScriptGoToProjectConfigCommand } from './server/commands'
import { OrganizeImportsCommand, SourceImportsCommand } from './server/organizeImports'
2019-03-05 20:33:05 +08:00
import { PluginManager } from './utils/plugins'
2018-09-07 20:40:51 +08:00
2019-03-05 20:33:05 +08:00
interface API {
configurePlugin(pluginId: string, configuration: {}): void
}
export async function activate(context: ExtensionContext): Promise<API> {
let { subscriptions, logger } = context
2018-10-21 13:21:25 +08:00
const config = workspace.getConfiguration().get<any>('tsserver', {})
2018-09-07 20:40:51 +08:00
if (!config.enable) return
2019-03-05 20:33:05 +08:00
const pluginManager = new PluginManager()
const service = new TsserverService(pluginManager)
2018-09-07 20:40:51 +08:00
function registCommand(cmd: Command): void {
let { id, execute } = cmd
subscriptions.push(commands.registerCommand(id as string, execute, cmd))
}
2019-03-05 20:33:05 +08:00
registCommand(new ConfigurePluginCommand(pluginManager))
registCommand(new AutoFixCommand(service))
registCommand(new ReloadProjectsCommand(service))
registCommand(new FileReferencesCommand(service))
registCommand(new OpenTsServerLogCommand(service))
registCommand(new TypeScriptGoToProjectConfigCommand(service))
registCommand(new OrganizeImportsCommand(service))
registCommand(new SourceImportsCommand(service))
2020-12-17 20:28:49 +08:00
registCommand({
id: 'tsserver.restart',
execute: (): void => {
service.restart()
2020-12-17 20:28:49 +08:00
}
})
service.start().then(() => {
subscriptions.push(services.regist(service))
}, e => {
logger.error(`Error on service start:`, e)
})
2019-03-05 20:33:05 +08:00
return {
configurePlugin: (pluginId: string, configuration: {}): void => {
pluginManager.setConfiguration(pluginId, configuration)
}
}
2018-09-07 20:40:51 +08:00
}