作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在代码库中搜索字符串。 Ctrl + Shift + F 应该这样做,但我想在搜索结果中获取文件列表。
我尝试使用 VS Code 命令:
commands.executeCommand("workbench.action.findInFiles");
但是,它只是进行了搜索,但没有返回任何内容。
最佳答案
这是我从跨文件搜索结果中获取文件的方式。这是在 workbench.action.findInFiles
之后命令已运行。
/**
* 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.commands.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;
}
}
它旨在获取这些文件的相对路径,您可以根据需要进行更改。
关于javascript - 如何在 VS 代码中获取搜索结果中的文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57087400/
我是一名优秀的程序员,十分优秀!