Skip to content

API to programmatically detect if Java Preview features are enabled #3102

Closed

Description

Hi,

We would like to programmatically detect whether a user has enabled Java preview features.

Would it be possible to add such functionality to the extension's public API?

Environment
  • Visual Studio Code version: 1.78.0
  • Java extension version: v0.25.11

Best,

Activity

  1. rgrunber commented on May 24, 2023

    @rgrunber
    Member

    I think this is currently possible. If you look at the API you'll see we define a function, getProjectSettings(Uri, string[]) . You can use this with org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures, which is the setting that enables preview features :

    const vscodeJava = extensions.getExtension('redhat.java');
    if (!vscodeJava) {
      throw new Error("VSCode java is not installed");
    }
    
    const api = await vscodeJava.activate();
    if (!api) {
      throw new Error("VSCode java api not found");
    }
    
    const projectSetting: {} = await api.getProjectSettings(
      Uri.file(path.join('some', 'project', 'path')).toString(),
      ['org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures']
    );
    

    I think you would need to ensure that the language server has imported the project, but there are events like onDidProjectsImport that we provide for that also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions