Skip to content

Commit

Permalink
Add popup asking for star/review - but only once for each installation
Browse files Browse the repository at this point in the history
0.1.3
  • Loading branch information
piotrgredowski committed Jul 8, 2022
1 parent 2c4cc92 commit d4bebf5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
28 changes: 28 additions & 0 deletions src/begger.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
36 changes: 24 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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) {
Expand All @@ -47,6 +57,8 @@ export function activate(context: vscode.ExtensionContext) {
}
},
});

askForStar(context);
}

export function deactivate() {
Expand Down

0 comments on commit d4bebf5

Please sign in to comment.