diff --git a/package.json b/package.json index 65f6503361..188f0d2eaf 100644 --- a/package.json +++ b/package.json @@ -359,10 +359,22 @@ "string", "null" ], - "markdownDescription": "A relative path to the workspace where stores the compiled output. `Only` effective in the `WORKSPACE` scope. The setting will `NOT` affect Maven or Gradle project. ", + "markdownDescription": "A relative path to the workspace where stores the compiled output. `Only` effective in the `WORKSPACE` scope. The setting will `NOT` affect Maven or Gradle project.", "default": "", "scope": "window" }, + "java.project.sourcePaths": { + "type": [ + "array", + "null" + ], + "items": { + "type": "string" + }, + "markdownDescription": "Relative paths to the workspace where stores the source files. `Only` effective in the `WORKSPACE` scope. The setting will `NOT` affect Maven or Gradle project.", + "default": [], + "scope": "window" + }, "java.contentProvider.preferred": { "type": "string", "description": "Preferred content provider (a 3rd party decompiler id, usually)", diff --git a/src/buildpath.ts b/src/buildpath.ts index 911f01da44..daf7ffbedf 100644 --- a/src/buildpath.ts +++ b/src/buildpath.ts @@ -1,7 +1,8 @@ 'use strict'; -import { window, commands, ExtensionContext, Uri } from 'vscode'; +import { window, commands, ExtensionContext, Uri, ConfigurationTarget } from 'vscode'; import { Commands } from './commands'; +import { getJavaConfiguration } from './utils'; interface Result { status: boolean; @@ -23,6 +24,9 @@ export function registerCommands(context: ExtensionContext) { context.subscriptions.push(commands.registerCommand(Commands.ADD_TO_SOURCEPATH, async (uri: Uri) => { const result = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.ADD_TO_SOURCEPATH, uri.toString()); if (result.status) { + if (result.sourcePaths) { + getJavaConfiguration().update('project.sourcePaths', result.sourcePaths, ConfigurationTarget.Workspace); + } window.showInformationMessage(result.message ? result.message : 'Successfully added the folder to the source path.'); } else { window.showErrorMessage(result.message); @@ -32,6 +36,9 @@ export function registerCommands(context: ExtensionContext) { context.subscriptions.push(commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH, async (uri: Uri) => { const result = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.REMOVE_FROM_SOURCEPATH, uri.toString()); if (result.status) { + if (result.sourcePaths) { + getJavaConfiguration().update('project.sourcePaths', result.sourcePaths, ConfigurationTarget.Workspace); + } window.showInformationMessage(result.message ? result.message : 'Successfully removed the folder from the source path.'); } else { window.showErrorMessage(result.message); diff --git a/src/extension.ts b/src/extension.ts index 3c6eb86b16..7a0d08b629 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -400,9 +400,11 @@ export function getJavaConfig(javaHome: string) { const origConfig = getJavaConfiguration(); const javaConfig = JSON.parse(JSON.stringify(origConfig)); javaConfig.home = javaHome; - // Since output path is a project specific setting. To avoid pollute other project, + // Since source & output path are project specific settings. To avoid pollute other project, // we avoid reading the value from the global scope. javaConfig.project.outputPath = origConfig.inspect("project.outputPath").workspaceValue; + javaConfig.project.sourcePaths = origConfig.inspect("project.sourcePaths").workspaceValue; + const editorConfig = workspace.getConfiguration('editor'); javaConfig.format.insertSpaces = editorConfig.get('insertSpaces'); javaConfig.format.tabSize = editorConfig.get('tabSize');