Skip to content

Commit

Permalink
Adding support for eclipse.jdt.ls
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Jul 12, 2024
1 parent 534a665 commit 87e4a4d
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 20 deletions.
18 changes: 10 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Linked packages are problematic during build, npm i during start will fix it
node_modules/@typefox/monaco-editor-react
node_modules/example-client-vite
node_modules/example-client-webpack
node_modules/monaco-languageclient
node_modules/monaco-editor-wrapper
node_modules/monaco-languageclient-examples
node_modules/vscode-ws-jsonrpc
## Linked packages are problematic during build, npm i during start will fix it
#node_modules/@typefox/monaco-editor-react
#node_modules/example-client-vite
#node_modules/example-client-webpack
#node_modules/monaco-languageclient
#node_modules/monaco-editor-wrapper
#node_modules/monaco-languageclient-examples
#node_modules/vscode-ws-jsonrpc

node_modules
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ <h3>Python</h3>
Please execute <b><code>npm run start:example:server:python</code></b> beforehand:<br>
<a href="./packages/examples/python.html">Python Language Client & Pyright Language Server (Web Socket)</a><br>

<h3>Java</h3>
Requires docker. Please execute <b><code>docker compose -f ./packages/examples/resources/eclipse.jdt.ls/docker-compose.yml up -d</code></b> beforehand:<br>
<a href="./packages/examples/eclipse.jdt.ls.html">Java Language Client & Language Server (Web Socket)</a>
<br>

