Skip to content

Allow Exact Match For Filters - #1649

Open
tthornton3-chwy wants to merge 4 commits into
microsoft:mainfrom
tthornton3-chwy:feature/allow-exact-match
Open

Allow Exact Match For Filters#1649
tthornton3-chwy wants to merge 4 commits into
microsoft:mainfrom
tthornton3-chwy:feature/allow-exact-match

Conversation

@tthornton3-chwy

Copy link
Copy Markdown
Contributor

I was having cases where filters were matching inappropriately, for example with composite builds. This lets you have an exact match syntax. I know it's a bit niche, but I do think it's useful/I personally use it!

@tthornton3-chwy

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@chagong

Copy link
Copy Markdown
Contributor

Thanks, this is a reasonable addition and the trailing-separator approach is backward compatible. One blocker and two smaller asks before merge:

Windows separator gap. The typical config form is !${workspaceFolder}/build/classes/ — after resolution that's an absolute path with forward slashes and a trailing /. Since it's absolute, path.join is skipped, so on Windows exclude.endsWith('\\') is false and exact-match silently never triggers. A Windows user would have to hand-write backslashes. Suggest making the check separator-agnostic and running it before normalization:

if (/[\\/]$/.test(exclude)) {
    exclude = exclude.slice(0, -1);
    isDirect = true;
} else {
    isDirect = this.isFilePath(exclude);
}

Docs. The trailing-slash convention isn't discoverable — can you update java.debugger.launch.classPaths.exclude and modulePaths.exclude in package.nls.json to mention it? It's also slightly counter-intuitive (a trailing slash usually implies a directory/prefix, here it means exact match), so a clear note helps.

Test. A small unit test covering the new exact-match path in filterExcluded would be good given this logic is filesystem-sensitive and currently untested.

@tthornton3-chwy

Copy link
Copy Markdown
Contributor Author

Changyong Gong (@chagong) I finally got around to addressing the (very good!) feedback :) Can you re-take a peek?

let exclude = p.slice(1);
let isDirect: boolean;

if (/[\\/]$/.test(exclude)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

before normalization, and using the exact code-block suggested, per feedback!

@chagong Changyong Gong (chagong) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The revised Windows separator handling and tests address the earlier feedback, but the trailing-separator comparison and documentation wording still need adjustment before merge.

for (const [excludedPath, isFile] of excludes.entries()) {
if (isFile && r === excludedPath) {
for (const [excludedPath, isDirect] of excludes.entries()) {
if (isDirect && r === excludedPath) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you normalize trailing separators consistently on both sides before this exact comparison? Currently, ["C:\\workspace\\lib\\", "!C:\\workspace\\lib\\"] leaves the separator on r but removes it from excludedPath, so the directory is not excluded. Please also add forward-slash and backslash tests where the included entry ends in a separator, taking care not to alter filesystem roots.

Comment thread package.nls.json
"java.debugger.launch.modulePaths.runtime": "The module paths within 'runtime' scope of current project.",
"java.debugger.launch.modulePaths.test": "The module paths within 'test' scope of current project.",
"java.debugger.launch.modulePaths.exclude": "The path after '!' will be excluded from the modulePaths.",
"java.debugger.launch.modulePaths.exclude": "The path after '!' will be excluded from the modulePaths. A slash (forwards or backwards) will treat the path as an exact match.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should say “A trailing slash or backslash will treat the path as an exact match.” The current wording suggests that any slash triggers exact matching, while the implementation only checks the final character. Please make the same change to the classPaths.exclude description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants