diff --git a/README.md b/README.md index 264af03d6..edcfc000b 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ The following settings are supported: * `java.compile.nullAnalysis.nullable`: Specify the Nullable annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if `java.compile.nullAnalysis.mode` is set to `disabled`. * `java.compile.nullAnalysis.nonnullbydefault`: Specify the NonNullByDefault annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if `java.compile.nullAnalysis.mode` is set to `disabled`. * `java.import.maven.offline.enabled`: Enable/disable the Maven offline mode. Defaults to `false`. -* `java.import.maven.projectNameTemplate`: Specifies the template used to name imported Maven projects, e.g. `[groupId]-[artifactId]-[version]`. This is helpful when importing projects with the same groupId and artifactId but a different version. Supported variables are `[groupId]`, `[artifactId]`, `[version]` and `[name]`. Already imported projects keep their name until the workspace is cleaned. +* `java.import.maven.projectNameTemplate`: Specifies the template used to name imported Maven projects, e.g. `[groupId]-[artifactId]-[version]`. This is helpful when importing projects with the same groupId and artifactId but a different version. Supported variables are `[groupId]`, `[artifactId]`, `[version]` and `[name]`. Already imported projects keep their name until the workspace is cleaned. In a multi-root workspace, it can be set per workspace folder. * `java.codeAction.sortMembers.avoidVolatileChanges`: Reordering of fields, enum constants, and initializers can result in semantic and runtime changes due to different initialization and persistence order. This setting prevents this from occurring. Defaults to `true`. * `java.jdt.ls.protobufSupport.enabled`: Specify whether to automatically add Protobuf output source directories to the classpath. **Note:** Only works for Gradle `com.google.protobuf` plugin `0.8.4` or higher. Defaults to `true`. * `java.jdt.ls.aspectjSupport.enabled`: Specify whether to enable `io.freefair.aspectj` plugin in Gradle projects. Defaults to `false`. diff --git a/package.json b/package.json index f7bfec19c..a92d48d84 100644 --- a/package.json +++ b/package.json @@ -703,8 +703,8 @@ "java.import.maven.projectNameTemplate": { "type": "string", "default": null, - "markdownDescription": "Specifies the template used to name imported Maven projects, e.g. `[groupId]-[artifactId]-[version]`. This is helpful when importing projects with the same groupId and artifactId but a different version. Supported variables are `[groupId]`, `[artifactId]`, `[version]` and `[name]`. Already imported projects keep their name until the workspace is cleaned.", - "scope": "window", + "markdownDescription": "Specifies the template used to name imported Maven projects, e.g. `[groupId]-[artifactId]-[version]`. This is helpful when importing projects with the same groupId and artifactId but a different version. Supported variables are `[groupId]`, `[artifactId]`, `[version]` and `[name]`. Already imported projects keep their name until the workspace is cleaned. In a multi-root workspace, it can be set per workspace folder.", + "scope": "resource", "order": 25 }, "java.import.maven.disableTestClasspathFlag": { diff --git a/src/utils.ts b/src/utils.ts index 22188d5b5..8947e028a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -234,6 +234,15 @@ export async function getJavaConfig(javaHome: string, skipAutoDetection?: boolea javaConfig.format.tabSize = editorConfig.get('tabSize'); const filesConfig = workspace.getConfiguration('files'); javaConfig.associations = filesConfig.get('associations'); + javaConfig.import.maven.projectNameTemplateByFolder = {}; + if (workspace.workspaceFolders && workspace.workspaceFolders.length) { + workspace.workspaceFolders.forEach((folder) => { + const template = workspace.getConfiguration('java', folder.uri).get('import.maven.projectNameTemplate'); + if (template) { + javaConfig.import.maven.projectNameTemplateByFolder[folder.uri.toString()] = template; + } + }); + } const isInsider: boolean = isInsiderEditor(); const androidSupport = javaConfig.jdt.ls.androidSupport.enabled; switch (androidSupport) {