Skip to content

Commit 56be0ca

Browse files
fbriconrgrunber
authored andcommitted
Enable javac-based compilation.
Signed-off-by: Fred Bricon <[email protected]>
1 parent 973f3d1 commit 56be0ca

File tree

9 files changed

+87
-7
lines changed

9 files changed

+87
-7
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- name: Set Up Java
8282
uses: actions/setup-java@v4
8383
with:
84-
java-version: '17'
84+
java-version: '23'
8585
distribution: 'adopt'
8686
- name: Build JDT-LS
8787
if: "${{ inputs.JDT_LS_VERSION == '' }}"

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ The following settings are supported:
254254
- Call Hierarchy
255255
- Workspace Symbols
256256

257+
New in 1.36.0
258+
* `java.jdt.ls.javac.enabled`: [Experimental] Specify whether to enable Javac-based compilation in the language server. Requires running this extension with Java 23. Defaults to `false`.
259+
* `java.completion.engine`: [Experimental] Select code completion engine. Defaults to `ecj`.
260+
257261
Semantic Highlighting
258262
===============
259263
[Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings).

USAGE_DATA.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ vscode-java has opt-in telemetry collection, provided by [vscode-redhat-telemetr
1919
* Errors relating to running the language server, such as the message & stacktrace
2020
* Whether there is a mismatch between the project's requested source level, and the JDK used for the project (eg. true)
2121
* Information about the following settings. In the case of settings that store a well defined value (eg. path/url/string), we simply collect whether the setting has been set.
22-
* `java.settings.url`, `java.format.settings.url`, `java.quickfix.showAt`, `java.symbols.includeSourceMethodDeclarations`, `java.completion.collapseCompletionItems`, `java.completion.guessMethodArguments`, `java.completion.postfix.enabled`, `java.cleanup.actionsOnSave`, `java.sharedIndexes.enabled`, `java.inlayHints.parameterNames.enabled`, `java.server.launchMode`, `java.autobuild.enabled`
22+
* `java.settings.url`, `java.format.settings.url`, `java.quickfix.showAt`, `java.symbols.includeSourceMethodDeclarations`, `java.completion.collapseCompletionItems`, `java.completion.guessMethodArguments`, `java.completion.postfix.enabled`, `java.cleanup.actionsOnSave`, `java.sharedIndexes.enabled`, `java.inlayHints.parameterNames.enabled`, `java.server.launchMode`, `java.autobuild.enabled`, `java.jdt.ls.javac.enabled`
2323
* The extension name and the choice made when a recommendation to install a 3rd party extension is proposed
2424
* The name of Java commands being manually executed, and any resulting errors
25-
* The number of results (eg. 20), whether an error occured (eg. false), and duration (in milliseconds) when code assist is activated
25+
* The number of results (eg. 20), whether an error occured (eg. false), engine type (eg. 'ecj', 'dom') and duration (in milliseconds) when code assist is activated
2626
* Whether the language server ran out of memory and the maximum allocated memory at which that occured (eg. 200m)
2727

2828
## What's included in the general telemetry data

package.json

+27-1
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/extension.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ export function registerCodeCompletionTelemetryListener() {
12031203
resultLength: traceEvent.resultLength || 0,
12041204
error: !!traceEvent.error,
12051205
fromSyntaxServer: !!traceEvent.fromSyntaxServer,
1206+
engine: getJavaConfiguration().get('completion.engine'),
12061207
};
12071208
return Telemetry.sendTelemetry(Telemetry.COMPLETION_EVENT, props);
12081209
}

src/javaServerStarter.ts

+34-1
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

+2-1
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

+3-1
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) {

src/utils.ts

+13
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ export async function getJavaConfig(javaHome: string) {
245245
break;
246246
}
247247

248+
const javacSupport = javaConfig.jdt.ls.javac.enabled;
249+
switch (javacSupport) {
250+
case "on":
251+
javaConfig.jdt.ls.javac.enabled = true;
252+
break;
253+
case "off":
254+
javaConfig.jdt.ls.javac.enabled = false;
255+
break;
256+
default:
257+
javaConfig.jdt.ls.javac.enabled = false;
258+
break;
259+
}
260+
248261
if (javaConfig.completion.matchCase === "auto") {
249262
javaConfig.completion.matchCase = "firstLetter";
250263
}

0 commit comments

Comments
 (0)