From b6a4e61faa7ba12264d9dfca7b2414d866001b72 Mon Sep 17 00:00:00 2001 From: Henry Wong Date: Fri, 1 Feb 2019 17:34:40 +0800 Subject: [PATCH] [code] WIP: Implement a go language server launcher at external mode. This is the initialization commit for go language server. And `go_launcher.ts` is mainly borrowed from `java_launcher.ts` --- x-pack/plugins/code/model/repository.ts | 1 + .../admin_page/project_settings.tsx | 1 + .../code/server/indexer/schema/document.ts | 3 ++ x-pack/plugins/code/server/lsp/go_launcher.ts | 49 +++++++++++++++++++ .../code/server/lsp/language_servers.ts | 11 ++++- .../server/repository_config_controller.ts | 3 ++ .../functional/es_archives/code/mappings.json | 3 ++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/code/server/lsp/go_launcher.ts diff --git a/x-pack/plugins/code/model/repository.ts b/x-pack/plugins/code/model/repository.ts index 57456d401a788..a5c5cb1cdeb66 100644 --- a/x-pack/plugins/code/model/repository.ts +++ b/x-pack/plugins/code/model/repository.ts @@ -23,6 +23,7 @@ export interface Repository { export interface RepositoryConfig { uri: RepositoryUri; + disableGo?: boolean; disableJava?: boolean; disableTypescript?: boolean; } diff --git a/x-pack/plugins/code/public/components/admin_page/project_settings.tsx b/x-pack/plugins/code/public/components/admin_page/project_settings.tsx index f0d9da4bca5a1..78701d89a4fb5 100644 --- a/x-pack/plugins/code/public/components/admin_page/project_settings.tsx +++ b/x-pack/plugins/code/public/components/admin_page/project_settings.tsx @@ -36,6 +36,7 @@ const IconContainer = styled.div` `; const defaultConfig = { + disableGo: true, disableJava: true, disableTypescript: true, }; diff --git a/x-pack/plugins/code/server/indexer/schema/document.ts b/x-pack/plugins/code/server/indexer/schema/document.ts index 09ce678251564..f8c8ce552d0ef 100644 --- a/x-pack/plugins/code/server/indexer/schema/document.ts +++ b/x-pack/plugins/code/server/indexer/schema/document.ts @@ -68,6 +68,9 @@ export const DocumentSchema = { uri: { type: 'text', }, + disableGo: { + type: 'boolean', + }, disableJava: { type: 'boolean', }, diff --git a/x-pack/plugins/code/server/lsp/go_launcher.ts b/x-pack/plugins/code/server/lsp/go_launcher.ts new file mode 100644 index 0000000000000..e0b1f1693563d --- /dev/null +++ b/x-pack/plugins/code/server/lsp/go_launcher.ts @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { ServerOptions } from '../server_options'; +import { LoggerFactory } from '../utils/log_factory'; +import { ILanguageServerLauncher } from './language_server_launcher'; +import { LanguageServerProxy } from './proxy'; +import { RequestExpander } from './request_expander'; + +export class GoLauncher implements ILanguageServerLauncher { + private isRunning: boolean = false; + constructor( + readonly targetHost: string, + readonly detach: boolean, + readonly options: ServerOptions, + readonly loggerFactory: LoggerFactory + ) {} + public get running(): boolean { + return this.isRunning; + } + + public async launch(builtinWorkspace: boolean, maxWorkspace: number, installationPath: string) { + const port = 2091; + + const log = this.loggerFactory.getLogger(['code', `go@${this.targetHost}:${port}`]); + const proxy = new LanguageServerProxy(port, this.targetHost, log); + proxy.awaitServerConnection(); + // detach mode + proxy.onConnected(() => { + this.isRunning = true; + }); + proxy.onDisconnected(() => { + this.isRunning = false; + if (!proxy.isClosed) { + proxy.awaitServerConnection(); + } + }); + + proxy.listen(); + return new Promise(resolve => { + proxy.onConnected(() => { + resolve(new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options)); + }); + }); + } +} diff --git a/x-pack/plugins/code/server/lsp/language_servers.ts b/x-pack/plugins/code/server/lsp/language_servers.ts index 1311e0654f96a..54acbf7ee5dc0 100644 --- a/x-pack/plugins/code/server/lsp/language_servers.ts +++ b/x-pack/plugins/code/server/lsp/language_servers.ts @@ -7,6 +7,7 @@ import * as path from 'path'; import { InstallationType } from '../../common/installation'; import { LanguageServer } from '../../common/language_server'; +import { GoLauncher } from './go_launcher'; import { JavaLauncher } from './java_launcher'; import { LauncherConstructor } from './language_server_launcher'; import { TypescriptServerLauncher } from './ts_launcher'; @@ -46,5 +47,13 @@ export const JAVA: LanguageServerDefinition = { lang.version }/jdt-language-server-${lang.version}-${lang.build}.tar.gz`, }; +export const GO: LanguageServerDefinition = { + name: 'Go', + builtinWorkspaceFolders: true, + languages: ['go'], + launcher: GoLauncher, + installationType: InstallationType.Plugin, + installationPluginName: 'goLanguageServer', +}; export const LanguageServers: LanguageServerDefinition[] = [TYPESCRIPT, JAVA]; -export const LanguageServersDeveloping: LanguageServerDefinition[] = []; +export const LanguageServersDeveloping: LanguageServerDefinition[] = [GO]; diff --git a/x-pack/plugins/code/server/repository_config_controller.ts b/x-pack/plugins/code/server/repository_config_controller.ts index 5691eb40c9f81..b3766d5d04ee5 100644 --- a/x-pack/plugins/code/server/repository_config_controller.ts +++ b/x-pack/plugins/code/server/repository_config_controller.ts @@ -29,6 +29,9 @@ export class RepositoryConfigController { } } + if (lang === 'go' && repoConfig.disableGo === true) { + return true; + } if (lang === 'java' && repoConfig.disableJava === true) { return true; } diff --git a/x-pack/test/functional/es_archives/code/mappings.json b/x-pack/test/functional/es_archives/code/mappings.json index dfcb736aed142..4cd04d4116b0f 100644 --- a/x-pack/test/functional/es_archives/code/mappings.json +++ b/x-pack/test/functional/es_archives/code/mappings.json @@ -138,6 +138,9 @@ }, "repository_config": { "properties": { + "disableGo": { + "type": "boolean" + }, "disableJava": { "type": "boolean" },