I'm implementing a vs code extension that utilizes the Tree View.
Whenever user clicks on the item, I'd like to perform a "find in files" command.
public getTreeItem(element: Item): TreeItem {
return {
label: element.name,
collapsibleState: element.isGroup ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None,
command: element.isGroup ? void 0 : {
command: 'workbench.action.findInFiles',
arguments: [element.name],
title: 'Find references'
}
...
}
}
As you can see, I'm passing element.name
as an argument for workbench.action.findInFiles
command.
Doesn't work - it simply opens the Search sidebar.
I looked for some reference in the documentation but with no luck.
As of the April 2019 release (1.34), this is now possible by specifying the query
argument. You can also use triggerSearch
to start the search immediately:
{
command: 'workbench.action.findInFiles',
arguments: {
query: element.name,
triggerSearch: true
},
title: 'Find references'
}
The full list of options is as follows:
export interface IFindInFilesArgs {
query?: string;
replace?: string;
triggerSearch?: boolean;
filesToInclude?: string;
filesToExclude?: string;
isRegex?: boolean;
isCaseSensitive?: boolean;
matchWholeWord?: boolean;
}
Note that query
must be set for any of the other values to be respected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With