From 747fbb09a5c28bffb1a3df6ac48eb38a01c9deea Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Mon, 13 Oct 2025 14:33:26 -0400 Subject: [PATCH] vscode: update comment behavior & auto closing pairs I think we could set something up to keep the monaco version in sync with the vscode version --- playground/src/App.tsx | 70 +++++++++++++++++ squawk-vscode/package.json | 6 +- squawk-vscode/sql-language-configuration.json | 78 +++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 squawk-vscode/sql-language-configuration.json diff --git a/playground/src/App.tsx b/playground/src/App.tsx index cf91b5de..dece20cd 100644 --- a/playground/src/App.tsx +++ b/playground/src/App.tsx @@ -282,6 +282,76 @@ function Editor({ editor.onDidBlurEditorText(() => { onSaveText(editor.getValue()) }) + monaco.languages.setLanguageConfiguration("pgsql", { + comments: { + lineComment: "--", + blockComment: ["/*", "*/"], + }, + brackets: [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ], + autoClosingPairs: [ + { open: "{", close: "}" }, + { open: "[", close: "]" }, + { open: "(", close: ")" }, + { open: '"', close: '"', notIn: ["string"] }, + { open: "$$", close: "$$", notIn: ["string", "comment"] }, + { open: "E'", close: "'", notIn: ["string", "comment"] }, + { open: "e'", close: "'", notIn: ["string", "comment"] }, + { open: "U&'", close: "'", notIn: ["string", "comment"] }, + { open: "u&'", close: "'", notIn: ["string", "comment"] }, + { open: "B'", close: "'", notIn: ["string", "comment"] }, + { open: "b'", close: "'", notIn: ["string", "comment"] }, + { open: "X'", close: "'", notIn: ["string", "comment"] }, + { open: "x'", close: "'", notIn: ["string", "comment"] }, + { open: "N'", close: "'", notIn: ["string", "comment"] }, + { open: "'", close: "'", notIn: ["string", "comment"] }, + { open: "/*", close: " */", notIn: ["string", "comment"] }, + ], + surroundingPairs: [ + { open: "{", close: "}" }, + { open: "[", close: "]" }, + { open: "(", close: ")" }, + { open: '"', close: '"' }, + { open: "'", close: "'" }, + { open: "`", close: "`" }, + { open: "$$", close: "$$" }, + ], + onEnterRules: [ + { + beforeText: /^\s*--.*$/, + afterText: /\S/, + action: { + indentAction: monaco.languages.IndentAction.None, + appendText: "-- ", + }, + }, + { + beforeText: /^\s*\/\*/, + afterText: /^\s*\*\/$/, + action: { + indentAction: monaco.languages.IndentAction.IndentOutdent, + appendText: " * ", + }, + }, + { + beforeText: /^\s*\/\*(?!.*\*\/).*$/, + action: { + indentAction: monaco.languages.IndentAction.None, + appendText: " * ", + }, + }, + { + beforeText: /^\s*\*(?!\/).*$/, + action: { + indentAction: monaco.languages.IndentAction.None, + appendText: "* ", + }, + }, + ], + }) monaco.languages.register({ id: "rast" }) const tokenProvider = monaco.languages.setMonarchTokensProvider("rast", { tokenizer: { diff --git a/squawk-vscode/package.json b/squawk-vscode/package.json index b7d9d643..565da630 100644 --- a/squawk-vscode/package.json +++ b/squawk-vscode/package.json @@ -76,7 +76,8 @@ "aliases": [ "SQL", "sql" - ] + ], + "configuration": "./sql-language-configuration.json" }, { "id": "postgres", @@ -86,7 +87,8 @@ "aliases": [ "PostgreSQL", "postgres" - ] + ], + "configuration": "./sql-language-configuration.json" } ], "configuration": { diff --git a/squawk-vscode/sql-language-configuration.json b/squawk-vscode/sql-language-configuration.json new file mode 100644 index 00000000..343f854c --- /dev/null +++ b/squawk-vscode/sql-language-configuration.json @@ -0,0 +1,78 @@ +// Based on https://github.com/microsoft/vscode/blob/bb0294ffca5583a768e5ea44350ecc4e9c6e3791/extensions/sql/language-configuration.json +{ + "comments": { + "lineComment": "--", + "blockComment": ["/*", "*/"] + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + { "open": "\"", "close": "\"", "notIn": ["string"] }, + { "open": "$$", "close": "$$", "notIn": ["string", "comment"] }, + { "open": "E'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "e'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "U&'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "u&'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "B'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "b'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "X'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "x'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "N'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "/*", "close": " */", "notIn": ["string", "comment"] } + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"], + ["`", "`"], + ["$$", "$$"] + ], + "folding": { + "offSide": true, + "markers": { + "start": "^\\s*--\\s*#region\\b", + "end": "^\\s*--\\s*#endregion\\b" + } + }, + "onEnterRules": [ + { + "beforeText": "^\\s*--.*$", + "afterText": "\\S", + "action": { + "indent": "none", + "appendText": "-- " + } + }, + { + "beforeText": "^\\s*\\/\\*", + "afterText": "^\\s*\\*\\/$", + "action": { + "indent": "indentOutdent", + "appendText": " * " + } + }, + { + "beforeText": "^\\s*\\/\\*(?!.*\\*\\/).*$", + "action": { + "indent": "none", + "appendText": " * " + } + }, + { + "beforeText": "^\\s*\\*(?!\\/).*$", + "action": { + "indent": "none", + "appendText": "* " + } + } + ] +}