Skip to content
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
4 changes: 4 additions & 0 deletions x-pack/plugins/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const code = (kibana: any) =>
verbose: Joi.boolean().default(false),
}).default(),
repos: Joi.array().default([]),
codeSecurity: Joi.object({
enableMavenImport: Joi.boolean().default(true),
enableGradleImport: Joi.boolean().default(true),
}).default(),
maxWorkspace: Joi.number().default(5), // max workspace folder for each language server
disableScheduler: Joi.boolean().default(true), // Temp option to disable all schedulers.
enableGlobalReference: Joi.boolean().default(false), // Global reference as optional feature for now
Expand Down
10 changes: 9 additions & 1 deletion x-pack/plugins/code/server/lsp/java_launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export class JavaLauncher implements ILanguageServerLauncher {
proxy.listen();
return new Promise<RequestExpander>(resolve => {
proxy.onConnected(() => {
resolve(new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options));
resolve(
new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options, {
settings: {
'java.import.gradle.enabled': this.options.codeSecurity.enableGradleImport,
'java.import.maven.enabled': this.options.codeSecurity.enableMavenImport,
'java.autobuild.enabled': false,
},
})
);
});
});
}
Expand Down
24 changes: 15 additions & 9 deletions x-pack/plugins/code/server/lsp/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class LanguageServerProxy implements ILanguageServerHandler {
}
public async initialize(
clientCapabilities: ClientCapabilities,
workspaceFolders: [WorkspaceFolder]
workspaceFolders: [WorkspaceFolder],
initOptions?: object
): Promise<InitializeResult> {
const clientConn = await this.connect();
const rootUri = workspaceFolders[0].uri;
Expand All @@ -110,15 +111,20 @@ export class LanguageServerProxy implements ILanguageServerHandler {
rootUri,
capabilities: clientCapabilities,
};
return await clientConn.sendRequest('initialize', params).then(r => {
this.logger.info(`initialized at ${rootUri}`);
return await clientConn
.sendRequest(
'initialize',
initOptions ? { ...params, initializationOptions: initOptions } : params
)
.then(r => {
this.logger.info(`initialized at ${rootUri}`);

// @ts-ignore
// TODO fix this
clientConn.sendNotification(InitializedNotification.type, {});
this.initialized = true;
return r as InitializeResult;
});
// @ts-ignore
// TODO fix this
clientConn.sendNotification(InitializedNotification.type, {});
this.initialized = true;
return r as InitializeResult;
});
}

public listen() {
Expand Down
19 changes: 12 additions & 7 deletions x-pack/plugins/code/server/lsp/request_expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export class RequestExpander implements ILanguageServerHandler {
proxy: LanguageServerProxy,
readonly builtinWorkspace: boolean,
readonly maxWorkspace: number,
readonly serverOptions: ServerOptions
readonly serverOptions: ServerOptions,
readonly initialOptions?: object
) {
this.proxy = proxy;
this.handle = this.handle.bind(this);
Expand Down Expand Up @@ -144,12 +145,16 @@ export class RequestExpander implements ILanguageServerHandler {
}

private async sendInitRequest(workspacePath: string) {
return await this.proxy.initialize({}, [
{
name: workspacePath,
uri: `file://${workspacePath}`,
},
]);
return await this.proxy.initialize(
{},
[
{
name: workspacePath,
uri: `file://${workspacePath}`,
},
],
this.initialOptions
);
}

private handle() {
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/code/server/server_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export interface LspOptions {
detach: boolean;
verbose: boolean;
}

export interface CodeSecurityOptions {
enableMavenImport: boolean;
enableGradleImport: boolean;
}

export class ServerOptions {
public readonly workspacePath = resolve(this.config.get('path.data'), 'code/workspace');

Expand Down Expand Up @@ -39,6 +45,8 @@ export class ServerOptions {

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

public readonly codeSecurity: CodeSecurityOptions = this.options.codeSecurity;

public readonly repoConfigs: RepoConfigs = (this.options.repos as RepoConfig[]).reduce(
(previous, current) => {
previous[current.repo] = current;
Expand Down