Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find in files with VS Code extension

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.

like image 656
Kuba Avatar asked Oct 29 '22 06:10

Kuba


1 Answers

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.

like image 89
Gama11 Avatar answered Dec 28 '22 08:12

Gama11