From 6eff782854ad27145cf1dc91007a5cfc7cd5ef74 Mon Sep 17 00:00:00 2001 From: gerneio Date: Tue, 30 Apr 2019 17:48:30 -0500 Subject: [PATCH 1/2] Default Keybind Add support for the built in format keybinding SHIFT+ALT+F --- extension.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/extension.js b/extension.js index 67f04d0..3a0f95e 100644 --- a/extension.js +++ b/extension.js @@ -39,8 +39,9 @@ function collectOptions(extensionOptions) { var commandDisposable; -function activate(context) { - commandDisposable = vscode.commands.registerCommand('poor-mans-t-sql-formatter.formatSql', () => { +function activate(context) { + + var EditText = () => { let editor = vscode.window.activeTextEditor; let doc = editor.document; @@ -103,8 +104,21 @@ function activate(context) { } }); }).catch(e => {console.log(e); throw e;}); - }); + }; + + var fmtProv = vscode.languages.registerDocumentFormattingEditProvider( { language: 'sql' }, { + provideDocumentFormattingEdits: function( document ) + { + return EditText(); + } + } ); + + context.subscriptions.push(fmtProv); + + + commandDisposable = vscode.commands.registerCommand('poor-mans-t-sql-formatter.formatSql', EditText); + context.subscriptions.push(commandDisposable); } exports.activate = activate; @@ -113,4 +127,4 @@ function deactivate() { if (commandDisposable) commandDisposable.dispose(); } -exports.deactivate = deactivate; \ No newline at end of file +exports.deactivate = deactivate; From c36926d6c4d81660d745170bbc97b8de7e8829ee Mon Sep 17 00:00:00 2001 From: gerneio Date: Tue, 30 Apr 2019 17:55:11 -0500 Subject: [PATCH 2/2] Activate on SQL file --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d2f72cc..bae6100 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "Other" ], "activationEvents": [ - "onCommand:poor-mans-t-sql-formatter.formatSql" + "onCommand:poor-mans-t-sql-formatter.formatSql", + "onLanguage:sql" ], "license": "AGPL-3.0", "bugs": {