Sfoglia il codice sorgente

[editor] Port Ace editor v2 to use the new js formatter

Romain Rigaux 4 anni fa
parent
commit
ff6a27a9fa
1 ha cambiato i file con 7 aggiunte e 14 eliminazioni
  1. 7 14
      desktop/core/src/desktop/js/apps/editor/api.ts

+ 7 - 14
desktop/core/src/desktop/js/apps/editor/api.ts

@@ -14,30 +14,23 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+import { format } from '@gethue/sql-formatter';
 import { ExecutionStatus } from './execution/executable';
 import { CancellablePromise } from 'api/cancellablePromise';
-import { get, post } from 'api/utils';
+import { get } from 'api/utils';
 
-const FORMAT_SQL_API_URL = '/notebook/api/format';
 const HISTORY_API_URL = '/notebook/api/get_history';
 
-interface FormatSqlApiResponse {
-  formatted_statements?: string;
-  status: number;
-}
-
 export const formatSql = async (options: {
   statements: string;
   silenceErrors?: boolean;
 }): Promise<string> => {
   try {
-    const params = new URLSearchParams();
-    params.append('statements', options.statements);
-    const response = await post<FormatSqlApiResponse>(FORMAT_SQL_API_URL, params);
-
-    if (response.status !== -1 && response.formatted_statements) {
-      return response.formatted_statements;
-    }
+    return format(options.statements, {
+      uppercase: true,
+      linesBetweenQueries: 2,
+      indentQuerySeparator: true
+    });
   } catch (err) {
     if (!options.silenceErrors) {
       throw err;