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'
|
2021-06-04 18:54:48 +08:00
|
|
|
import { AutoFixCommand, Command, ConfigurePluginCommand, FileReferencesCommand, OpenTsServerLogCommand, ReloadProjectsCommand, TypeScriptGoToProjectConfigCommand } from './server/commands'
|
2021-12-21 13:56:01 +08:00
|
|
|
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> {
|
2020-12-08 18:50:01 +08:00
|
|
|
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))
|
2020-12-08 18:50:01 +08:00
|
|
|
registCommand(new AutoFixCommand(service))
|
|
|
|
registCommand(new ReloadProjectsCommand(service))
|
2021-06-04 18:54:48 +08:00
|
|
|
registCommand(new FileReferencesCommand(service))
|
2020-12-08 18:50:01 +08:00
|
|
|
registCommand(new OpenTsServerLogCommand(service))
|
|
|
|
registCommand(new TypeScriptGoToProjectConfigCommand(service))
|
|
|
|
registCommand(new OrganizeImportsCommand(service))
|
2021-12-21 13:56:01 +08:00
|
|
|
registCommand(new SourceImportsCommand(service))
|
2020-12-17 20:28:49 +08:00
|
|
|
registCommand({
|
|
|
|
id: 'tsserver.restart',
|
|
|
|
execute: (): void => {
|
2021-12-22 16:53:53 +08:00
|
|
|
service.restart()
|
2020-12-17 20:28:49 +08:00
|
|
|
}
|
|
|
|
})
|
2020-12-08 18:50:01 +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
|
|
|
}
|