Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to specify source paths for unmanaged folder #1799

Merged
merged 4 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update New settings to README as well.

"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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this added patch is that I hope the vscode setting can also be updated if the user changes the source paths from the explorer.

While the side effect is that the setting change event will be synced to the server side and update the classpath again.

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