Skip to content

Commit

Permalink
Support to specify source paths for unmanaged folder (#1799)
Browse files Browse the repository at this point in the history
* Support to specify source paths for unmanaged folder

Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Mar 9, 2021
1 parent 724e121 commit 3224e91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ The following settings are supported:
* `java.codeGeneration.toString.limitElements`: Limit number of items in arrays/collections/maps to list, if 0 then list all. Defaults to `0`.
* `java.selectionRange.enabled`: Enable/disable Smart Selection support for Java. Disabling this option will not affect the VS Code built-in word-based and bracket-based smart selection.
* `java.showBuildStatusOnStart.enabled`: Automatically show build status on startup. Defaults to `false`.
* `java.project.outputPath`: 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.
* `java.project.referencedLibraries`: Configure glob patterns for referencing local libraries to a Java project.
* `java.completion.maxResults`: Maximum number of completion results (not including snippets). `0` (the default value) disables the limit, all results are returned. In case of performance problems, consider setting a sensible limit..
* `java.configuration.runtimes`: Map Java Execution Environments to local JDKs.
Expand Down Expand Up @@ -186,6 +187,7 @@ The following settings are supported:

New in 0.77.0:
* `java.references.includeDecompiledSources` : Include the decompiled sources when finding references. Default to true.
* `java.project.sourcePaths`: 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.

Semantic Highlighting
===============
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,19 @@
"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",
"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 3224e91

Please sign in to comment.