Skip to content

Commit 4d2cdae

Browse files
committed
feat(langserver): highlight some formatting tags in documentation like bold and italics for englisch language
1 parent c2fc9ac commit 4d2cdae

File tree

4 files changed

+86
-29
lines changed

4 files changed

+86
-29
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@
315315
],
316316
"var": [
317317
"storage.type.robotframework"
318+
],
319+
"documentation": [
320+
"markup.robotframework"
318321
]
319322
}
320323
}
@@ -1487,4 +1490,4 @@
14871490
"webpack": "^5.90.3",
14881491
"webpack-cli": "^5.1.4"
14891492
}
1490-
}
1493+
}

packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
from robot.parsing.lexer.tokens import Token
2424
from robot.parsing.model.statements import (
2525
Arguments,
26-
Documentation,
2726
Fixture,
2827
KeywordCall,
2928
LibraryImport,
30-
Metadata,
3129
ResourceImport,
3230
Statement,
3331
Template,
@@ -116,6 +114,7 @@ class RobotSemTokenTypes(Enum):
116114
CONFIG = "config"
117115
NAMED_ARGUMENT = "namedArgument"
118116
VAR = "var"
117+
DOCUMENTATION = "documentation"
119118

120119

121120
class RobotSemTokenModifiers(Enum):
@@ -345,7 +344,7 @@ def generate_sem_sub_tokens(
345344
if sem_info is not None:
346345
sem_type, sem_mod = sem_info
347346

348-
if isinstance(node, (Documentation, Metadata)):
347+
if token.type in [Token.DOCUMENTATION, Token.METADATA]:
349348
sem_mod = {SemanticTokenModifiers.DOCUMENTATION}
350349

351350
if token.type in [Token.VARIABLE, Token.ASSIGN]:
@@ -368,14 +367,6 @@ def generate_sem_sub_tokens(
368367
sem_mod,
369368
)
370369

371-
# yield SemTokenInfo.from_token(
372-
# token,
373-
# RobotSemTokenTypes.VARIABLE_EXPRESSION if is_expr else sem_type,
374-
# sem_mod,
375-
# col_offset + (3 if is_expr else 2),
376-
# last_index - (4 if is_expr else 2),
377-
# )
378-
379370
yield SemTokenInfo(
380371
token.lineno,
381372
col_offset + ((last_index - 1) if is_expr else last_index),
@@ -398,19 +389,6 @@ def generate_sem_sub_tokens(
398389
else:
399390
yield SemTokenInfo.from_token(token, sem_type, sem_mod)
400391

401-
elif token.type == Token.ARGUMENT and "\\" in token.value:
402-
if col_offset is None:
403-
col_offset = token.col_offset
404-
405-
for g in cls.ESCAPE_REGEX.finditer(token.value):
406-
if g.group("x") is not None:
407-
yield SemTokenInfo.from_token(
408-
token,
409-
sem_type if g.group("x") is None else RobotSemTokenTypes.ESCAPE,
410-
sem_mod,
411-
col_offset + g.start(),
412-
g.end() - g.start(),
413-
)
414392
elif token.type in [Token.KEYWORD, ROBOT_KEYWORD_INNER] or (
415393
token.type == Token.NAME and isinstance(node, (Fixture, Template, TestTemplate))
416394
):

syntaxes/robotframework.tmLanguage.json

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
2+
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
33
"repository": {
44
"header": {
55
"name": "keyword.other.header.robotframework",
@@ -71,12 +71,68 @@
7171
"patterns": [ { "include": "#variables" } ]
7272
},
7373
"comment": {
74-
"name": "comment.robotframework",
74+
"name": "comment.block.robotframework",
7575
"match": "(?:^ *|\\t+| {2,})(#.*)$",
7676
"captures": { "1": { "name": "comment.line.robotframework" } }
7777
},
7878
"setting": {
79-
"contentName": "variable.parameter.argument.robotframework",
79+
"patterns": [
80+
{ "include": "#documentation_setting" },
81+
{ "include": "#other_setting" }
82+
]
83+
},
84+
"escape": {
85+
"patterns": [
86+
{ "include": "#escape-sequence-unicode" },
87+
{ "include": "#escape-sequence" }
88+
]
89+
},
90+
"documentation_setting": {
91+
"contentName": "markup.robotframework",
92+
"begin": "(?i)^(documentation|dokumentation|Tài liệu hướng dẫn)(?= {2}| ?\\t| ?$)",
93+
"beginCaptures": { "1": { "name": "keyword.control.settings.robotframework" } },
94+
"end": "^(?!\\s*\\.\\.\\.)",
95+
"patterns": [
96+
{ "include": "#documentation_italic" },
97+
{ "include": "#documentation_bold" },
98+
{ "include": "#escape" },
99+
{ "include": "#comment" },
100+
{ "include": "#variables" },
101+
{ "include": "#line_continuation" }
102+
]
103+
},
104+
"documentation_bold": {
105+
"contentName": "markup.bold.documentation.robotframework",
106+
"begin": "\\*",
107+
"end": "\\*|$",
108+
"beginCaptures": { "0": { "name": "markup.robotframework" } },
109+
"endCaptures": { "0": { "name": "markup.robotframework" } },
110+
"patterns": [
111+
{ "include": "#documentation_italic" },
112+
{ "include": "#documentation_bold" },
113+
{ "include": "#escape" },
114+
{ "include": "#comment" },
115+
{ "include": "#variables" },
116+
{ "include": "#line_continuation" }
117+
]
118+
},
119+
"documentation_italic": {
120+
"contentName": "markup.italic.documentation.robotframework",
121+
"begin": "_",
122+
"end": "_|$",
123+
"beginCaptures": { "0": { "name": "markup.robotframework" } },
124+
"endCaptures": { "0": { "name": "markup.robotframework" } },
125+
"patterns": [
126+
{ "include": "#documentation_italic" },
127+
{ "include": "#documentation_bold" },
128+
{ "include": "#escape" },
129+
{ "include": "#comment" },
130+
{ "include": "#variables" },
131+
{ "include": "#line_continuation" }
132+
]
133+
},
134+
"other_setting": {
135+
"contentName": "string.unquoted.argument.robotframework",
80136
"begin": "(?i)^(\\S+( \\S+)*)(?= {2}| ?\\t| ?$)",
81137
"beginCaptures": { "1": { "name": "keyword.control.settings.robotframework" } },
82138
"end": "^(?!\\s*\\.\\.\\.)",
@@ -88,7 +144,27 @@
88144
]
89145
},
90146
"testcase_settings": {
91-
"contentName": "variable.parameter.argument.robotframework",
147+
"patterns": [
148+
{ "include": "#documentation_testcase_settings" },
149+
{ "include": "#other_testcase_settings" }
150+
]
151+
},
152+
"documentation_testcase_settings": {
153+
"contentName": "markup.robotframework",
154+
"begin": "(?i)(\\[(documentation|dokumentation|Tài liệu hướng dẫn)\\])(?= {2}| ?\\t| ?$)",
155+
"beginCaptures": { "0": { "name": "keyword.control.settings.robotframework" } },
156+
"end": "^(?!\\s*\\.\\.\\.)",
157+
"patterns": [
158+
{ "include": "#documentation_italic" },
159+
{ "include": "#documentation_bold" },
160+
{ "include": "#escape" },
161+
{ "include": "#comment" },
162+
{ "include": "#variables" },
163+
{ "include": "#line_continuation" }
164+
]
165+
},
166+
"other_testcase_settings": {
167+
"contentName": "string.unquoted.argument.robotframework",
92168
"begin": "(\\[.*?\\])(?= {2}| ?\\t| ?$)",
93169
"beginCaptures": { "0": { "name": "keyword.control.settings.robotframework" } },
94170
"end": "^(?!\\s*\\.\\.\\.)",

syntaxes/robotframework.tmLanguage.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)