@@ -24,6 +24,7 @@ import {
2424 provideCompletionItems ,
2525 semanticTokensProvider ,
2626} from "./providers"
27+ import { language as pgsqlMonarchLanguage } from "./pgsql"
2728import BUILTINS_SQL from "./builtins.sql?raw"
2829
2930const modes = [ "Lint" , "Syntax Tree" , "Tokens" ] as const
@@ -282,6 +283,77 @@ function assertNever(x: never): never {
282283 throw new Error ( `expected never, got ${ x } ` )
283284}
284285
286+ const pgsqlConfig : monaco . languages . LanguageConfiguration = {
287+ comments : {
288+ lineComment : "--" ,
289+ blockComment : [ "/*" , "*/" ] ,
290+ } ,
291+ brackets : [
292+ [ "{" , "}" ] ,
293+ [ "[" , "]" ] ,
294+ [ "(" , ")" ] ,
295+ ] ,
296+ autoClosingPairs : [
297+ { open : "{" , close : "}" } ,
298+ { open : "[" , close : "]" } ,
299+ { open : "(" , close : ")" } ,
300+ { open : '"' , close : '"' , notIn : [ "string" ] } ,
301+ { open : "$$" , close : "$$" , notIn : [ "string" , "comment" ] } ,
302+ { open : "E'" , close : "'" , notIn : [ "string" , "comment" ] } ,
303+ { open : "e'" , close : "'" , notIn : [ "string" , "comment" ] } ,
304+ { open : "U&'" , close : "'" , notIn : [ "string" , "comment" ] } ,
305+ { open : "u&'" , close : "'" , notIn : [ "string" , "comment" ] } ,
306+ { open : "B'" , close : "'" , notIn : [ "string" , "comment" ] } ,
307+ { open : "b'" , close : "'" , notIn : [ "string" , "comment" ] } ,
308+ { open : "X'" , close : "'" , notIn : [ "string" , "comment" ] } ,
309+ { open : "x'" , close : "'" , notIn : [ "string" , "comment" ] } ,
310+ { open : "N'" , close : "'" , notIn : [ "string" , "comment" ] } ,
311+ { open : "'" , close : "'" , notIn : [ "string" , "comment" ] } ,
312+ { open : "/*" , close : " */" , notIn : [ "string" , "comment" ] } ,
313+ ] ,
314+ surroundingPairs : [
315+ { open : "{" , close : "}" } ,
316+ { open : "[" , close : "]" } ,
317+ { open : "(" , close : ")" } ,
318+ { open : '"' , close : '"' } ,
319+ { open : "'" , close : "'" } ,
320+ { open : "`" , close : "`" } ,
321+ { open : "$$" , close : "$$" } ,
322+ ] ,
323+ onEnterRules : [
324+ {
325+ beforeText : / ^ \s * - - .* $ / ,
326+ afterText : / \S / ,
327+ action : {
328+ indentAction : monaco . languages . IndentAction . None ,
329+ appendText : "-- " ,
330+ } ,
331+ } ,
332+ {
333+ beforeText : / ^ \s * \/ \* / ,
334+ afterText : / ^ \s * \* \/ $ / ,
335+ action : {
336+ indentAction : monaco . languages . IndentAction . IndentOutdent ,
337+ appendText : " * " ,
338+ } ,
339+ } ,
340+ {
341+ beforeText : / ^ \s * \/ \* (? ! .* \* \/ ) .* $ / ,
342+ action : {
343+ indentAction : monaco . languages . IndentAction . None ,
344+ appendText : " * " ,
345+ } ,
346+ } ,
347+ {
348+ beforeText : / ^ \s * \* (? ! \/ ) .* $ / ,
349+ action : {
350+ indentAction : monaco . languages . IndentAction . None ,
351+ appendText : "* " ,
352+ } ,
353+ } ,
354+ ] ,
355+ }
356+
285357let monacoGlobalProvidersRegistered = false
286358// Only want to register these once, otherwise we'll end up with multiple
287359// providers running and get dupe results for things like hover
@@ -299,76 +371,15 @@ function registerMonacoProvidersOnce() {
299371 rules : [ { token : "variable" , foreground : "D4D4D4" } ] ,
300372 colors : { } ,
301373 } )
302- const languageConfig = monaco . languages . setLanguageConfiguration ( "pgsql" , {
303- comments : {
304- lineComment : "--" ,
305- blockComment : [ "/*" , "*/" ] ,
306- } ,
307- brackets : [
308- [ "{" , "}" ] ,
309- [ "[" , "]" ] ,
310- [ "(" , ")" ] ,
311- ] ,
312- autoClosingPairs : [
313- { open : "{" , close : "}" } ,
314- { open : "[" , close : "]" } ,
315- { open : "(" , close : ")" } ,
316- { open : '"' , close : '"' , notIn : [ "string" ] } ,
317- { open : "$$" , close : "$$" , notIn : [ "string" , "comment" ] } ,
318- { open : "E'" , close : "'" , notIn : [ "string" , "comment" ] } ,
319- { open : "e'" , close : "'" , notIn : [ "string" , "comment" ] } ,
320- { open : "U&'" , close : "'" , notIn : [ "string" , "comment" ] } ,
321- { open : "u&'" , close : "'" , notIn : [ "string" , "comment" ] } ,
322- { open : "B'" , close : "'" , notIn : [ "string" , "comment" ] } ,
323- { open : "b'" , close : "'" , notIn : [ "string" , "comment" ] } ,
324- { open : "X'" , close : "'" , notIn : [ "string" , "comment" ] } ,
325- { open : "x'" , close : "'" , notIn : [ "string" , "comment" ] } ,
326- { open : "N'" , close : "'" , notIn : [ "string" , "comment" ] } ,
327- { open : "'" , close : "'" , notIn : [ "string" , "comment" ] } ,
328- { open : "/*" , close : " */" , notIn : [ "string" , "comment" ] } ,
329- ] ,
330- surroundingPairs : [
331- { open : "{" , close : "}" } ,
332- { open : "[" , close : "]" } ,
333- { open : "(" , close : ")" } ,
334- { open : '"' , close : '"' } ,
335- { open : "'" , close : "'" } ,
336- { open : "`" , close : "`" } ,
337- { open : "$$" , close : "$$" } ,
338- ] ,
339- onEnterRules : [
340- {
341- beforeText : / ^ \s * - - .* $ / ,
342- afterText : / \S / ,
343- action : {
344- indentAction : monaco . languages . IndentAction . None ,
345- appendText : "-- " ,
346- } ,
347- } ,
348- {
349- beforeText : / ^ \s * \/ \* / ,
350- afterText : / ^ \s * \* \/ $ / ,
351- action : {
352- indentAction : monaco . languages . IndentAction . IndentOutdent ,
353- appendText : " * " ,
354- } ,
355- } ,
356- {
357- beforeText : / ^ \s * \/ \* (? ! .* \* \/ ) .* $ / ,
358- action : {
359- indentAction : monaco . languages . IndentAction . None ,
360- appendText : " * " ,
361- } ,
362- } ,
363- {
364- beforeText : / ^ \s * \* (? ! \/ ) .* $ / ,
365- action : {
366- indentAction : monaco . languages . IndentAction . None ,
367- appendText : "* " ,
368- } ,
369- } ,
370- ] ,
371- } )
374+ const languageConfig = monaco . languages . setLanguageConfiguration (
375+ "pgsql" ,
376+ pgsqlConfig ,
377+ )
378+ const pgsqlTokenProvider = monaco . languages . setMonarchTokensProvider (
379+ "pgsql" ,
380+ pgsqlMonarchLanguage ,
381+ )
382+
372383 monaco . languages . register ( { id : "rast" } )
373384 const tokenProvider = monaco . languages . setMonarchTokensProvider ( "rast" , {
374385 tokenizer : {
@@ -492,6 +503,7 @@ function registerMonacoProvidersOnce() {
492503
493504 return ( ) => {
494505 languageConfig . dispose ( )
506+ pgsqlTokenProvider . dispose ( )
495507 codeActionProvider . dispose ( )
496508 hoverProvider . dispose ( )
497509 definitionProvider . dispose ( )
0 commit comments