我用谷歌搜索了很多,没有找到任何有效的方法来搜索里面的特定文件vscode.workspace
并替换找到的术语。
所以基本上我想搜索vscode.workspace
一个名为 app.component.ts 的文件,并检查该文件是否包含 // my-marker。如果是这样,这个标记应该被其他一些字符串替换。
有人知道这是否可能吗?如果是这样,怎么办?这是我的方法:
function createAppEnvironment(name: string)
{
if(name != undefined)
{
// replace all blanks ' ' with dashes '-'
name = name.replace(/\w/g, '-');
vscode.workspace.findFiles('app/app.component.ts', '', 1).then(
// all good
(result: vscode.Uri[]) => {
vscode.workspace.openTextDocument(result[0]);
vscode.commands.executeCommand('edit.findAndReplace');
},
// rejected
(reason: any) => {
// output error
vscode.window.showErrorMessage(reason);
});
// Display a message box to the user
// vscode.window.showInformationMessage('Successfully created a new App!');
}
else
{
vscode.window.showWarningMessage("Nothing was created, due to the fact that you haven't entered a name.");
}
}