Skip to content

Commit 960dcf0

Browse files
authored
feat: Introduce a setting to control whether non-Java resources should be filtered (#749)
* feat: Introduce a setting to control whether non-Java resources should be filtered
1 parent a3abd05 commit 960dcf0

File tree

11 files changed

+105
-15
lines changed

11 files changed

+105
-15
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## 0.22.0
88
### Added
99
- Display non-Java files in Java Projects explorer. [#145](https://github.com./microsoft/vscode-java-dependency/issues/145)
10-
- Show non Java projects in the Java Projects explorer. [#736](https://github.com./microsoft/vscode-java-dependency/issues/736)
10+
- Show non-Java projects in the Java Projects explorer. [#736](https://github.com./microsoft/vscode-java-dependency/issues/736)
11+
- Introduce a setting: `java.project.explorer.filters` to control whether non-Java resources show in Java Projects explorer. [#751](https://github.com./microsoft/vscode-java-dependency/issues/751)
1112
- Support creating files and folders in Java Projects explorer. [#598](https://github.com./microsoft/vscode-java-dependency/issues/598)
1213
- Apply file decorators to project level. [#481](https://github.com./microsoft/vscode-java-dependency/issues/481)
1314
- Give more hints about the project import status. [#580](https://github.com./microsoft/vscode-java-dependency/issues/580)

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
100100
IPath workspaceFolderPath = ResourceUtils.canonicalFilePathFromURI(workspaceUri);
101101

102102
IProject[] projects;
103-
boolean includeNonJava = false;
103+
boolean filterNonJava = false;
104104
if (arguments.size() > 1) {
105-
includeNonJava = (boolean) arguments.get(1);
105+
filterNonJava = (boolean) arguments.get(1);
106106
}
107-
if (includeNonJava) {
107+
if (!filterNonJava) {
108108
projects = ProjectUtils.getAllProjects();
109109
} else {
110110
projects = Arrays.stream(ProjectUtils.getJavaProjects())

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
"light": "icons/light/icon-link.svg"
143143
}
144144
},
145+
{
146+
"command": "java.project.explorer.configureFilters",
147+
"title": "%contributes.commands.java.project.explorer.configureFilters%",
148+
"category": "Java"
149+
},
145150
{
146151
"command": "java.view.package.revealFileInOS",
147152
"title": "%contributes.commands.java.view.package.revealFileInOS%",
@@ -258,6 +263,18 @@
258263
],
259264
"markdownDescription": "%configuration.java.project.exportJar.targetPath.customization%",
260265
"default": "${workspaceFolder}/${workspaceFolderBasename}.jar"
266+
},
267+
"java.project.explorer.filters": {
268+
"type": "object",
269+
"description": "%configuration.java.project.explorer.filters%",
270+
"default": {},
271+
"properties": {
272+
"nonJavaResources": {
273+
"type": "boolean",
274+
"description": "%configuration.java.project.explorer.filters.nonJavaResources%",
275+
"default": false
276+
}
277+
}
261278
}
262279
}
263280
},
@@ -481,6 +498,11 @@
481498
"when": "view == javaProjectExplorer && java:serverMode == Standard && config.java.dependency.syncWithFolderExplorer == true",
482499
"group": "overflow_10@20"
483500
},
501+
{
502+
"command": "java.project.explorer.configureFilters",
503+
"when": "view == javaProjectExplorer && java:serverMode == Standard",
504+
"group": "overflow_10@30"
505+
},
484506
{
485507
"command": "java.project.clean.workspace",
486508
"when": "view == javaProjectExplorer && java:serverMode == Standard && !java:noJavaProjects",

package.nls.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"Hierarchical View",
1616
"contributes.commands.java.view.package.linkWithFolderExplorer":"Synchronize with Editor",
1717
"contributes.commands.java.view.package.unlinkWithFolderExplorer":"Desynchronize with Editor",
18+
"contributes.commands.java.project.explorer.configureFilters": "Configure Filters",
1819
"contributes.commands.java.view.package.revealFileInOS": "Reveal in Explorer",
1920
"contributes.commands.java.view.package.exportJar": "Export Jar...",
2021
"contributes.commands.java.view.package.copyFilePath": "Copy Path",
@@ -33,6 +34,8 @@
3334
"configuration.java.dependency.autoRefresh": "Synchronize Java Projects explorer with changes",
3435
"configuration.java.dependency.refreshDelay": "The delay time (ms) the auto refresh is invoked when changes are detected",
3536
"configuration.java.dependency.packagePresentation": "Package presentation mode: flat or hierarchical",
37+
"configuration.java.project.explorer.filters": "Filters for the Java Projects explorer.",
38+
"configuration.java.project.explorer.filters.nonJavaResources": "Specify whether non-Java resources will be filtered out.",
3639
"configuration.java.project.exportJar.targetPath.customization": "The output path of the exported jar. Leave it empty if you want to manually pick the output location.",
3740
"configuration.java.project.exportJar.targetPath.workspaceFolder": "Export the jar file into the workspace folder. Its name is the same as the folder's.",
3841
"configuration.java.project.exportJar.targetPath.select": "Select output location manually when exporting the jar file.",

package.nls.zh-cn.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"层级显示",
1616
"contributes.commands.java.view.package.linkWithFolderExplorer":"启用编辑器关联",
1717
"contributes.commands.java.view.package.unlinkWithFolderExplorer":"关闭编辑器关联",
18+
"contributes.commands.java.project.explorer.configureFilters": "设置过滤器",
1819
"contributes.commands.java.view.package.revealFileInOS": "打开所在的文件夹",
1920
"contributes.commands.java.view.package.exportJar": "导出到 Jar 文件...",
2021
"contributes.commands.java.view.package.copyFilePath": "复制路径",
@@ -33,6 +34,8 @@
3334
"configuration.java.dependency.autoRefresh": "在 Java 项目管理器中自动同步修改",
3435
"configuration.java.dependency.refreshDelay": "控制 Java 项目管理器刷新的延迟时间 (毫秒)",
3536
"configuration.java.dependency.packagePresentation": "Java 包显示方式: 平行显示或者分层显示",
37+
"configuration.java.project.explorer.filters": "设置 Java 项目管理器要过滤的内容。",
38+
"configuration.java.project.explorer.filters.nonJavaResources": "是否需要过滤非 Java 资源。",
3639
"configuration.java.project.exportJar.targetPath.customization": "导出 Jar 文件的路径。您可以将此选项置为空串来手动选择 jar 文件的导出路径。",
3740
"configuration.java.project.exportJar.targetPath.workspaceFolder": "导出 Jar 文件到工作空间文件夹下。Jar 文件的名称和工作空间文件夹的名称相同。",
3841
"configuration.java.project.exportJar.targetPath.select": "在导出 Jar 文件时手动选择输出目录。",

src/commands.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export namespace Commands {
1818

1919
export const VIEW_PACKAGE_UNLINKWITHFOLDER = "java.view.package.unlinkWithFolderExplorer";
2020

21+
export const JAVA_PROJECT_EXPLORER_CONFIGURE_FILTERS = "java.project.explorer.configureFilters";
22+
2123
export const VIEW_PACKAGE_REFRESH = "java.view.package.refresh";
2224

2325
export const VIEW_PACKAGE_INTERNAL_REFRESH = "_java.view.package.internal.refresh";

src/java/jdtls.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import { CancellationToken, Uri, commands, workspace } from "vscode";
77
import { Commands, executeJavaLanguageServerCommand } from "../commands";
88
import { IClasspath } from "../tasks/buildArtifact/IStepMetadata";
99
import { IMainClassInfo } from "../tasks/buildArtifact/ResolveMainClassExecutor";
10-
import { INodeData } from "./nodeData";
10+
import { INodeData, NodeKind } from "./nodeData";
11+
import { Settings } from "../settings";
1112

1213
export namespace Jdtls {
1314
export async function getProjects(params: string): Promise<INodeData[]> {
1415
return await commands.executeCommand(
1516
Commands.EXECUTE_WORKSPACE_COMMAND,
1617
Commands.JAVA_PROJECT_LIST,
1718
params,
18-
true /*includeNonJavaProjects*/
19+
Settings.nonJavaResourcesFiltered()
1920
) || [];
2021
}
2122

@@ -33,6 +34,14 @@ export namespace Jdtls {
3334

3435
let nodeData: INodeData[] = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND,
3536
Commands.JAVA_GETPACKAGEDATA, params) || [];
37+
38+
// check filter settings.
39+
if (Settings.nonJavaResourcesFiltered()) {
40+
nodeData = nodeData.filter((data: INodeData) => {
41+
return data.kind !== NodeKind.Folder && data.kind !== NodeKind.File;
42+
});
43+
}
44+
3645
if (excludePatterns && nodeData.length) {
3746
const uriOfChildren: string[] = nodeData.map((node: INodeData) => node.uri).filter(Boolean) as string[];
3847
const urisToExclude: Set<string> = new Set<string>();

src/settings.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import {
5-
commands, ConfigurationChangeEvent, ExtensionContext,
5+
commands, ConfigurationChangeEvent, ConfigurationTarget, ExtensionContext,
66
workspace,
77
} from "vscode";
88
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
@@ -17,6 +17,7 @@ export class Settings {
1717
if ((e.affectsConfiguration("java.dependency.syncWithFolderExplorer") && Settings.syncWithFolderExplorer()) ||
1818
e.affectsConfiguration("java.dependency.showMembers") ||
1919
e.affectsConfiguration("java.dependency.packagePresentation") ||
20+
e.affectsConfiguration("java.project.explorer.filters") ||
2021
e.affectsConfiguration("files.exclude")) {
2122
commands.executeCommand(Commands.VIEW_PACKAGE_INTERNAL_REFRESH);
2223
} else if (e.affectsConfiguration("java.dependency.autoRefresh")) {
@@ -57,6 +58,13 @@ export class Settings {
5758
workspace.getConfiguration("java.dependency").update("packagePresentation", PackagePresentation.Hierarchical, false);
5859
}
5960

61+
public static switchNonJavaResourceFilter(enabled: boolean): void {
62+
workspace.getConfiguration("java.project.explorer").update(
63+
"filters",
64+
{ nonJavaResources: enabled },
65+
ConfigurationTarget.Workspace);
66+
}
67+
6068
public static updateReferencedLibraries(libraries: IReferencedLibraries): void {
6169
let updateSetting: string[] | Partial<IReferencedLibraries> = {
6270
include: libraries.include,
@@ -103,6 +111,14 @@ export class Settings {
103111
// tslint:disable-next-line: no-invalid-template-strings
104112
return workspace.getConfiguration("java.project.exportJar").get<string>("targetPath", "${workspaceFolder}/${workspaceFolderBasename}.jar");
105113
}
114+
115+
/**
116+
* Get whether non-Java resources should be filtered in the explorer.
117+
*/
118+
public static nonJavaResourcesFiltered(): boolean {
119+
const filter: IExplorerFilter = workspace.getConfiguration("java.project.explorer").get<IExplorerFilter>("filters", {});
120+
return !!filter.nonJavaResources;
121+
}
106122
}
107123

108124
enum PackagePresentation {
@@ -115,3 +131,7 @@ export interface IReferencedLibraries {
115131
exclude: string[];
116132
sources: { [binary: string]: string };
117133
}
134+
135+
interface IExplorerFilter {
136+
nonJavaResources?: boolean
137+
}

src/views/dependencyExplorer.ts

+18
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ export class DependencyExplorer implements Disposable {
9090

9191
this.reveal(uri, false /*force to reveal even the sync setting is turned off*/);
9292
}),
93+
instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_EXPLORER_CONFIGURE_FILTERS, async () => {
94+
const filters = await window.showQuickPick(
95+
[{
96+
label: "Non-Java resources",
97+
picked: Settings.nonJavaResourcesFiltered(),
98+
}],
99+
{
100+
placeHolder: "Select filters to apply to the Java Projects Explorer",
101+
canPickMany: true,
102+
ignoreFocusOut: true,
103+
}
104+
);
105+
if (!filters) {
106+
return;
107+
}
108+
109+
Settings.switchNonJavaResourceFilter(filters.some((filter) => filter.label === "Non-Java resources"));
110+
}),
93111
);
94112

95113
// register telemetry events

test/maven-suite/projectView.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,16 @@ suite("Maven Project View Tests", () => {
240240
const projectChildren = await projectNode.getChildren();
241241
assert.ok(!projectChildren.find((node: DataNode) => node.nodeData.name === ".hidden"));
242242
});
243+
244+
test("Can apply 'java.project.explorer.filters.nonJavaResources'", async function() {
245+
await vscode.workspace.getConfiguration("java.project.explorer").update(
246+
"filters",
247+
{ nonJavaResources:true }
248+
);
249+
const explorer = DependencyExplorer.getInstance(contextManager.context);
250+
251+
const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
252+
const projectChildren = await projectNode.getChildren();
253+
assert.equal(projectChildren.length, 4);
254+
});
243255
});

0 commit comments

Comments
 (0)