Skip to content

Commit

Permalink
Update java support to latest jdt.ls
Browse files Browse the repository at this point in the history
Updates the server to the latest snapshot which includes
a fix that is required for Theia. Also changes the way
language server is started to adjust to the changes
on environment variables.

fixes eclipse-theia#1068

Signed-off-by: Gorkem Ercan <[email protected]>
  • Loading branch information
gorkem committed Mar 27, 2018
1 parent e41a77e commit 4951131
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 88 deletions.
Binary file modified packages/java/download/jdt-language-server-latest.tar.gz
Binary file not shown.
64 changes: 32 additions & 32 deletions packages/java/src/browser/java-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@
import { injectable, inject } from "inversify";
import { CommandService } from "@theia/core/lib/common";
import {
Window, ILanguageClient, BaseLanguageClientContribution, Workspace, Languages, LanguageClientFactory
Window, ILanguageClient, BaseLanguageClientContribution, Workspace, Languages, LanguageClientFactory
} from '@theia/languages/lib/browser';
import { JAVA_LANGUAGE_ID, JAVA_LANGUAGE_NAME } from '../common';
import { ActionableNotification, ActionableMessage } from "./java-protocol";

@injectable()
export class JavaClientContribution extends BaseLanguageClientContribution {

readonly id = JAVA_LANGUAGE_ID;
readonly name = JAVA_LANGUAGE_NAME;

constructor(
@inject(Workspace) protected readonly workspace: Workspace,
@inject(Languages) protected readonly languages: Languages,
@inject(LanguageClientFactory) protected readonly languageClientFactory: LanguageClientFactory,
@inject(Window) protected readonly window: Window,
@inject(CommandService) protected readonly commandService: CommandService
) {
super(workspace, languages, languageClientFactory);
}

protected get globPatterns() {
return ['**/*.java', '**/pom.xml', '**/*.gradle'];
}

protected onReady(languageClient: ILanguageClient): void {
languageClient.onNotification(ActionableNotification.type, this.showActionableMessage.bind(this));
super.onReady(languageClient);
}

protected showActionableMessage(message: ActionableMessage): void {
const items = message.commands || [];
this.window.showMessage(message.severity, message.message, ...items).then(command => {
if (command) {
const args = command.arguments || [];
this.commandService.executeCommand(command.command, ...args);
}
});
}
readonly id = JAVA_LANGUAGE_ID;
readonly name = JAVA_LANGUAGE_NAME;

constructor(
@inject(Workspace) protected readonly workspace: Workspace,
@inject(Languages) protected readonly languages: Languages,
@inject(LanguageClientFactory) protected readonly languageClientFactory: LanguageClientFactory,
@inject(Window) protected readonly window: Window,
@inject(CommandService) protected readonly commandService: CommandService
) {
super(workspace, languages, languageClientFactory);
}

protected get globPatterns() {
return ['**/*.java', '**/pom.xml', '**/*.gradle'];
}

protected onReady(languageClient: ILanguageClient): void {
languageClient.onNotification(ActionableNotification.type, this.showActionableMessage.bind(this));
super.onReady(languageClient);
}

protected showActionableMessage(message: ActionableMessage): void {
const items = message.commands || [];
this.window.showMessage(message.severity, message.message, ...items).then(command => {
if (command) {
const args = command.arguments || [];
this.commandService.executeCommand(command.command, ...args);
}
});
}

}
14 changes: 7 additions & 7 deletions packages/java/src/browser/monaco-contribution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { JAVA_LANGUAGE_ID } from '../../common';
import { JAVA_LANGUAGE_ID, JAVA_LANGUAGE_NAME } from '../../common';
import { configuration, monarchLanguage } from "./java-monaco-language";

monaco.languages.register({
id: JAVA_LANGUAGE_ID,
extensions: ['.java', '.jav', '.class'],
aliases: ['Java', 'java'],
mimetypes: ['text/x-java-source', 'text/x-java'],
id: JAVA_LANGUAGE_ID,
extensions: ['.java', '.jav', '.class'],
aliases: [JAVA_LANGUAGE_NAME, 'java'],
mimetypes: ['text/x-java-source', 'text/x-java'],
});

