monaco-sql-languages icon indicating copy to clipboard operation
monaco-sql-languages copied to clipboard

Sql Formatter support

Open salvoravida opened this issue 2 years ago • 1 comments

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,
         },
      ];
   },
});

salvoravida avatar Jul 06 '22 09:07 salvoravida

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

wewoor avatar Jul 07 '22 02:07 wewoor