<h3>Groovy</h3>
Requires docker. Please execute <b><code>docker compose -f ./packages/examples/resources/groovy/docker-compose.yml up -d</code></b> beforehand:<br>
<a href="./packages/examples/groovy.html">Groovy Language Client & Language Server (Web Socket)</a>
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"start:example:server:json": "npm run start:server:json --workspace packages/examples",
"start:example:server:python": "npm run start:server:python --workspace packages/examples",
"start:example:server:groovy": "npm run start:server:groovy --workspace packages/examples",
"start:example:server:jdtls": "npm run start:server:jdtls --workspace packages/examples",
"release:prepare": "npm run reset:repo && npm ci && npm run build && npm run lint && npm run test:run",
"reset:repo": "git clean -f -X -d",
"test": "vitest",
Expand Down
2 changes: 2 additions & 0 deletions packages/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
resources/groovy/external
resources/eclipse.jdt.ls/ls
resources/eclipse.jdt.ls/*.tar.gz
resources/vsix
24 changes: 24 additions & 0 deletions packages/examples/eclipse.jdt.ls.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>

<head>
<title>Java Language Client & Language Server (Web Socket)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>

<body>
<h2>Java Language Client & Language Server (Web Socket)</h2>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module">
import { configureMonacoWorkers, runEclipseJdtLsClient } from "./src/eclipse.jdt.ls/client/main.ts";

configureMonacoWorkers();
runEclipseJdtLsClient();
</script>
</body>

</html>
4 changes: 3 additions & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@codingame/monaco-vscode-keybindings-service-override": "~7.0.3",
"@codingame/monaco-vscode-lifecycle-service-override": "~7.0.3",
"@codingame/monaco-vscode-localization-service-override": "~7.0.3",
"@codingame/monaco-vscode-java-default-extension": "~7.0.3",
"@codingame/monaco-vscode-javascript-default-extension": "~7.0.3",
"@codingame/monaco-vscode-json-default-extension": "~7.0.3",
"@codingame/monaco-vscode-python-default-extension": "~7.0.3",
Expand Down Expand Up @@ -118,7 +119,8 @@
"build:bundle": "vite --config vite.bundle.config.ts build",
"start:server:json": "node --loader ts-node/esm src/json/server/direct.ts",
"start:server:python": "node --loader ts-node/esm src/python/server/direct.ts",
"start:server:groovy": "node --watch --loader ts-node/esm src/groovy/server/direct.ts",
"start:server:groovy": "node --watch --loader ts-node/esm src/groovy/server/direct.ts",
"start:server:jdtls": "vite-node src/eclipse.jdt.ls/server/direct.ts",
"langium:generate": "langium generate --file ./src/langium/statemachine/config/langium-config.json"
}
}
29 changes: 29 additions & 0 deletions packages/examples/resources/eclipse.jdt.ls/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM eclipse-temurin:17-jdk

ARG MLC_PATH=/home/mlc
ARG ECLIPSE_JDT_PATH=${MLC_PATH}/packages/examples/resources/eclipse.jdt.ls/ls
ARG JDT_TAR_URL=https://download.eclipse.org/jdtls/milestones/1.37.0/jdt-language-server-1.37.0-202406271335.tar.gz
ARG JDT_TAR_LOCAL=eclipse.jdt.ls.tar.gz

RUN apt update \
&& apt upgrade -y
RUN apt install -y wget

RUN curl https://get.volta.sh | bash
ENV VOLTA_FEATURE_PNPM=1
ENV VOLTA_HOME "/root/.volta"
ENV PATH "$VOLTA_HOME/bin:$PATH"
RUN volta install node@20

RUN mkdir -p ${MLC_PATH}

COPY ./ ${MLC_PATH}

RUN mkdir -p ${ECLIPSE_JDT_PATH} \
&& cd ${ECLIPSE_JDT_PATH} \
&& wget -O ${JDT_TAR_LOCAL} ${JDT_TAR_URL} \
&& tar -xzf ${JDT_TAR_LOCAL}

WORKDIR ${MLC_PATH}

CMD ["/bin/bash", "npm i && npm run start:example:server:jdtls"]
16 changes: 16 additions & 0 deletions packages/examples/resources/eclipse.jdt.ls/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
eclipsejdtls:
build:
dockerfile: ./packages/examples/resources/eclipse.jdt.ls/Dockerfile
context: ../../../..
environment:
- MLC_PATH=/home/mlc
- JDT_TAR_URL=https://download.eclipse.org/jdtls/milestones/1.37.0/jdt-language-server-1.37.0-202406271335.tar.gz
- JDT_TAR_LOCAL=eclipse.jdt.ls.tar.gz
command: [
"bash", "-c", "npm i && npm run start:example:server:jdtls"
]
ports:
- 30003:30003
working_dir: /home/mlc
container_name: eclipsejdtls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public static void main (String[] args) {
System.out.println("Hello World!");
}
18 changes: 10 additions & 8 deletions packages/examples/resources/groovy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
FROM gradle:7-jdk17-focal

ARG MLC_PATH=/home/gradle/mlc

RUN apt update \
&& apt upgrade -y \
&& apt install -y ca-certificates curl gnupg unzip

RUN mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt update \
&& apt install -y nodejs
RUN curl https://get.volta.sh | bash
ENV VOLTA_FEATURE_PNPM=1
ENV VOLTA_HOME "/root/.volta"
ENV PATH "$VOLTA_HOME/bin:$PATH"
RUN volta install node@20

RUN git clone https://github.com/GroovyLanguageServer/groovy-language-server \
&& cd groovy-language-server \
&& ./gradlew build \
&& cd ..

RUN mkdir -p /home/gradle/mlc
RUN mkdir -p ${MLC_PATH}

COPY ./ /home/gradle/mlc/
COPY ./ ${MLC_PATH}

WORKDIR /home/gradle/mlc
WORKDIR ${MLC_PATH}
2 changes: 0 additions & 2 deletions packages/examples/resources/groovy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
groovyls:
build:
Expand Down
86 changes: 86 additions & 0 deletions packages/examples/src/eclipse.jdt.ls/client/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import * as vscode from 'vscode';
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
// this is required syntax highlighting
import '@codingame/monaco-vscode-java-default-extension';
import { MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
import { RegisteredFileSystemProvider, RegisteredMemoryFile } from '@codingame/monaco-vscode-files-service-override';
import helloJavaCode from '../../../resources/eclipse.jdt.ls/workspace/hello.java?raw';
import { eclipseJdtLsConfig } from '../config';

export const configureMonacoWorkers = () => {
useWorkerFactory({
ignoreMapping: true,
workerLoaders: {
editorWorkerService: () => new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url), { type: 'module' }),
}
});
};

export const runEclipseJdtLsClient = () => {
const helloJavaUri = vscode.Uri.file(`${eclipseJdtLsConfig.basePath}/workspace/hello.java`);
const fileSystemProvider = new RegisteredFileSystemProvider(false);
fileSystemProvider.registerFile(new RegisteredMemoryFile(helloJavaUri, helloJavaCode));

const userConfig: UserConfig = {
wrapperConfig: {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
debugLogging: true
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: helloJavaCode,
uri: `${eclipseJdtLsConfig.basePath}/workspace/hello.java`
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active'
})
}
}
},
languageClientConfig: {
languageId: 'java',
options: {
$type: 'WebSocketUrl',
url: 'ws://localhost:30003/jdtls'
},
clientOptions: {
documentSelector: ['java'],
workspaceFolder: {
index: 0,
name: 'workspace',
uri: vscode.Uri.parse(`${eclipseJdtLsConfig.basePath}/workspace`)
},
},
}
};

const wrapper = new MonacoEditorLanguageClientWrapper();
const htmlElement = document.getElementById('monaco-editor-root');

try {
document.querySelector('#button-start')?.addEventListener('click', async () => {
await wrapper.dispose();
await wrapper.initAndStart(userConfig, htmlElement);
});
document.querySelector('#button-dispose')?.addEventListener('click', async () => {
await wrapper.dispose();
});
} catch (e) {
console.error(e);
}
};
9 changes: 9 additions & 0 deletions packages/examples/src/eclipse.jdt.ls/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */
export const eclipseJdtLsConfig = {
port: 30003,
path: '/jdtls',
basePath: '/home/mlc/packages/examples/resources/eclipse.jdt.ls'
};
8 changes: 8 additions & 0 deletions packages/examples/src/eclipse.jdt.ls/server/direct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import { runEclipseJdtLs } from './main.js';

