Skip to content

Commit e4bb0c8

Browse files
committed
WIP: enable javac-based compilation
Signed-off-by: Fred Bricon <[email protected]>
1 parent ab29322 commit e4bb0c8

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

package.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,17 @@
404404
"scope": "window",
405405
"order": 90
406406
},
407+
"java.jdt.ls.javac.enabled": {
408+
"type": "string",
409+
"enum": [
410+
"on",
411+
"off"
412+
],
413+
"default": "off",
414+
"markdownDescription": "[Experimental] Specify whether to enable Javac-based compilation in the language server. Requires running this extension with Java 23",
415+
"scope": "window",
416+
"order": 95
417+
},
407418
"java.trace.server": {
408419
"type": "string",
409420
"enum": [
@@ -1003,6 +1014,21 @@
10031014
"scope": "window",
10041015
"order": 10
10051016
},
1017+
"java.completion.engine": {
1018+
"type": "string",
1019+
"default": "ecj",
1020+
"description": "[Experimental] Select code completion engine",
1021+
"scope": "window",
1022+
"enum": [
1023+
"ecj",
1024+
"dom"
1025+
],
1026+
"markdownEnumDescriptions": [
1027+
"Use ECJ-based code completion engine (default)",
1028+
"Use (highly experimental) JDT DOM-based code completion engine (requires `java.jdt.ls.javac.enabled` to be `on`)"
1029+
],
1030+
"order": 1000
1031+
},
10061032
"java.completion.postfix.enabled": {
10071033
"type": "boolean",
10081034
"default": true,
@@ -1912,4 +1938,4 @@
19121938
},
19131939
"segmentWriteKey": "Y7Y5Xk8dKEhVZHTmAkFZkqgdN4d7c4lt",
19141940
"segmentWriteKeyDebug": "BflPll7uuKOCm3y0g7JpfXLVBVFBivDE"
1915-
}
1941+
}

src/javaServerStarter.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,38 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
104104
// See https://github.com/redhat-developer/vscode-java/issues/2264
105105
// It requires the internal API sun.nio.fs.WindowsFileAttributes.isDirectoryLink() to check if a Windows directory is symlink.
106106
'--add-opens',
107-
'java.base/sun.nio.fs=ALL-UNNAMED');
107+
'java.base/sun.nio.fs=ALL-UNNAMED'
108+
);
109+
110+
const javacEnabled = 'on' === getJavaConfiguration().get('jdt.ls.javac.enabled');
111+
if (javacEnabled) {
112+
// Javac flags
113+
params.push(
114+
'--add-opens',
115+
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
116+
'--add-opens',
117+
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
118+
'--add-opens',
119+
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
120+
'--add-opens',
121+
'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
122+
'--add-opens',
123+
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
124+
'--add-opens',
125+
'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
126+
'--add-opens',
127+
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
128+
'--add-opens',
129+
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
130+
'-DICompilationUnitResolver=org.eclipse.jdt.core.dom.JavacCompilationUnitResolver',
131+
'-DCompilationUnit.DOM_BASED_OPERATIONS=true',
132+
'-DAbstractImageBuilder.compilerFactory=org.eclipse.jdt.internal.javac.JavacCompilerFactory'
133+
);
134+
135+
if('dom' === getJavaConfiguration().get('java.completion.engine')){
136+
params.push('-DCompilationUnit.codeComplete.DOM_BASED_OPERATIONS=true');
137+
};
138+
}
108139

109140
params.push('-Declipse.application=org.eclipse.jdt.ls.core.id1',
110141
'-Dosgi.bundles.defaultStartLevel=4',

src/requirements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { logger } from './log';
1010
import { checkJavaPreferences } from './settings';
1111
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
1212

13-
const REQUIRED_JDK_VERSION = 17;
13+
const REQUIRED_JDK_VERSION = 23;
1414
/* eslint-disable @typescript-eslint/naming-convention */
1515
export interface RequirementsData {
1616
tooling_jre: string;

src/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: Work
137137
|| hasConfigKeyChanged('server.launchMode', oldConfig, newConfig)
138138
|| hasConfigKeyChanged('sharedIndexes.location', oldConfig, newConfig)
139139
|| hasConfigKeyChanged('transport', oldConfig, newConfig)
140-
|| hasConfigKeyChanged('diagnostic.filter', oldConfig, newConfig);
140+
|| hasConfigKeyChanged('diagnostic.filter', oldConfig, newConfig)
141+
|| hasConfigKeyChanged('jdt.ls.javac.enabled', oldConfig, newConfig)
142+
|| hasConfigKeyChanged('java.completion.engine', oldConfig, newConfig);
141143
}
142144

143145
function hasConfigKeyChanged(key, oldConfig, newConfig) {

0 commit comments

Comments
 (0)