https://code.visualstudio.com/api/get-started/your-first-extensionnpm install -g yo generator-code
yo code
Select ts or js for normal development.
The results are as follows. The contributions.commands node of package.json controls the command life, and
contributes.menus defines the menu
extension.ts . Register events inside
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('extension.sqltool.execSql', () => {
// vscode.window.showInformationMessage('not implemention!');
const editor = vscode.window.activeTextEditor;
if (editor) {
const document = editor.document;
const inputText = document.getText();
editor.edit(editBuilder => {
const start = new vscode.Position(0, 0);
const end = new vscode.Position(document.lineCount, 0);
const range = new vscode.Range(start, end);
editBuilder.replace(range, '处理后的结果');
});
}
}));
}
![](https://img-blog.csdnimg.cn/img_convert/7e255477398ec0d9d4b132d3bfad7705.webp?x-oss-process=image/format,png)
![](https://img-blog.csdnimg.cn/img_convert/5c36e3b3c84179907e813048beaf8c79.webp?x-oss-process=image/format,png)
tsc -watch -p ./
Converting ts code to js code and monitoring it in real time npm run compile
has the same effect
. The actual definition of running the extension is as follows
![](https://img-blog.csdnimg.cn/img_convert/3bae62de71e68618c0ec6d51b384a02c.webp?x-oss-process=image/format,png)
If it does not work, you should update the new version of vscode.
https://astexplorer.net/ can be combined with babel to replace the code content, but I think simple things are complicated. I used row scanning to complete a stored procedure that is directly converted into sql code.
publish extension
npm install -g @vscode/vsce
vsve publish
获取tokenhttps://marketplace.visualstudio.com/manage/publishers/https://dev.azure.com/lozn/_usersSettings/tokens
![](https://img-blog.csdnimg.cn/img_convert/488b88531efddd6a7b68f48ce9d2d0ff.webp?x-oss-process=image/format,png)
![](https://img-blog.csdnimg.cn/img_convert/2e93d81922fc5c85d86f4395824ca7f9.webp?x-oss-process=image/format,png)