Skip to content

Commit 7df558d

Browse files
Pengcheng Xuzfy0701
authored andcommitted
[Code] Add options to disable maven/gradle importer and autobuild (#33240)
* [Code] Add options to disable maven/gradle importer and autobuild * [Code] rename option to codeSecurity * [Code] Add initial options to request expander
1 parent bda74aa commit 7df558d

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

x-pack/plugins/code/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export const code = (kibana: any) =>
5151
verbose: Joi.boolean().default(false),
5252
}).default(),
5353
repos: Joi.array().default([]),
54+
codeSecurity: Joi.object({
55+
enableMavenImport: Joi.boolean().default(true),
56+
enableGradleImport: Joi.boolean().default(true),
57+
}).default(),
5458
maxWorkspace: Joi.number().default(5), // max workspace folder for each language server
5559
disableScheduler: Joi.boolean().default(true), // Temp option to disable all schedulers.
5660
enableGlobalReference: Joi.boolean().default(false), // Global reference as optional feature for now

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ export class JavaLauncher implements ILanguageServerLauncher {
6969
proxy.listen();
7070
return new Promise<RequestExpander>(resolve => {
7171
proxy.onConnected(() => {
72-
resolve(new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options));
72+
resolve(
73+
new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options, {
74+
settings: {
75+
'java.import.gradle.enabled': this.options.codeSecurity.enableGradleImport,
76+
'java.import.maven.enabled': this.options.codeSecurity.enableMavenImport,
77+
'java.autobuild.enabled': false,
78+
},
79+
})
80+
);
7381
});
7482
});
7583
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export class LanguageServerProxy implements ILanguageServerHandler {
100100
}
101101
public async initialize(
102102
clientCapabilities: ClientCapabilities,
103-
workspaceFolders: [WorkspaceFolder]
103+
workspaceFolders: [WorkspaceFolder],
104+
initOptions?: object
104105
): Promise<InitializeResult> {
105106
const clientConn = await this.connect();
106107
const rootUri = workspaceFolders[0].uri;
@@ -110,15 +111,20 @@ export class LanguageServerProxy implements ILanguageServerHandler {
110111
rootUri,
111112
capabilities: clientCapabilities,
112113
};
113-
return await clientConn.sendRequest('initialize', params).then(r => {
114-
this.logger.info(`initialized at ${rootUri}`);
114+
return await clientConn
115+
.sendRequest(
116+
'initialize',
117+
initOptions ? { ...params, initializationOptions: initOptions } : params
118+
)
119+
.then(r => {
120+
this.logger.info(`initialized at ${rootUri}`);
115121

116-
// @ts-ignore
117-
// TODO fix this
118-
clientConn.sendNotification(InitializedNotification.type, {});
119-
this.initialized = true;
120-
return r as InitializeResult;
121-
});
122+
// @ts-ignore
123+
// TODO fix this
124+
clientConn.sendNotification(InitializedNotification.type, {});
125+
this.initialized = true;
126+
return r as InitializeResult;
127+
});
122128
}
123129

124130
public listen() {

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export class RequestExpander implements ILanguageServerHandler {
5454
proxy: LanguageServerProxy,
5555
readonly builtinWorkspace: boolean,
5656
readonly maxWorkspace: number,
57-
readonly serverOptions: ServerOptions
57+
readonly serverOptions: ServerOptions,
58+
readonly initialOptions?: object
5859
) {
5960
this.proxy = proxy;
6061
this.handle = this.handle.bind(this);
@@ -144,12 +145,16 @@ export class RequestExpander implements ILanguageServerHandler {
144145
}
145146

146147
private async sendInitRequest(workspacePath: string) {
147-
return await this.proxy.initialize({}, [
148-
{
149-
name: workspacePath,
150-
uri: `file://${workspacePath}`,
151-
},
152-
]);
148+
return await this.proxy.initialize(
149+
{},
150+
[
151+
{
152+
name: workspacePath,
153+
uri: `file://${workspacePath}`,
154+
},
155+
],
156+
this.initialOptions
157+
);
153158
}
154159

155160
private handle() {

x-pack/plugins/code/server/server_options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export interface LspOptions {
1212
detach: boolean;
1313
verbose: boolean;
1414
}
15+
16+
export interface CodeSecurityOptions {
17+
enableMavenImport: boolean;
18+
enableGradleImport: boolean;
19+
}
20+
1521
export class ServerOptions {
1622
public readonly workspacePath = resolve(this.config.get('path.data'), 'code/workspace');
1723

@@ -39,6 +45,8 @@ export class ServerOptions {
3945

4046
public readonly lsp: LspOptions = this.options.lsp;
4147

48+
public readonly codeSecurity: CodeSecurityOptions = this.options.codeSecurity;
49+
4250
public readonly repoConfigs: RepoConfigs = (this.options.repos as RepoConfig[]).reduce(
4351
(previous, current) => {
4452
previous[current.repo] = current;

0 commit comments

Comments
 (0)