Skip to content

Commit a1e6cfb

Browse files
authored
fix: Apply 'files.exclude' to Java Projects explorer (#739)
* fix: Apply 'files.exclude' to Java Projects explorer --------- Signed-off-by: Sheng Chen <[email protected]>
1 parent bdc5fa8 commit a1e6cfb

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
- Display non-Java files in Java Projects explorer. [#145](https://github.com./microsoft/vscode-java-dependency/issues/145)
1010
- Apply file decorators to project level. [#481](https://github.com./microsoft/vscode-java-dependency/issues/481)
1111

12+
### Fixed
13+
- Apply `files.exclude` to Java Projects explorer. [#214](https://github.com./microsoft/vscode-java-dependency/issues/214)
14+
1215
## 0.21.2
1316
### Fixed
1417
- Improve the output of exporting jar tasks. [#699](https://github.com./microsoft/vscode-java-dependency/issues/699)

src/java/jdtls.ts

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { CancellationToken, commands } from "vscode";
4+
5+
import * as minimatch from "minimatch";
6+
import { CancellationToken, Uri, commands, workspace } from "vscode";
57
import { Commands, executeJavaLanguageServerCommand } from "../commands";
68
import { IClasspath } from "../tasks/buildArtifact/IStepMetadata";
79
import { IMainClassInfo } from "../tasks/buildArtifact/ResolveMainClassExecutor";
@@ -20,8 +22,32 @@ export namespace Jdtls {
2022
return commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_REFRESH_LIB_SERVER, params);
2123
}
2224

23-
export async function getPackageData(params: { [key: string]: any }): Promise<INodeData[]> {
24-
return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_GETPACKAGEDATA, params) || [];
25+
export async function getPackageData(params: IPackageDataParam): Promise<INodeData[]> {
26+
const uri: Uri | null = !params.projectUri ? null : Uri.parse(params.projectUri);
27+
const excludePatterns: {[key: string]: boolean} | undefined = workspace.getConfiguration("files", uri).get("exclude");
28+
29+
let nodeData: INodeData[] = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND,
30+
Commands.JAVA_GETPACKAGEDATA, params) || [];
31+
if (excludePatterns && nodeData.length) {
32+
const uriOfChildren: string[] = nodeData.map((node: INodeData) => node.uri).filter(Boolean) as string[];
33+
const urisToExclude: Set<string> = new Set<string>();
34+
for (const pattern in excludePatterns) {
35+
if (excludePatterns[pattern]) {
36+
const toExclude: string[] = minimatch.match(uriOfChildren, pattern);
37+
toExclude.forEach((uri: string) => urisToExclude.add(uri));
38+
}
39+
}
40+
41+
if (urisToExclude.size) {
42+
nodeData = nodeData.filter((node: INodeData) => {
43+
if (!node.uri) {
44+
return true;
45+
}
46+
return !urisToExclude.has(node.uri);
47+
})
48+
}
49+
}
50+
return nodeData;
2551
}
2652

2753
export async function resolvePath(params: string): Promise<INodeData[]> {
@@ -49,3 +75,8 @@ export namespace Jdtls {
4975
return <Promise<string[]>>executeJavaLanguageServerCommand(Commands.JAVA_RESOLVE_BUILD_FILES);
5076
}
5177
}
78+
79+
interface IPackageDataParam {
80+
projectUri: string | undefined,
81+
[key: string]: any,
82+
}

src/settings.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class Settings {
1616
context.subscriptions.push(workspace.onDidChangeConfiguration((e: ConfigurationChangeEvent) => {
1717
if ((e.affectsConfiguration("java.dependency.syncWithFolderExplorer") && Settings.syncWithFolderExplorer()) ||
1818
e.affectsConfiguration("java.dependency.showMembers") ||
19-
e.affectsConfiguration("java.dependency.packagePresentation")) {
19+
e.affectsConfiguration("java.dependency.packagePresentation") ||
20+
e.affectsConfiguration("files.exclude")) {
2021
commands.executeCommand(Commands.VIEW_PACKAGE_INTERNAL_REFRESH);
2122
} else if (e.affectsConfiguration("java.dependency.autoRefresh")) {
2223
syncHandler.updateFileWatcher(Settings.autoRefresh());

test/maven-suite/projectView.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,11 @@ suite("Maven Project View Tests", () => {
223223
assert.equal(mainClasses![0].name, "com.mycompany.app.App", "mainClasses[0]'s name should be com.mycompany.app.App");
224224
});
225225

226+
test("Can apply 'files.exclude'", async function() {
227+
const explorer = DependencyExplorer.getInstance(contextManager.context);
228+
229+
const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
230+
const projectChildren = await projectNode.getChildren();
231+
assert.ok(!projectChildren.find((node: DataNode) => node.nodeData.name === ".hidden"));
232+
});
226233
});

test/maven/.hidden

Whitespace-only changes.

test/maven/.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"java.server.launchMode": "Standard"
2+
"java.server.launchMode": "Standard",
3+
"files.exclude": {
4+
"**/.hidden": true,
5+
}
36
}

0 commit comments

Comments
 (0)