I googled a lot and did not find any working way to search inside a specific file inside the vscode.workspace and replace the found terms.
So basicly I want to search the vscode.workspace for a file named app.component.ts, and check if the file contains a // my-marker. If so this marker should be replaced by some other string.
Does anybody know if this is possible? And if so, how? This is my approach:
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.");
}
}
I haven't done this myself, so I'm kinda winging it here...
Instead of opening find/replace:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With