diff --git a/package-lock.json b/package-lock.json index 71dc8f7..810c736 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "poor-mans-t-sql-formatter-pg", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4dd4bd8..f540a69 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "poor-mans-t-sql-formatter-pg", "displayName": "poor-mans-t-sql-formatter-pg", "description": "", - "version": "0.1.2", + "version": "0.1.3", "publisher": "piotrgredowski", "repository": "https://github.com/piotrgredowski/poor-mans-t-sql-formatter-vscode-extension", "engines": { diff --git a/src/begger.ts b/src/begger.ts new file mode 100644 index 0000000..3c048e4 --- /dev/null +++ b/src/begger.ts @@ -0,0 +1,28 @@ +import * as vscode from "vscode"; + +export function askForStar(context: vscode.ExtensionContext) { + const askForStarKey = "didAskForStart"; + const didAlreadyAsk = !!context.globalState.get(askForStarKey); + + if (didAlreadyAsk) { + return; + } + + const superAnswer = "Ok"; + const closeAnswer = "Close"; + vscode.window + .showInformationMessage( + `If you like this extension and it helps you - consider giving it a star on ` + + `[Github](https://github.com/piotrgredowski/poor-mans-t-sql-formatter-vscode-extension) or writing a review in ` + + `[VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=piotrgredowski.poor-mans-t-sql-formatter-pg&ssr=false#review-details) to make maintainer motivated!`, + { modal: false }, + ...[superAnswer, closeAnswer] + ) + .then((answer) => { + context.globalState.update(askForStarKey, false); + + if (answer === superAnswer) { + vscode.window.showInformationMessage("Thank you!", closeAnswer); + } + }); +} diff --git a/src/extension.ts b/src/extension.ts index b8a7001..2e19f98 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,13 +1,17 @@ -import * as vscode from 'vscode'; -import { formatDocument } from './lib'; +import * as vscode from "vscode"; +import { askForStar } from "./begger"; +import { formatDocument } from "./lib"; let commandsDisposables: vscode.Disposable[] = []; function _format(shoudlFormatSelection: boolean) { const { activeTextEditor } = vscode.window; - if (!!activeTextEditor && activeTextEditor.document.languageId === 'sql') { + if (!!activeTextEditor && activeTextEditor.document.languageId === "sql") { const options = activeTextEditor.options; - const edit = formatDocument(options as vscode.FormattingOptions, shoudlFormatSelection); + const edit = formatDocument( + options as vscode.FormattingOptions, + shoudlFormatSelection + ); if (!!edit) { activeTextEditor.edit((editBuilder) => { editBuilder.replace(edit[0].range, edit[0].newText); @@ -24,20 +28,26 @@ function formatSelection() { export function activate(context: vscode.ExtensionContext) { commandsDisposables.push( - vscode.commands.registerCommand('poor-mans-t-sql-formatter-pg.poorFormatSql', () => { - formatWhole(); - }), - vscode.commands.registerCommand('poor-mans-t-sql-formatter-pg.poorFormatSelectionSql', () => { - formatSelection(); - }), + vscode.commands.registerCommand( + "poor-mans-t-sql-formatter-pg.poorFormatSql", + () => { + formatWhole(); + } + ), + vscode.commands.registerCommand( + "poor-mans-t-sql-formatter-pg.poorFormatSelectionSql", + () => { + formatSelection(); + } + ) ); context.subscriptions.push(...commandsDisposables); - vscode.languages.registerDocumentFormattingEditProvider('sql', { + vscode.languages.registerDocumentFormattingEditProvider("sql", { provideDocumentFormattingEdits( document: vscode.TextDocument, - options: vscode.FormattingOptions, + options: vscode.FormattingOptions ): vscode.TextEdit[] { const result = formatDocument(options, false); if (result !== undefined) { @@ -47,6 +57,8 @@ export function activate(context: vscode.ExtensionContext) { } }, }); + + askForStar(context); } export function deactivate() {