runEclipseJdtLs();
40 changes: 40 additions & 0 deletions packages/examples/src/eclipse.jdt.ls/server/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import { runLanguageServer } from '../../common/node/language-server-runner.js';
import { LanguageName } from '../../common/node/server-commons.js';
import { eclipseJdtLsConfig } from '../config.js';

export const runEclipseJdtLs = () => {
;

Check failure on line 11 in packages/examples/src/eclipse.jdt.ls/server/main.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unnecessary semicolon
runLanguageServer({
serverName: 'Eclipse JDT LS',
pathName: eclipseJdtLsConfig.path,
serverPort: eclipseJdtLsConfig.port,
runCommand: LanguageName.java,
runCommandArgs: [
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product',
'-Dlog.level=ALL',
'-Xmx1G',
'--add-modules=ALL-SYSTEM',
'--add-opens',
'java.base/java.util=ALL-UNNAMED',
'--add-opens',
'java.base/java.lang=ALL-UNNAMED',
'-jar',
`${eclipseJdtLsConfig.basePath}/ls/plugins/org.eclipse.equinox.launcher_1.6.900.v20240613-2009.jar`,
'-configuration',
`${eclipseJdtLsConfig.basePath}/ls/config_linux`,
'-data',
`${eclipseJdtLsConfig.basePath}/workspace`
],
wsServerOptions: {
noServer: true,
perMessageDeflate: false
}
});
};
2 changes: 1 addition & 1 deletion packages/examples/src/groovy/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const configureMonacoWorkers = () => {
};

const code = `package test.org;
import java.io.File ;
import java.io.File;
File file = new File("E:/Example.txt");
`;

Expand Down

0 comments on commit 87e4a4d

Please sign in to comment.