-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add processFilter for remote attach process selection #14684
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
Sean McManus (sean-mcmanus)
merged 4 commits into
microsoft:main
from
afreof:feat/14682-remote-attach-process-filter
Sep 3, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bfb2307
Add processFilter for remote attach process selection
a10b0b7
Extract remote process filtering into a helper
a88d135
Add unit tests for processFilter matching
dd274fc
Merge branch 'main' into feat/14682-remote-attach-process-filter
sean-mcmanus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| * See 'LICENSE' in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
|
|
||
| import * as nls from 'vscode-nls'; | ||
|
|
||
| nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); | ||
| const localize: nls.LocalizeFunc = nls.loadMessageBundle(); | ||
|
|
||
| export interface ProcessFilterItem { | ||
| label?: string; | ||
| description?: string; | ||
| detail?: string; | ||
| } | ||
|
|
||
| export function filterProcessItems<T extends ProcessFilterItem>(items: T[], processFilter?: unknown): T[] | undefined { | ||
| // The value comes from launch.json, so it is not guaranteed to be a string. | ||
| if (typeof processFilter !== 'string' || !processFilter.trim()) { | ||
| return undefined; | ||
| } | ||
|
|
||
| let processRegex: RegExp; | ||
| try { | ||
| processRegex = new RegExp(processFilter); | ||
|
sean-mcmanus marked this conversation as resolved.
|
||
| } catch { | ||
| throw new Error(localize("invalid.processFilter.regex", "Invalid {0} regular expression: {1}", "processFilter", processFilter)); | ||
| } | ||
|
|
||
| return items.filter((item: T) => [item.label, item.description, item.detail] | ||
| .some((value: string | undefined) => typeof value === "string" && processRegex.test(value))); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| * See 'LICENSE' in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
|
|
||
| import { deepStrictEqual, strictEqual, throws } from 'assert'; | ||
| import { describe, it } from 'mocha'; | ||
| import { filterProcessItems } from '../../src/Debugger/processFilter'; | ||
|
|
||
| interface TestProcessItem { | ||
| label?: string; | ||
| description?: string; | ||
| detail?: string; | ||
| id: string; | ||
| } | ||
|
|
||
| describe('Remote attach process filter', () => { | ||
| const processes: TestProcessItem[] = [ | ||
| { id: '101', label: 'root /usr/bin/my-daemon --serve', description: '101' }, | ||
| { id: '102', label: 'root /usr/bin/other-service', description: '102', detail: 'worker' }, | ||
| { id: '103', label: 'app /usr/bin/my-daemon --once', description: '103' } | ||
| ]; | ||
|
|
||
| it('returns undefined when filter is empty', () => { | ||
| strictEqual(filterProcessItems(processes, ''), undefined); | ||
| strictEqual(filterProcessItems(processes, ' '), undefined); | ||
| strictEqual(filterProcessItems(processes, undefined), undefined); | ||
| }); | ||
|
|
||
| it('returns undefined when filter is not a string', () => { | ||
| strictEqual(filterProcessItems(processes, 1234), undefined); | ||
| strictEqual(filterProcessItems(processes, true), undefined); | ||
| strictEqual(filterProcessItems(processes, {}), undefined); | ||
| }); | ||
|
|
||
| it('matches by label and description and detail', () => { | ||
| deepStrictEqual(filterProcessItems(processes, 'other-service')?.map(p => p.id), ['102']); | ||
| deepStrictEqual(filterProcessItems(processes, '^101$')?.map(p => p.id), ['101']); | ||
| deepStrictEqual(filterProcessItems(processes, 'worker')?.map(p => p.id), ['102']); | ||
| }); | ||
|
|
||
| it('preserves edge whitespace in the regular expression', () => { | ||
|
sean-mcmanus marked this conversation as resolved.
|
||
| deepStrictEqual(filterProcessItems(processes, '^root /usr/bin/my-daemon --serve ')?.map(p => p.id), []); | ||
| }); | ||
|
|
||
| it('returns multiple matches when regex matches more than one process', () => { | ||
| deepStrictEqual(filterProcessItems(processes, 'my-daemon')?.map(p => p.id), ['101', '103']); | ||
| }); | ||
|
|
||
| it('throws for invalid regular expression', () => { | ||
| throws(() => filterProcessItems(processes, '['), /Invalid processFilter regular expression/); | ||
| }); | ||
|
|
||
| it('does not treat missing fields as empty strings', () => { | ||
| const items: TestProcessItem[] = [ | ||
| { id: '201' }, // label, description, and detail are all missing | ||
| { id: '202', detail: '' } // detail is explicitly an empty string | ||
| ]; | ||
| deepStrictEqual(filterProcessItems(items, '^$')?.map(p => p.id), ['202']); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.