diff --git a/CHANGELOG.md b/CHANGELOG.md index ce7e306f..2a84de39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/java/jdtls.ts b/src/java/jdtls.ts index a5674e62..b3fc6424 100644 --- a/src/java/jdtls.ts +++ b/src/java/jdtls.ts @@ -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"; @@ -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 { - return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_GETPACKAGEDATA, params) || []; + export async function getPackageData(params: IPackageDataParam): Promise { + 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 = new Set(); + 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 { @@ -49,3 +75,8 @@ export namespace Jdtls { return >executeJavaLanguageServerCommand(Commands.JAVA_RESOLVE_BUILD_FILES); } } + +interface IPackageDataParam { + projectUri: string | undefined, + [key: string]: any, +} \ No newline at end of file diff --git a/src/settings.ts b/src/settings.ts index 08b99213..c0b9d86c 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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()); diff --git a/test/maven-suite/projectView.test.ts b/test/maven-suite/projectView.test.ts index ae73ccd0..11fffebf 100644 --- a/test/maven-suite/projectView.test.ts +++ b/test/maven-suite/projectView.test.ts @@ -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")); + }); }); diff --git a/test/maven/.hidden b/test/maven/.hidden new file mode 100644 index 00000000..e69de29b diff --git a/test/maven/.vscode/settings.json b/test/maven/.vscode/settings.json index 66e66c61..ee7bd904 100644 --- a/test/maven/.vscode/settings.json +++ b/test/maven/.vscode/settings.json @@ -1,3 +1,6 @@ { - "java.server.launchMode": "Standard" + "java.server.launchMode": "Standard", + "files.exclude": { + "**/.hidden": true, + } }