Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code] WIP: Implement a go language server launcher at external mode. #29168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/code/model/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Repository {

export interface RepositoryConfig {
uri: RepositoryUri;
disableGo?: boolean;
disableJava?: boolean;
disableTypescript?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const IconContainer = styled.div`
`;

const defaultConfig = {
disableGo: true,
disableJava: true,
disableTypescript: true,
};
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/code/server/indexer/schema/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export const DocumentSchema = {
uri: {
type: 'text',
},
disableGo: {
type: 'boolean',
},
disableJava: {
type: 'boolean',
},
Expand Down
49 changes: 49 additions & 0 deletions x-pack/plugins/code/server/lsp/go_launcher.ts
Original file line number Diff line number Diff line change
@@ -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<RequestExpander>(resolve => {
proxy.onConnected(() => {
resolve(new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options));
});
});
}
}
11 changes: 10 additions & 1 deletion x-pack/plugins/code/server/lsp/language_servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
3 changes: 3 additions & 0 deletions x-pack/plugins/code/server/repository_config_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export class RepositoryConfigController {
}
}

if (lang === 'go' && repoConfig.disableGo === true) {
return true;
}
if (lang === 'java' && repoConfig.disableJava === true) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions x-pack/test/functional/es_archives/code/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
},
"repository_config": {
"properties": {
"disableGo": {
"type": "boolean"
},
"disableJava": {
"type": "boolean"
},
Expand Down