Skip to content

Commit d7e4ee3

Browse files
authored
[Code]: clean up the way we config LSP related configs (#32607)
1 parent 84a564b commit d7e4ee3

File tree

15 files changed

+103
-70
lines changed

15 files changed

+103
-70
lines changed

x-pack/plugins/code/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ export const code = (kibana: any) =>
4141
updateRepoFrequencyMs: Joi.number().default(moment.duration(1, 'hour').asMilliseconds()),
4242
// The frequency which each repo tries to index. 1 day by default.
4343
indexRepoFrequencyMs: Joi.number().default(moment.duration(1, 'day').asMilliseconds()),
44-
// timeout a request over 30s.
45-
lspRequestTimeoutMs: Joi.number().default(moment.duration(10, 'second').asMilliseconds()),
44+
lsp: Joi.object({
45+
// timeout of a request
46+
requestTimeoutMs: Joi.number().default(moment.duration(10, 'second').asMilliseconds()),
47+
// if we want the language server run in seperately
48+
detach: Joi.boolean().default(false),
49+
// whether we want to show more language server logs
50+
verbose: Joi.boolean().default(false),
51+
}),
4652
repos: Joi.array().default([]),
4753
maxWorkspace: Joi.number().default(5), // max workspace folder for each language server
4854
disableScheduler: Joi.boolean().default(true), // Temp option to disable all schedulers.

x-pack/plugins/code/server/__tests__/clone_worker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ const options = {
4242
queueTimeout: 60 * 60 * 1000, // 1 hour by default
4343
updateFreqencyMs: 5 * 60 * 1000, // 5 minutes by default
4444
indexFrequencyMs: 24 * 60 * 60 * 1000, // 1 day by default
45-
lspRequestTimeoutMs: 5 * 60, // timeout a request over 30s
45+
lsp: {
46+
requestTimeoutMs: 5 * 60, // timeout a request over 30s
47+
detach: false,
48+
verbose: false,
49+
},
4650
repos: [],
4751
maxWorkspace: 5, // max workspace folder for each language server
4852
disableScheduler: true, // Temp option to disable all schedulers.

x-pack/plugins/code/server/__tests__/git_operations.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ describe('git_operations', () => {
8383
queueTimeout: 60 * 60 * 1000, // 1 hour by default
8484
updateFreqencyMs: 5 * 60 * 1000, // 5 minutes by default
8585
indexFrequencyMs: 24 * 60 * 60 * 1000, // 1 day by default
86-
lspRequestTimeoutMs: 5 * 60, // timeout a request over 30s
86+
lsp: {
87+
requestTimeoutMs: 5 * 60, // timeout a request over 30s
88+
detach: false,
89+
verbose: false,
90+
},
8791
repos: [],
8892
maxWorkspace: 5, // max workspace folder for each language server
8993
disableScheduler: true, // Temp option to disable all schedulers.

x-pack/plugins/code/server/__tests__/lsp_indexer_test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ const options = {
6969
queueTimeout: 60 * 60 * 1000, // 1 hour by default
7070
updateFreqencyMs: 5 * 60 * 1000, // 5 minutes by default
7171
indexFrequencyMs: 24 * 60 * 60 * 1000, // 1 day by default
72-
lspRequestTimeoutMs: 5 * 60, // timeout a request over 30s
72+
lsp: {
73+
requestTimeoutMs: 5 * 60, // timeout a request over 30s
74+
detach: false,
75+
verbose: false,
76+
},
7377
repos: [],
7478
maxWorkspace: 5, // max workspace folder for each language server
7579
disableScheduler: true, // Temp option to disable all schedulers.

x-pack/plugins/code/server/__tests__/lsp_service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ describe('lsp_service tests', () => {
4848
queueTimeout: 60 * 60 * 1000, // 1 hour by default
4949
updateFreqencyMs: 5 * 60 * 1000, // 5 minutes by default
5050
indexFrequencyMs: 24 * 60 * 60 * 1000, // 1 day by default
51-
lspRequestTimeoutMs: 5 * 60, // timeout a request over 30s
51+
lsp: {
52+
requestTimeoutMs: 5 * 60, // timeout a request over 30s
53+
detach: false,
54+
verbose: false,
55+
},
5256
repos: [],
5357
maxWorkspace: 5, // max workspace folder for each language server
5458
disableScheduler: true, // Temp option to disable all schedulers.

x-pack/plugins/code/server/lsp/controller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class LanguageServerController implements ILanguageServerHandler {
4747
// a { lang -> server } map from above list
4848
private readonly languageServerMap: { [lang: string]: LanguageServerData };
4949
private log: Logger;
50-
private readonly detach: boolean = process.env.LSP_DETACH === 'true';
5150

5251
constructor(
5352
readonly options: ServerOptions,
@@ -62,7 +61,7 @@ export class LanguageServerController implements ILanguageServerHandler {
6261
builtinWorkspaceFolders: def.builtinWorkspaceFolders,
6362
languages: def.languages,
6463
maxWorkspace: options.maxWorkspace,
65-
launcher: new def.launcher(this.targetHost, this.detach, options, loggerFactory),
64+
launcher: new def.launcher(this.targetHost, options, loggerFactory),
6665
}));
6766
this.languageServerMap = this.languageServers.reduce(
6867
(map, ls) => {
@@ -241,7 +240,7 @@ export class LanguageServerController implements ILanguageServerHandler {
241240
const ls = this.languageServerMap[lang];
242241
if (ls) {
243242
if (
244-
!this.detach &&
243+
!this.options.lsp.detach &&
245244
this.installManager.status(ls.definition) !== LanguageServerStatus.READY
246245
) {
247246
throw new ResponseError(

x-pack/plugins/code/server/lsp/go_launcher.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class GoLauncher implements ILanguageServerLauncher {
1414
private isRunning: boolean = false;
1515
constructor(
1616
readonly targetHost: string,
17-
readonly detach: boolean,
1817
readonly options: ServerOptions,
1918
readonly loggerFactory: LoggerFactory
2019
) {}
@@ -26,7 +25,7 @@ export class GoLauncher implements ILanguageServerLauncher {
2625
const port = 2091;
2726

2827
const log = this.loggerFactory.getLogger(['code', `go@${this.targetHost}:${port}`]);
29-
const proxy = new LanguageServerProxy(port, this.targetHost, log);
28+
const proxy = new LanguageServerProxy(port, this.targetHost, log, this.options.lsp);
3029

3130
log.info('Detach mode, expected langserver launch externally');
3231
proxy.onConnected(() => {

x-pack/plugins/code/server/lsp/java_launcher.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class JavaLauncher implements ILanguageServerLauncher {
2121
private isRunning: boolean = false;
2222
constructor(
2323
readonly targetHost: string,
24-
readonly detach: boolean,
2524
readonly options: ServerOptions,
2625
readonly loggerFactory: LoggerFactory
2726
) {}
@@ -32,13 +31,13 @@ export class JavaLauncher implements ILanguageServerLauncher {
3231
public async launch(builtinWorkspace: boolean, maxWorkspace: number, installationPath: string) {
3332
let port = 2090;
3433

35-
if (!this.detach) {
34+
if (!this.options) {
3635
port = await getPort();
3736
}
3837
const log = this.loggerFactory.getLogger(['code', `java@${this.targetHost}:${port}`]);
39-
const proxy = new LanguageServerProxy(port, this.targetHost, log);
38+
const proxy = new LanguageServerProxy(port, this.targetHost, log, this.options.lsp);
4039
proxy.awaitServerConnection();
41-
if (this.detach) {
40+
if (this.options.lsp.detach) {
4241
// detach mode
4342
proxy.onConnected(() => {
4443
this.isRunning = true;

x-pack/plugins/code/server/lsp/language_server_launcher.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const tmpDataPath = fs.mkdtempSync(path.join(os.tmpdir(), 'code_test'));
2020
const options: ServerOptions = {
2121
workspacePath: `${tmpDataPath}/workspace`,
2222
jdtWorkspacePath: `${tmpDataPath}/jdt`,
23+
// @ts-ignore
24+
lsp: {
25+
detach: false,
26+
},
2327
};
2428

2529
beforeAll(async () => {
@@ -40,13 +44,7 @@ function delay(seconds: number) {
4044
}
4145

4246
test('typescript language server could be shutdown', async () => {
43-
// @ts-ignore
44-
const tsLauncher = new TypescriptServerLauncher(
45-
'localhost',
46-
false,
47-
options,
48-
new ConsoleLoggerFactory()
49-
);
47+
const tsLauncher = new TypescriptServerLauncher('localhost', options, new ConsoleLoggerFactory());
5048
const proxy = await tsLauncher.launch(true, 1, TYPESCRIPT.embedPath!);
5149
await proxy.initialize(options.workspacePath);
5250
await delay(2);

x-pack/plugins/code/server/lsp/language_server_launcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export interface ILanguageServerLauncher {
2020
export interface LauncherConstructor {
2121
new (
2222
targetHost: string,
23-
detach: boolean,
2423
options: ServerOptions,
2524
loggerFactory: LoggerFactory
2625
): ILanguageServerLauncher;

0 commit comments

Comments
 (0)