Skip to content

Commit 83364d3

Browse files
authored
feat: syntax highlighting in documentation comments (#690)
Closes partially #669 ### Summary of Changes Highlight tags in documentation comments: ![image](https://github.com/Safe-DS/DSL/assets/2501322/940096a3-a248-4856-bd47-b1ecd7aa8fa5)
1 parent ff70b07 commit 83364d3

File tree

3 files changed

+119
-89
lines changed

3 files changed

+119
-89
lines changed

src/language/lsp/safe-ds-semantic-token-provider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
isSdsPipeline,
2525
isSdsPlaceholder,
2626
isSdsReference,
27+
isSdsResult,
2728
isSdsSchema,
2829
isSdsSegment,
2930
isSdsTypeArgument,
@@ -207,6 +208,12 @@ export class SafeDsSemanticTokenProvider extends AbstractSemanticTokenProvider {
207208
type: SemanticTokenTypes.variable,
208209
modifier: [SemanticTokenModifiers.readonly, ...additionalModifiers],
209210
};
211+
} else if (isSdsResult(node)) {
212+
return {
213+
// For lack of a better option, we use the token type for parameters here
214+
type: SemanticTokenTypes.parameter,
215+
modifier: additionalModifiers,
216+
};
210217
} else if (isSdsSchema(node)) {
211218
return {
212219
type: SemanticTokenTypes.type,

syntaxes/safe-ds.tmLanguage.json

Lines changed: 107 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,116 @@
11
{
2-
"name": "safe-ds",
3-
"scopeName": "source.safe-ds",
4-
"fileTypes": [
5-
".sdspipe",
6-
".sdsstub",
7-
".sdstest"
8-
],
9-
"patterns": [
10-
{
11-
"include": "#comments"
12-
},
13-
{
14-
"name": "constant.numeric.safe-ds",
15-
"match": "\\b([0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?)\\b"
16-
},
17-
{
18-
"name": "constant.language.safe-ds",
19-
"match": "\\b(false|null|true)\\b"
20-
},
21-
{
22-
"name": "storage.type.safe-ds",
23-
"match": "\\b(annotation|attr|class|enum|fun|package|pipeline|schema|segment|val)\\b"
24-
},
25-
{
26-
"name": "storage.modifier.safe-ds",
27-
"match": "\\b(const|in|internal|out|private|static)\\b"
28-
},
29-
{
30-
"name": "keyword.operator.safe-ds",
31-
"match": "\\b(and|not|or|sub|super)\\b"
32-
},
33-
{
34-
"name": "keyword.other.safe-ds",
35-
"match": "\\b(as|from|import|literal|union|where|yield)\\b"
36-
},
37-
{
38-
"name": "meta.safe-ds",
39-
"begin": "\\`",
40-
"end": "\\`"
41-
},
42-
{
43-
"name": "string.interpolated.safe-ds",
44-
"begin": "\"|}}",
45-
"end": "{{|\"",
46-
"patterns": [
2+
"name": "safe-ds",
3+
"scopeName": "source.safe-ds",
4+
"fileTypes": [
5+
".sdspipe",
6+
".sdsstub",
7+
".sdstest"
8+
],
9+
"patterns": [
4710
{
48-
"include": "#string-character-escape"
49-
}
50-
]
51-
},
52-
{
53-
"name": "string.quoted.double.safe-ds",
54-
"begin": "\"",
55-
"end": "\"",
56-
"patterns": [
11+
"include": "#comments"
12+
},
5713
{
58-
"include": "#string-character-escape"
59-
}
60-
]
61-
}
62-
],
63-
"repository": {
64-
"comments": {
65-
"patterns": [
14+
"name": "constant.numeric.safe-ds",
15+
"match": "\\b([0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?)\\b"
16+
},
6617
{
67-
"name": "comment.line.double-slash.safe-ds",
68-
"begin": "//",
69-
"beginCaptures": {
70-
"1": {
71-
"name": "punctuation.whitespace.comment.leading.safe-ds"
72-
}
73-
},
74-
"end": "(?=$)"
18+
"name": "constant.language.safe-ds",
19+
"match": "\\b(false|null|true)\\b"
7520
},
7621
{
77-
"name": "comment.block.safe-ds",
78-
"begin": "/\\*",
79-
"beginCaptures": {
80-
"0": {
81-
"name": "punctuation.definition.comment.safe-ds"
82-
}
83-
},
84-
"end": "\\*/",
85-
"endCaptures": {
86-
"0": {
87-
"name": "punctuation.definition.comment.safe-ds"
88-
}
89-
}
22+
"name": "storage.type.safe-ds",
23+
"match": "\\b(annotation|attr|class|enum|fun|package|pipeline|schema|segment|val)\\b"
24+
},
25+
{
26+
"name": "storage.modifier.safe-ds",
27+
"match": "\\b(const|in|internal|out|private|static)\\b"
28+
},
29+
{
30+
"name": "keyword.operator.safe-ds",
31+
"match": "\\b(and|not|or|sub|super)\\b"
32+
},
33+
{
34+
"name": "keyword.other.safe-ds",
35+
"match": "\\b(as|from|import|literal|union|where|yield)\\b"
36+
},
37+
{
38+
"name": "meta.safe-ds",
39+
"begin": "\\`",
40+
"end": "\\`"
41+
},
42+
{
43+
"name": "string.interpolated.safe-ds",
44+
"begin": "\"|}}",
45+
"end": "{{|\"",
46+
"patterns": [
47+
{
48+
"include": "#string-character-escape"
49+
}
50+
]
51+
},
52+
{
53+
"name": "string.quoted.double.safe-ds",
54+
"begin": "\"",
55+
"end": "\"",
56+
"patterns": [
57+
{
58+
"include": "#string-character-escape"
59+
}
60+
]
61+
}
62+
],
63+
"repository": {
64+
"comments": {
65+
"patterns": [
66+
{
67+
"name": "comment.line.double-slash.safe-ds",
68+
"begin": "//",
69+
"end": "(?=$)"
70+
},
71+
{
72+
"name": "comment.block.documentation.safe-ds",
73+
"begin": "/\\*\\*",
74+
"end": "\\*/",
75+
"patterns": [
76+
{
77+
"match": "(@param|@result)\\s+([_a-zA-Z][_a-zA-Z0-9]*)?",
78+
"captures": {
79+
"1": {
80+
"name": "keyword.other.safe-ds"
81+
},
82+
"2": {
83+
"name": "variable.parameter.safe-ds"
84+
}
85+
}
86+
},
87+
{
88+
"match": "(@since)\\b",
89+
"name": "keyword.other.safe-ds"
90+
},
91+
{
92+
"match": "(@typeParam)\\s+([_a-zA-Z][_a-zA-Z0-9]*)?",
93+
"captures": {
94+
"1": {
95+
"name": "keyword.other.safe-ds"
96+
},
97+
"2": {
98+
"name": "entity.name.type.parameter"
99+
}
100+
}
101+
}
102+
]
103+
},
104+
{
105+
"name": "comment.block.safe-ds",
106+
"begin": "/\\*",
107+
"end": "\\*/"
108+
}
109+
]
110+
},
111+
"string-character-escape": {
112+
"name": "constant.character.escape.safe-ds",
113+
"match": "\\\\(b|f|n|r|t|v|0|'|\"|{|\\\\|u[0-9a-fA-F]{4})"
90114
}
91-
]
92-
},
93-
"string-character-escape": {
94-
"name": "constant.character.escape.safe-ds",
95-
"match": "\\\\(b|f|n|r|t|v|0|'|\"|{|\\\\|u[0-9a-fA-F]{4})"
96115
}
97-
}
98116
}

tests/language/lsp/safe-ds-semantic-token-provider.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ describe('SafeDsSemanticTokenProvider', async () => {
100100
`,
101101
expectedTokenTypes: [SemanticTokenTypes.variable],
102102
},
103+
{
104+
testName: 'result declaration',
105+
code: 'fun f() -> (<|r|>: String)',
106+
expectedTokenTypes: [SemanticTokenTypes.parameter],
107+
},
103108
{
104109
testName: 'schema declaration',
105110
code: 'schema <|S|>() {}',

0 commit comments

Comments
 (0)