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, '处理后的结果');
});
}
}));
}
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
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