Skip to content

Commit

Permalink
Support to specify source paths for unmanaged folder
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo committed Mar 2, 2021
1 parent 68ae0e0 commit ba19062
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
9 changes: 8 additions & 1 deletion src/buildpath.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,6 +24,9 @@ export function registerCommands(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand(Commands.ADD_TO_SOURCEPATH, async (uri: Uri) => {
const result = await <any>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);
Expand All @@ -32,6 +36,9 @@ export function registerCommands(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH, async (uri: Uri) => {
const result = await <any>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);
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("project.outputPath").workspaceValue;
javaConfig.project.sourcePaths = origConfig.inspect<string[]>("project.sourcePaths").workspaceValue;

const editorConfig = workspace.getConfiguration('editor');
javaConfig.format.insertSpaces = editorConfig.get('insertSpaces');
javaConfig.format.tabSize = editorConfig.get('tabSize');
Expand Down

0 comments on commit ba19062

Please sign in to comment.