vscode.workspace
私はたくさんグーグルで調べましたが、特定のファイル内を検索して見つかった用語を置き換える有効な方法が見つかりませんでした。
基本的に、 app.component.tsという名前のファイルを検索し、そのファイルに // my-marker が含まれているかどうかを確認します。vscode.workspace
その場合、このマーカーは他の文字列に置き換える必要があります。
これが可能かどうか誰にもわかりますか?もしそうなら、どのように?これが私のアプローチです:
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.");
}
}