DTStack / monaco-sql-languages

SQL languages for monaco-editor
https://dtstack.github.io/monaco-sql-languages/
MIT License
214 stars 42 forks source link

Sql Formatter support #12

Open salvoravida opened 2 years ago

salvoravida commented 2 years ago

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 commented 2 years ago

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