Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const JAVA_RESOLVE_MAINMETHOD = "vscode.java.resolveMainMethod";

export const JAVA_INFER_LAUNCH_COMMAND_LENGTH = "vscode.java.inferLaunchCommandLength";

export const JAVA_CHECK_PROJECT_SETTINGS = "vscode.java.checkProjectSettings";

export function executeJavaLanguageServerCommand(...rest) {
// TODO: need to handle error and trace telemetry
return vscode.commands.executeCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest);
Expand Down
4 changes: 4 additions & 0 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration

// Add the default launch options to the config.
config.cwd = config.cwd || _.get(folder, "uri.fsPath");
// Auto add '--enable-preview' vmArgs if the java project enables COMPILER_PB_ENABLE_PREVIEW_FEATURES flag.
if (await lsPlugin.detectPreviewFlag(config.mainClass, config.projectName)) {
config.vmArgs = (config.vmArgs || "") + " --enable-preview";
}
} else if (config.request === "attach") {
if (!config.hostName || !config.port) {
throw new utility.UserError({
Expand Down
19 changes: 19 additions & 0 deletions src/languageServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,22 @@ export function validateLaunchConfig(workspaceUri: vscode.Uri, mainClass: string
export function inferLaunchCommandLength(config: vscode.DebugConfiguration): Promise<number> {
return <Promise<number>>commands.executeJavaLanguageServerCommand(commands.JAVA_INFER_LAUNCH_COMMAND_LENGTH, JSON.stringify(config));
}

export function checkProjectSettings(className: string, projectName: string, inheritedOptions: boolean, expectedOptions: {[key: string]: string}):
Promise<boolean> {
return <Promise<boolean>>commands.executeJavaLanguageServerCommand(
commands.JAVA_CHECK_PROJECT_SETTINGS, JSON.stringify({
className,
projectName,
inheritedOptions,
expectedOptions,
}));
}

const COMPILER_PB_ENABLE_PREVIEW_FEATURES: string = "org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures";
export async function detectPreviewFlag(className: string, projectName: string): Promise<boolean> {
const expectedOptions = {
[COMPILER_PB_ENABLE_PREVIEW_FEATURES]: "enabled",
};
return await checkProjectSettings(className, projectName, true, expectedOptions);
}