Skip to content

Commit

Permalink
Add pgsql 16+ language definition
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Nov 7, 2024
1 parent 7d87e8e commit b87d966
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/pgsql/pgsql.contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { LanguageDefinition } from '../types';

export const pgsqlLanguageDefinition: LanguageDefinition = {
aliases: ['PostgreSQL', 'postgres', 'pg', 'postgre'],
extensions: [],
id: 'pgsql',
loader: () => import('./pgsql.js'),
};
37 changes: 37 additions & 0 deletions src/pgsql/pgsql.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { testTokenization } from '../../test/testRunner';

import { pgsqlLanguageDefinition } from './pgsql.contribution';

// Given this is an extension of the base pgsql language from monaco-editor
// which has tests, then just a simple test to ensure it generally works.

testTokenization('pgsql', pgsqlLanguageDefinition, [
[
{
line: 'SELECT * FROM sch.MyTable WHERE MyColumn IN (1,2)',
tokens: [
{ startIndex: 0, type: 'keyword.sql' },
{ startIndex: 6, type: 'white.sql' },
{ startIndex: 7, type: 'operator.sql' },
{ startIndex: 8, type: 'white.sql' },
{ startIndex: 9, type: 'keyword.sql' },
{ startIndex: 13, type: 'white.sql' },
{ startIndex: 14, type: 'identifier.sql' },
{ startIndex: 17, type: 'delimiter.sql' },
{ startIndex: 18, type: 'identifier.sql' },
{ startIndex: 25, type: 'white.sql' },
{ startIndex: 26, type: 'keyword.sql' },
{ startIndex: 31, type: 'white.sql' },
{ startIndex: 32, type: 'identifier.sql' },
{ startIndex: 40, type: 'white.sql' },
{ startIndex: 41, type: 'operator.sql' },
{ startIndex: 43, type: 'white.sql' },
{ startIndex: 44, type: 'delimiter.parenthesis.sql' },
{ startIndex: 45, type: 'number.sql' },
{ startIndex: 46, type: 'delimiter.sql' },
{ startIndex: 47, type: 'number.sql' },
{ startIndex: 48, type: 'delimiter.parenthesis.sql' },
],
},
],
]);
59 changes: 59 additions & 0 deletions src/pgsql/pgsql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
conf,
language,
} from 'monaco-editor/esm/vs/basic-languages/pgsql/pgsql';

language.builtinFunctions.push(
...[
// pg16 functions
'any_value',
'array_simple',
'array_shuffle',
'date_add',
'date_substract',
'erf',
'erfc',
'json_agg_strict',
'json_array',
'json_arrayagg',
'json_object_agg_strict',
'json_object_agg_unique',
'json_object_agg_unique_strict',
'json_objectagg',
'jsonb_agg_strict',
'jsonb_object_agg_strict',
'jsonb_object_agg_unique',
'jsonb_object_agg_unique_strict',
'pg_input_is_valid',
'pg_input_error_info',
'pg_split_walfile_name',
'random_normal',
// pg17 functions
'icu_unicode_version',
'json',
'json_exists',
'json_query',
'json_scalar',
'json_serialize',
'json_table',
'json_value',
'pg_basetype',
'pg_column_toast_chunk_id',
'pg_sync_replication_slots',
'to_bin',
'to_oct',
'to_regtypemod',
'unicode_assigned',
'unicode_version',
'uuid_extract_timestamp',
'uuid_extract_version',
'xmltext',
],
);

// Re-sort the list of functions, and remove potential duplicates
language.builtinFunctions = (language.builtinFunctions as string[])
.sort()
.filter((x, i, a) => !i || x !== a[i - 1]);

export { conf, language };
5 changes: 1 addition & 4 deletions src/timescale/timescale.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
conf,
language,
} from 'monaco-editor/esm/vs/basic-languages/pgsql/pgsql';
import { conf, language } from '../pgsql/pgsql';

language.builtinFunctions.push(
...[
Expand Down

0 comments on commit b87d966

Please sign in to comment.