Skip to content

Commit

Permalink
WIP: enable javac-based compilation
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jul 10, 2024
1 parent 38c8b58 commit 51ef99b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
28 changes: 27 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@
"scope": "window",
"order": 90
},
"java.jdt.ls.javac.enabled": {
"type": "string",
"enum": [
"on",
"off"
],
"default": "off",
"markdownDescription": "[Experimental] Specify whether to enable Javac-based compilation in the language server. Requires running this extension with Java 23",
"scope": "window",
"order": 95
},
"java.trace.server": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1003,6 +1014,21 @@
"scope": "window",
"order": 10
},
"java.completion.engine": {
"type": "string",
"default": "ecj",
"description": "[Experimental] Select code completion engine",
"scope": "window",
"enum": [
"ecj",
"dom"
],
"markdownEnumDescriptions": [
"Use ECJ-based code completion engine (default)",
"Use (highly experimental) JDT DOM-based code completion engine (requires `java.jdt.ls.javac.enabled` to be `on`)"
],
"order": 1000
},
"java.completion.postfix.enabled": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -1903,4 +1929,4 @@
},
"segmentWriteKey": "Y7Y5Xk8dKEhVZHTmAkFZkqgdN4d7c4lt",
"segmentWriteKeyDebug": "BflPll7uuKOCm3y0g7JpfXLVBVFBivDE"
}
}
33 changes: 32 additions & 1 deletion src/javaServerStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,38 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
// See https://github.com/redhat-developer/vscode-java/issues/2264
// It requires the internal API sun.nio.fs.WindowsFileAttributes.isDirectoryLink() to check if a Windows directory is symlink.
'--add-opens',
'java.base/sun.nio.fs=ALL-UNNAMED');
'java.base/sun.nio.fs=ALL-UNNAMED'
);

const javacEnabled = 'on' === getJavaConfiguration().get('jdt.ls.javac.enabled');
if (javacEnabled) {
// Javac flags
params.push(
'--add-opens',
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'-DICompilationUnitResolver=org.eclipse.jdt.core.dom.JavacCompilationUnitResolver',
'-DCompilationUnit.DOM_BASED_OPERATIONS=true',
'-DAbstractImageBuilder.compilerFactory=org.eclipse.jdt.internal.javac.JavacCompilerFactory'
);

if('dom' === getJavaConfiguration().get('java.completion.engine')){
params.push('-DCompilationUnit.codeComplete.DOM_BASED_OPERATIONS=true');
};
}

params.push('-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
Expand Down
2 changes: 1 addition & 1 deletion src/requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { logger } from './log';
import { checkJavaPreferences } from './settings';
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';

const REQUIRED_JDK_VERSION = 17;
const REQUIRED_JDK_VERSION = 23;
/* eslint-disable @typescript-eslint/naming-convention */
export interface RequirementsData {
tooling_jre: string;
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: Work
|| hasConfigKeyChanged('jdt.ls.vmargs', oldConfig, newConfig)
|| hasConfigKeyChanged('server.launchMode', oldConfig, newConfig)
|| hasConfigKeyChanged('sharedIndexes.location', oldConfig, newConfig)
|| hasConfigKeyChanged('transport', oldConfig, newConfig);
|| hasConfigKeyChanged('transport', oldConfig, newConfig)
|| hasConfigKeyChanged('jdt.ls.javac.enabled', oldConfig, newConfig)
|| hasConfigKeyChanged('java.completion.engine', oldConfig, newConfig);
}

function hasConfigKeyChanged(key, oldConfig, newConfig) {
Expand Down

0 comments on commit 51ef99b

Please sign in to comment.