monaco.languages.onLanguage(JAVA_LANGUAGE_ID, () => {
monaco.languages.setLanguageConfiguration(JAVA_LANGUAGE_ID, configuration);
monaco.languages.setMonarchTokensProvider(JAVA_LANGUAGE_ID, monarchLanguage);
monaco.languages.setLanguageConfiguration(JAVA_LANGUAGE_ID, configuration);
monaco.languages.setMonarchTokensProvider(JAVA_LANGUAGE_ID, monarchLanguage);
});
95 changes: 46 additions & 49 deletions packages/java/src/node/java-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,56 @@ configurations.set('linux', 'config_linux');
@injectable()
export class JavaContribution extends BaseLanguageServerContribution {

readonly id = JAVA_LANGUAGE_ID;
readonly name = JAVA_LANGUAGE_NAME;
readonly id = JAVA_LANGUAGE_ID;
readonly name = JAVA_LANGUAGE_NAME;

start(clientConnection: IConnection): void {
const serverPath = path.resolve(__dirname, 'server');
const jarPaths = glob.sync('**/plugins/org.eclipse.equinox.launcher_*.jar', { cwd: serverPath });
if (jarPaths.length === 0) {
throw new Error('The Java server launcher is not found.');
}
start(clientConnection: IConnection): void {
const serverPath = path.resolve(__dirname, 'server');
const jarPaths = glob.sync('**/plugins/org.eclipse.equinox.launcher_*.jar', { cwd: serverPath });
if (jarPaths.length === 0) {
throw new Error('The Java server launcher is not found.');
}

const jarPath = path.resolve(serverPath, jarPaths[0]);
const workspacePath = path.resolve(os.tmpdir(), '_ws_' + new Date().getTime());
const configuration = configurations.get(process.platform);
if (!configuration) {
throw new Error('Cannot find Java server configuration for ' + process.platform);
}
const configurationPath = path.resolve(serverPath, configuration);
const command = 'java';
const args = [
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product'
];
const jarPath = path.resolve(serverPath, jarPaths[0]);
const workspacePath = path.resolve(os.tmpdir(), '_ws_' + new Date().getTime());
const configuration = configurations.get(process.platform);
if (!configuration) {
throw new Error('Cannot find Java server configuration for ' + process.platform);
}
const configurationPath = path.resolve(serverPath, configuration);
const command = 'java';
const args = [
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product'
];

if (DEBUG_MODE) {
args.push(
'-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044',
'-Dlog.protocol=true',
'-Dlog.level=ALL'
);
}
if (DEBUG_MODE) {
args.push(
'-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044',
'-Dlog.protocol=true',
'-Dlog.level=ALL'
);
}

args.push(
'-jar', jarPath,
'-configuration', configurationPath,
'-data', workspacePath
);
args.push(
'-jar', jarPath,
'-configuration', configurationPath,
'-data', workspacePath
);

Promise.all([
this.startSocketServer(), this.startSocketServer()
]).then(servers => {
const [inServer, outServer] = servers;
const inSocket = this.accept(inServer);
const outSocket = this.accept(outServer);
Promise.all(
[this.startSocketServer()]
).then(servers => {
const [server] = servers;
const socket = this.accept(server);

this.logInfo('logs at ' + path.resolve(workspacePath, '.metadata', '.log'));
const env = Object.create(process.env);
env.STDIN_HOST = inServer.address().address;
env.STDIN_PORT = inServer.address().port;
env.STDOUT_HOST = outServer.address().address;
env.STDOUT_PORT = outServer.address().port;
this.createProcessSocketConnection(inSocket, outSocket, command, args, { env })
.then(serverConnection => this.forward(clientConnection, serverConnection));
});
}
this.logInfo('logs at ' + path.resolve(workspacePath, '.metadata', '.log'));
const env = Object.create(process.env);
env.CLIENT_HOST = server.address().address;
env.CLIENT_PORT = server.address().port;
this.createProcessSocketConnection(socket, socket, command, args, { env })
.then(serverConnection => this.forward(clientConnection, serverConnection));
});
}
}

0 comments on commit 4951131

Please sign in to comment.