Skip to content

fix: Apply 'files.exclude' to Java Projects explorer #739

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

Merged
merged 2 commits into from
Apr 10, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Display non-Java files in Java Projects explorer. [#145](https://github.com/microsoft/vscode-java-dependency/issues/145)
- Apply file decorators to project level. [#481](https://github.com/microsoft/vscode-java-dependency/issues/481)

### Fixed
- Apply `files.exclude` to Java Projects explorer. [#214](https://github.com/microsoft/vscode-java-dependency/issues/214)

## 0.21.2
### Fixed
- Improve the output of exporting jar tasks. [#699](https://github.com/microsoft/vscode-java-dependency/issues/699)
Expand Down
37 changes: 34 additions & 3 deletions src/java/jdtls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { CancellationToken, commands } from "vscode";

import * as minimatch from "minimatch";
import { CancellationToken, Uri, commands, workspace } from "vscode";
import { Commands, executeJavaLanguageServerCommand } from "../commands";
import { IClasspath } from "../tasks/buildArtifact/IStepMetadata";
import { IMainClassInfo } from "../tasks/buildArtifact/ResolveMainClassExecutor";
Expand All @@ -20,8 +22,32 @@ export namespace Jdtls {
return commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_REFRESH_LIB_SERVER, params);
}

export async function getPackageData(params: { [key: string]: any }): Promise<INodeData[]> {
return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_GETPACKAGEDATA, params) || [];
export async function getPackageData(params: IPackageDataParam): Promise<INodeData[]> {
const uri: Uri | null = !params.projectUri ? null : Uri.parse(params.projectUri);
const excludePatterns: {[key: string]: boolean} | undefined = workspace.getConfiguration("files", uri).get("exclude");

let nodeData: INodeData[] = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_GETPACKAGEDATA, params) || [];
if (excludePatterns && nodeData.length) {
const uriOfChildren: string[] = nodeData.map((node: INodeData) => node.uri).filter(Boolean) as string[];
const urisToExclude: Set<string> = new Set<string>();
for (const pattern in excludePatterns) {
if (excludePatterns[pattern]) {
const toExclude: string[] = minimatch.match(uriOfChildren, pattern);
toExclude.forEach((uri: string) => urisToExclude.add(uri));
}
}

if (urisToExclude.size) {
nodeData = nodeData.filter((node: INodeData) => {
if (!node.uri) {
return true;
}
return !urisToExclude.has(node.uri);
})
}
}
return nodeData;
}

export async function resolvePath(params: string): Promise<INodeData[]> {
Expand Down Expand Up @@ -49,3 +75,8 @@ export namespace Jdtls {
return <Promise<string[]>>executeJavaLanguageServerCommand(Commands.JAVA_RESOLVE_BUILD_FILES);
}
}

interface IPackageDataParam {
projectUri: string | undefined,
[key: string]: any,
}
3 changes: 2 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class Settings {
context.subscriptions.push(workspace.onDidChangeConfiguration((e: ConfigurationChangeEvent) => {
if ((e.affectsConfiguration("java.dependency.syncWithFolderExplorer") && Settings.syncWithFolderExplorer()) ||
e.affectsConfiguration("java.dependency.showMembers") ||
e.affectsConfiguration("java.dependency.packagePresentation")) {
e.affectsConfiguration("java.dependency.packagePresentation") ||
e.affectsConfiguration("files.exclude")) {
commands.executeCommand(Commands.VIEW_PACKAGE_INTERNAL_REFRESH);
} else if (e.affectsConfiguration("java.dependency.autoRefresh")) {
syncHandler.updateFileWatcher(Settings.autoRefresh());
Expand Down
7 changes: 7 additions & 0 deletions test/maven-suite/projectView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,11 @@ suite("Maven Project View Tests", () => {
assert.equal(mainClasses![0].name, "com.mycompany.app.App", "mainClasses[0]'s name should be com.mycompany.app.App");
});

test("Can apply 'files.exclude'", async function() {
const explorer = DependencyExplorer.getInstance(contextManager.context);

const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const projectChildren = await projectNode.getChildren();
assert.ok(!projectChildren.find((node: DataNode) => node.nodeData.name === ".hidden"));
});
});
Empty file added test/maven/.hidden
Empty file.
5 changes: 4 additions & 1 deletion test/maven/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"java.server.launchMode": "Standard"
"java.server.launchMode": "Standard",
"files.exclude": {
"**/.hidden": true,
}
}