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 Sep 11, 2024
1 parent 8923a98 commit e68cd9f
Show file tree
Hide file tree
Showing 4 changed files with 66 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 @@ -1912,4 +1938,4 @@
},
"segmentWriteKey": "Y7Y5Xk8dKEhVZHTmAkFZkqgdN4d7c4lt",
"segmentWriteKeyDebug": "BflPll7uuKOCm3y0g7JpfXLVBVFBivDE"
}
}
35 changes: 34 additions & 1 deletion src/javaServerStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,40 @@ 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',
'--add-opens',
'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',
'-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
3 changes: 2 additions & 1 deletion src/requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Commands } from './commands';
import { logger } from './log';
import { checkJavaPreferences } from './settings';
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
import { getJavaConfiguration } from './utils';

const REQUIRED_JDK_VERSION = 17;
/* eslint-disable @typescript-eslint/naming-convention */
export interface RequirementsData {
tooling_jre: string;
Expand Down Expand Up @@ -41,6 +41,7 @@ export async function resolveRequirements(context: ExtensionContext): Promise<Re
const preferenceName = javaPreferences.preference;
let javaHome = javaPreferences.javaHome;
let javaVersion: number = 0;
const REQUIRED_JDK_VERSION = ('on' === getJavaConfiguration().get('jdt.ls.javac.enabled'))?23:17;
if (javaHome) {
const source = `${preferenceName} variable defined in ${env.appName} settings`;
javaHome = expandHomeDir(javaHome);
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: Work
|| hasConfigKeyChanged('server.launchMode', oldConfig, newConfig)
|| hasConfigKeyChanged('sharedIndexes.location', oldConfig, newConfig)
|| hasConfigKeyChanged('transport', oldConfig, newConfig)
|| hasConfigKeyChanged('diagnostic.filter', oldConfig, newConfig);
|| hasConfigKeyChanged('diagnostic.filter', 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 e68cd9f

Please sign in to comment.