Skip to content

Commit 50a6d1f

Browse files
authored
vscode: update comment behavior & auto closing pairs (#690)
I think we could set something up to keep the monaco version in sync with the vscode version
1 parent 2729630 commit 50a6d1f

File tree

3 files changed

+152
-2
lines changed

3 files changed

+152
-2
lines changed

playground/src/App.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,76 @@ function Editor({
282282
editor.onDidBlurEditorText(() => {
283283
onSaveText(editor.getValue())
284284
})
285+
monaco.languages.setLanguageConfiguration("pgsql", {
286+
comments: {
287+
lineComment: "--",
288+
blockComment: ["/*", "*/"],
289+
},
290+
brackets: [
291+
["{", "}"],
292+
["[", "]"],
293+
["(", ")"],
294+
],
295+
autoClosingPairs: [
296+
{ open: "{", close: "}" },
297+
{ open: "[", close: "]" },
298+
{ open: "(", close: ")" },
299+
{ open: '"', close: '"', notIn: ["string"] },
300+
{ open: "$$", close: "$$", notIn: ["string", "comment"] },
301+
{ open: "E'", close: "'", notIn: ["string", "comment"] },
302+
{ open: "e'", close: "'", notIn: ["string", "comment"] },
303+
{ open: "U&'", close: "'", notIn: ["string", "comment"] },
304+
{ open: "u&'", close: "'", notIn: ["string", "comment"] },
305+
{ open: "B'", close: "'", notIn: ["string", "comment"] },
306+
{ open: "b'", close: "'", notIn: ["string", "comment"] },
307+
{ open: "X'", close: "'", notIn: ["string", "comment"] },
308+
{ open: "x'", close: "'", notIn: ["string", "comment"] },
309+
{ open: "N'", close: "'", notIn: ["string", "comment"] },
310+
{ open: "'", close: "'", notIn: ["string", "comment"] },
311+
{ open: "/*", close: " */", notIn: ["string", "comment"] },
312+
],
313+
surroundingPairs: [
314+
{ open: "{", close: "}" },
315+
{ open: "[", close: "]" },
316+
{ open: "(", close: ")" },
317+
{ open: '"', close: '"' },
318+
{ open: "'", close: "'" },
319+
{ open: "`", close: "`" },
320+
{ open: "$$", close: "$$" },
321+
],
322+
onEnterRules: [
323+
{
324+
beforeText: /^\s*--.*$/,
325+
afterText: /\S/,
326+
action: {
327+
indentAction: monaco.languages.IndentAction.None,
328+
appendText: "-- ",
329+
},
330+
},
331+
{
332+
beforeText: /^\s*\/\*/,
333+
afterText: /^\s*\*\/$/,
334+
action: {
335+
indentAction: monaco.languages.IndentAction.IndentOutdent,
336+
appendText: " * ",
337+
},
338+
},
339+
{
340+
beforeText: /^\s*\/\*(?!.*\*\/).*$/,
341+
action: {
342+
indentAction: monaco.languages.IndentAction.None,
343+
appendText: " * ",
344+
},
345+
},
346+
{
347+
beforeText: /^\s*\*(?!\/).*$/,
348+
action: {
349+
indentAction: monaco.languages.IndentAction.None,
350+
appendText: "* ",
351+
},
352+
},
353+
],
354+
})
285355
monaco.languages.register({ id: "rast" })
286356
const tokenProvider = monaco.languages.setMonarchTokensProvider("rast", {
287357
tokenizer: {

squawk-vscode/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"aliases": [
7777
"SQL",
7878
"sql"
79-
]
79+
],
80+
"configuration": "./sql-language-configuration.json"
8081
},
8182
{
8283
"id": "postgres",
@@ -86,7 +87,8 @@
8687
"aliases": [
8788
"PostgreSQL",
8889
"postgres"
89-
]
90+
],
91+
"configuration": "./sql-language-configuration.json"
9092
}
9193
],
9294
"configuration": {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Based on https://github.com/microsoft/vscode/blob/bb0294ffca5583a768e5ea44350ecc4e9c6e3791/extensions/sql/language-configuration.json
2+
{
3+
"comments": {
4+
"lineComment": "--",
5+
"blockComment": ["/*", "*/"]
6+
},
7+
"brackets": [
8+
["{", "}"],
9+
["[", "]"],
10+
["(", ")"]
11+
],
12+
"autoClosingPairs": [
13+
["{", "}"],
14+
["[", "]"],
15+
["(", ")"],
16+
{ "open": "\"", "close": "\"", "notIn": ["string"] },
17+
{ "open": "$$", "close": "$$", "notIn": ["string", "comment"] },
18+
{ "open": "E'", "close": "'", "notIn": ["string", "comment"] },
19+
{ "open": "e'", "close": "'", "notIn": ["string", "comment"] },
20+
{ "open": "U&'", "close": "'", "notIn": ["string", "comment"] },
21+
{ "open": "u&'", "close": "'", "notIn": ["string", "comment"] },
22+
{ "open": "B'", "close": "'", "notIn": ["string", "comment"] },
23+
{ "open": "b'", "close": "'", "notIn": ["string", "comment"] },
24+
{ "open": "X'", "close": "'", "notIn": ["string", "comment"] },
25+
{ "open": "x'", "close": "'", "notIn": ["string", "comment"] },
26+
{ "open": "N'", "close": "'", "notIn": ["string", "comment"] },
27+
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
28+
{ "open": "/*", "close": " */", "notIn": ["string", "comment"] }
29+
],
30+
"surroundingPairs": [
31+
["{", "}"],
32+
["[", "]"],
33+
["(", ")"],
34+
["\"", "\""],
35+
["'", "'"],
36+
["`", "`"],
37+
["$$", "$$"]
38+
],
39+
"folding": {
40+
"offSide": true,
41+
"markers": {
42+
"start": "^\\s*--\\s*#region\\b",
43+
"end": "^\\s*--\\s*#endregion\\b"
44+
}
45+
},
46+
"onEnterRules": [
47+
{
48+
"beforeText": "^\\s*--.*$",
49+
"afterText": "\\S",
50+
"action": {
51+
"indent": "none",
52+
"appendText": "-- "
53+
}
54+
},
55+
{
56+
"beforeText": "^\\s*\\/\\*",
57+
"afterText": "^\\s*\\*\\/$",
58+
"action": {
59+
"indent": "indentOutdent",
60+
"appendText": " * "
61+
}
62+
},
63+
{
64+
"beforeText": "^\\s*\\/\\*(?!.*\\*\\/).*$",
65+
"action": {
66+
"indent": "none",
67+
"appendText": " * "
68+
}
69+
},
70+
{
71+
"beforeText": "^\\s*\\*(?!\\/).*$",
72+
"action": {
73+
"indent": "none",
74+
"appendText": "* "
75+
}
76+
}
77+
]
78+
}

0 commit comments

Comments
 (0)