Skip to content

Commit

Permalink
🚀 Add query formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Javaloyes committed Feb 5, 2023
1 parent 89d9db4 commit 24ac480
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
40 changes: 36 additions & 4 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"react-dom": "^18.0.0",
"react-hotkeys-hook": "3.4.7",
"react-router-dom": "^6.4.3",
"react-split": "2.0.14"
"react-split": "2.0.14",
"sql-formatter": "^12.1.0"
},
"devDependencies": {
"@playwright/test": "1.27.1",
Expand Down
20 changes: 18 additions & 2 deletions src/hooks/useMonacoConfigSupplier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useUrlState } from "./useUrlState";
import { initialState } from "../hooks/useQueryForm";
import { usePasswordContext } from "../contexts/usePassword";
import { getTablesSuggestionProvider } from "../lib/editor-suggestions/tables.suggestion";
import { format } from 'sql-formatter';

type Params = {
jsonParams: string;
Expand All @@ -26,15 +27,30 @@ export const useMonacoConfigSupplier = ({ jsonParams }: Params) => {
subs.push(
monaco.languages.registerCompletionItemProvider(
paremeterSnippetSuggetionProvider.language,
paremeterSnippetSuggetionProvider.provider
)
paremeterSnippetSuggetionProvider.provider,
),
);
subs.push(
monaco.languages.registerCompletionItemProvider(
paremeterTypeSuggetionProvider.language,
paremeterTypeSuggetionProvider.provider
)
);
subs.push(
monaco.languages.registerDocumentFormattingEditProvider('sql', {
async provideDocumentFormattingEdits(model) {

const text = format(model.getValue(), { language: 'sql' , });
return [
{
range: model.getFullModelRange(),
text,
},
];
},
})

)
}
return () => {
subs.forEach((sub) => sub.dispose());
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useQueryForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const useQueryForm = ({
},
]);


return {
HotKeysHelpDialog,
openHelpDialog,
Expand Down

0 comments on commit 24ac480

Please sign in to comment.