Skip to content

Commit

Permalink
Prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertOstermann committed Jul 10, 2024
1 parent 83652b8 commit 0b039b7
Show file tree
Hide file tree
Showing 28 changed files with 361 additions and 437 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
// @typescript
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.vscode-test
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"bracketSameLine": false,
"singleQuote": false,
"jsxSingleQuote": false,
"printWidth": 120,
"tabWidth": 2
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
}
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@
"postdownload-api": "vscode-dts main",
"lint": "eslint src --ext ts",
"fix": "eslint src --ext ts --fix",
"format": "prettier \"**/*.{js,ts,tsx}\" --write",
"format:check": "prettier \"**/*.{js,ts,tsx}\" --check",
"esbuild-base": "rimraf out && esbuild ./src/extension.ts --bundle --outfile=out/src/extension.js --external:vscode --format=cjs --keep-names --platform=node",
"esbuild": "npm run -S esbuild-base -- --sourcemap",
"esbuild-watch": "npm run -S esbuild-base -- --sourcemap --watch",
Expand All @@ -427,7 +429,7 @@
"build-vsix": "vsce package"
},
"dependencies": {
"dotenv": "^16.3.1",
"dotenv": "^16.4.5",
"node-abort-controller": "^2.0.0",
"node-fetch": "^2.6.7"
},
Expand All @@ -436,20 +438,20 @@
"@types/node": "^20.4.2",
"@types/node-fetch": "^2.6.4",
"@types/vscode": "1.63.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"@vscode/dts": "^0.4.1",
"@vscode/test-electron": "^2.4.1",
"@vscode/vsce": "^2.29.0",
"copyfiles": "^2.4.1",
"esbuild": "^0.18.13",
"esbuild": "^0.23.0",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-tsdoc": "^0.2.17",
"glob": "^10.3.3",
"mocha": "^10.2.0",
"typescript": "^5.1.6",
"@vscode/vsce": "^2.15.0",
"@vscode/dts": "^0.4.0",
"@vscode/test-electron": "^2.3.9"
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-tsdoc": "^0.3.0",
"glob": "^11.0.0",
"mocha": "^10.6.0",
"typescript": "^5.5.3"
}
}
51 changes: 22 additions & 29 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,19 @@ export const activate = (context: vscode.ExtensionContext) => {
const formatSelectors = Configuration.formatLanguages();
const linterSelectors = Configuration.linterLanguages();

formatSelectors.forEach(selector => {
formatSelectors.forEach((selector) => {
// Register the "Format Document" command
const formattingProvider = new FormattingEditProvider().activate();
vscode.languages.registerDocumentFormattingEditProvider(
selector,
formattingProvider,
);
vscode.languages.registerDocumentFormattingEditProvider(selector, formattingProvider);

// Register the "Format Selection" command
if (!Configuration.executeInTerminal()) {
const rangeFormattingProvider = new RangeFormattingEditProvider().activate();
vscode.languages.registerDocumentRangeFormattingEditProvider(
selector,
rangeFormattingProvider,
);
vscode.languages.registerDocumentRangeFormattingEditProvider(selector, rangeFormattingProvider);
}
});

linterSelectors.forEach(selector => {
linterSelectors.forEach((selector) => {
// Register the code actions
if (!Configuration.dbtInterfaceEnabled()) {
const codeActionProvider = vscode.languages.registerCodeActionsProvider(selector, new QuickFixProvider(), {
Expand All @@ -53,8 +47,8 @@ export const activate = (context: vscode.ExtensionContext) => {
});

const contextMenuItems = Configuration.formatLanguagesContextMenuItems();
vscode.commands.executeCommand("setContext", "sqlfluff.formatLanguages", formatSelectors)
vscode.commands.executeCommand("setContext", "sqlfluff.contextLanguages", contextMenuItems)
vscode.commands.executeCommand("setContext", "sqlfluff.formatLanguages", formatSelectors);
vscode.commands.executeCommand("setContext", "sqlfluff.contextLanguages", contextMenuItems);

context.subscriptions.push(vscode.commands.registerCommand(EXCLUDE_RULE, ExcludeRules.toggleRule));
context.subscriptions.push(vscode.commands.registerCommand(EXCLUDE_RULE_WORKSPACE, ExcludeRules.toggleRuleWorkspace));
Expand Down Expand Up @@ -94,15 +88,15 @@ export const activate = (context: vscode.ExtensionContext) => {
context.subscriptions.push(vscode.commands.registerCommand(fixCommand, fixCommandHandler));

if (Configuration.dbtInterfaceEnabled()) {
// When dbt-core-interface is enabled, adds a "Format document with
// sqlfluff" button to the lower right corner of the VS Code window. Use
// of the word "format" (vs "fix") is deliberate, as the button hits the
// dbt-core-interface "/format" endpoint, equivalent to "sqlfluff format".
const customStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
customStatusBarItem.text = "$(list-selection) Format SQL";
customStatusBarItem.tooltip = "Format document with sqlfluff";
customStatusBarItem.command = fixCommand;
customStatusBarItem.show();
// When dbt-core-interface is enabled, adds a "Format document with
// sqlfluff" button to the lower right corner of the VS Code window. Use
// of the word "format" (vs "fix") is deliberate, as the button hits the
// dbt-core-interface "/format" endpoint, equivalent to "sqlfluff format".
const customStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
customStatusBarItem.text = "$(list-selection) Format SQL";
customStatusBarItem.tooltip = "Format document with sqlfluff";
customStatusBarItem.command = fixCommand;
customStatusBarItem.show();
}

const formatSelection = "sqlfluff.format.selection";
Expand All @@ -113,19 +107,16 @@ export const activate = (context: vscode.ExtensionContext) => {
const range = new vscode.Range(
vscode.window.activeTextEditor.selection.start,
vscode.window.activeTextEditor.selection.end,
)

const textEdits = await FormatSelectionProvider.provideTextEdits(
document,
range,
);

const textEdits = await FormatSelectionProvider.provideTextEdits(document, range);

textEdits.forEach((textEdit) => {
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.replace(document.uri, textEdit.range, textEdit.newText);

vscode.workspace.applyEdit(workspaceEdit);
})
});
}
};
context.subscriptions.push(vscode.commands.registerCommand(formatSelection, formatSelectionHandler));
Expand All @@ -140,8 +131,10 @@ export const activate = (context: vscode.ExtensionContext) => {
const showOutputChannelCommandHandler = async () => {
Utilities.outputChannel.show();
};
context.subscriptions.push(vscode.commands.registerCommand(showOutputChannelCommand, showOutputChannelCommandHandler));
context.subscriptions.push(
vscode.commands.registerCommand(showOutputChannelCommand, showOutputChannelCommandHandler),
);
};

// eslint-disable-next-line @typescript-eslint/no-empty-function
export const deactivate: any = () => { };
export const deactivate: any = () => {};
25 changes: 15 additions & 10 deletions src/features/helper/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ export class Throttler<T> {
this.activePromise = promiseFactory();

return new Promise<T>((resolve, reject) => {
this.activePromise.then((result: T) => {
// @ts-ignore
this.activePromise = null;
resolve(result);
}, (err: any) => {
// @ts-ignore
this.activePromise = null;
reject(err);
});
this.activePromise.then(
(result: T) => {
// @ts-ignore
this.activePromise = null;
resolve(result);
},
(err: any) => {
// @ts-ignore
this.activePromise = null;
reject(err);
},
);
});
}
}
Expand Down Expand Up @@ -137,6 +140,8 @@ export class ThrottledDelayer<T> extends Delayer<Promise<T>> {

public trigger(promiseFactory: ITask<Promise<T>>, delay?: number): Promise<Promise<T>> {
// @ts-ignore
return super.trigger(() => { return this.throttler.queue(promiseFactory); }, delay);
return super.trigger(() => {
return this.throttler.queue(promiseFactory);
}, delay);
}
}
Loading

0 comments on commit 0b039b7

Please sign in to comment.