Skip to content

Commit c23569c

Browse files
committed
Enable javac-based compilation
Signed-off-by: Fred Bricon <[email protected]>
1 parent 973f3d1 commit c23569c

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

package.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,17 @@
409409
"scope": "window",
410410
"order": 90
411411
},
412+
"java.jdt.ls.javac.enabled": {
413+
"type": "string",
414+
"enum": [
415+
"on",
416+
"off"
417+
],
418+
"default": "off",
419+
"markdownDescription": "[Experimental] Specify whether to enable Javac-based compilation in the language server. Requires running this extension with Java 23",
420+
"scope": "window",
421+
"order": 95
422+
},
412423
"java.trace.server": {
413424
"type": "string",
414425
"enum": [
@@ -1009,6 +1020,21 @@
10091020
"scope": "window",
10101021
"order": 10
10111022
},
1023+
"java.completion.engine": {
1024+
"type": "string",
1025+
"default": "ecj",
1026+
"description": "[Experimental] Select code completion engine",
1027+
"scope": "window",
1028+
"enum": [
1029+
"ecj",
1030+
"dom"
1031+
],
1032+
"markdownEnumDescriptions": [
1033+
"Use ECJ-based code completion engine (default)",
1034+
"Use (highly experimental) JDT DOM-based code completion engine (requires `java.jdt.ls.javac.enabled` to be `on`)"
1035+
],
1036+
"order": 1000
1037+
},
10121038
"java.completion.postfix.enabled": {
10131039
"type": "boolean",
10141040
"default": true,
@@ -1939,4 +1965,4 @@
19391965
},
19401966
"segmentWriteKey": "Y7Y5Xk8dKEhVZHTmAkFZkqgdN4d7c4lt",
19411967
"segmentWriteKeyDebug": "BflPll7uuKOCm3y0g7JpfXLVBVFBivDE"
1942-
}
1968+
}

src/javaServerStarter.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,40 @@ 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+
'--add-opens',
131+
'jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets.snippet=ALL-UNNAMED --add-opens jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets=ALL-UNNAMED',
132+
'-DICompilationUnitResolver=org.eclipse.jdt.core.dom.JavacCompilationUnitResolver',
133+
'-DCompilationUnit.DOM_BASED_OPERATIONS=true',
134+
'-DAbstractImageBuilder.compilerFactory=org.eclipse.jdt.internal.javac.JavacCompilerFactory'
135+
);
136+
137+
if('dom' === getJavaConfiguration().get('completion.engine')){
138+
params.push('-DCompilationUnit.codeComplete.DOM_BASED_OPERATIONS=true');
139+
};
140+
}
108141

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

src/requirements.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { Commands } from './commands';
99
import { logger } from './log';
1010
import { checkJavaPreferences } from './settings';
1111
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
12+
import { getJavaConfiguration } from './utils';
1213

13-
const REQUIRED_JDK_VERSION = 17;
1414
/* eslint-disable @typescript-eslint/naming-convention */
1515
export interface RequirementsData {
1616
tooling_jre: string;
@@ -41,6 +41,7 @@ export async function resolveRequirements(context: ExtensionContext): Promise<Re
4141
const preferenceName = javaPreferences.preference;
4242
let javaHome = javaPreferences.javaHome;
4343
let javaVersion: number = 0;
44+
const REQUIRED_JDK_VERSION = ('on' === getJavaConfiguration().get('jdt.ls.javac.enabled'))?23:17;
4445
if (javaHome) {
4546
const source = `${preferenceName} variable defined in ${env.appName} settings`;
4647
javaHome = expandHomeDir(javaHome);

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('completion.engine', oldConfig, newConfig);
141143
}
142144

143145
function hasConfigKeyChanged(key, oldConfig, newConfig) {

0 commit comments

Comments
 (0)