Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql Formatter support #12

Open
salvoravida opened this issue Jul 6, 2022 · 1 comment
Open

Sql Formatter support #12

salvoravida opened this issue Jul 6, 2022 · 1 comment

Comments

@salvoravida
Copy link
Contributor

salvoravida commented Jul 6, 2022

Hi there, thanks for this lib!

I have added support for formatting, lmk if you'd like a PR

it's pretty simple, something like this:

import { languages } from 'monaco-editor/esm/vs/editor/editor.api';
import { format } from 'sql-formatter';

languages.registerDocumentFormattingEditProvider('sql', {
   provideDocumentFormattingEdits(model, options) {
      const formatted = format(model.getValue(), {
         indentStyle: 'standard',
      });
      return [
         {
            range: model.getFullModelRange(),
            text: formatted,
         },
      ];
   },
});

languages.registerDocumentRangeFormattingEditProvider('sql', {
   provideDocumentRangeFormattingEdits(model, range, options) {
      const formatted = format(model.getValueInRange(range), {
         indentStyle: 'standard',
      });
      return [
         {
            range: range,
            text: formatted,
         },
      ];
   },
});
@wewoor
Copy link
Collaborator

wewoor commented Jul 7, 2022

Hi, @salvoravida, we are very welcome your contribution. But there needs to integrate of many kinds of SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants