Closed kevcunnane closed 6 years ago
implemented with reusable function, releasing in 0.2.0
async function placescript(fileName, scriptText) {
var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName);
try {
let connection = await sqlops.connection.getCurrentConnection();
let doc = await vscode.workspace.openTextDocument(setting);
let editor = await vscode.window.showTextDocument(doc, 1, false);
editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), scriptText);
});
if (connection) {
await sqlops.queryeditor.connect(doc.uri.toString(), connection.connectionId);
}
} catch (err) {
vscode.window.showErrorMessage(err);
}
}
It'd be great if you could auto-connect to the active connection when you open new query windows for the various sp_blitz import and run commands. It's possible to do this but the APIs are still in a proposed state right now. I've opened https://github.com/Microsoft/sqlopsstudio/issues/2076 to request this to change. Once that's ported in the next release, this'd make it much quicker to go from "I want to run this code" to "my code runs!". You could even use the
queryeditor.runQuery
command to programmatically run it after connect, in the case of therun sp_blitz
command.Basic process one this is done: