admin管理员组文章数量:1291089
I'm trying to search a string in the code base. Ctrl + Shift + F should do it, but I want to get the list of files in search results.
I tried using the VS Code mand:
mands.executeCommand("workbench.action.findInFiles");
However, it simply did the search but didn't return anything.
Is there an API to get the list of search results?
I'm trying to search a string in the code base. Ctrl + Shift + F should do it, but I want to get the list of files in search results.
I tried using the VS Code mand:
mands.executeCommand("workbench.action.findInFiles");
However, it simply did the search but didn't return anything.
Is there an API to get the list of search results?
Share Improve this question edited Apr 4, 2022 at 0:24 Viradex 3,7783 gold badges14 silver badges39 bronze badges asked Jul 18, 2019 at 4:59 yuanOrangeyuanOrange 911 silver badge3 bronze badges 1-
You're asking for a feature that it wouldn't really make sense for VSCode to have. From a programmer's perspective, you need to find by keyword and symbol most often. If you don't, then like @theMayer said, try to use a terminal mand like
find
. – ifconfig Commented Jul 19, 2019 at 6:07
4 Answers
Reset to default 3The Copy All right-click mand in the Search Results pane will get you the entire search results, including the file names.
You can then use regex find/replace to delete the results, leaving only the file names.
Here is how I am getting the files from a search across files result. This is after the workbench.action.findInFiles
mand has been run.
/**
* Get the relative paths of the current search results
* for the next `runInSearchPanel` call
*
* @returns array of paths or undefined
*/
exports.getSearchResultsFiles = async function () {
await vscode.mands.executeCommand('search.action.copyAll');
let results = await vscode.env.clipboard.readText();
if (results) {
// regex to get just the file names
results = results.replaceAll(/^\s*\d.*$\s?|^$\s/gm, "");
let resultsArray = results.split(/[\r\n]{1,2}/); // does this cover all OS's?
let pathArray = resultsArray.filter(result => result !== "");
pathArray = pathArray.map(path => this.getRelativeFilePath(path))
return pathArray.join(", ");
}
else {
// notifyMessage?
return undefined;
}
}
It is designed to get the relative paths of those files, you can change that if you want.
On your search tab, press the little triangle thing next to the search box. It will expand to offer a find/replace in files capability (assuming you’re on the latest version).
Steps:
- Select one file using
ctrl+click
ctrl+A
to select all files- mouse
right click
Copy All
本文标签: javascriptHow to get the list of files in search results in VS codeStack Overflow
版权声明:本文标题:javascript - How to get the list of files in search results in VS code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741516299a2382908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论