Skip to content

Commit e3fd41c

Browse files
authored
Fix syntax highlighting grammar (#680)
* (fix) syntag highlighting Fix special svelte attributes highlighting by listing them out instead of using a generic \w+ regex. No longer treats "superon:click" as a special svelte attribute and highlights accordingly. * Fix highlighting for empty style/script/template tag by adding a "not immediately followed by </" condition to the begin regex.
1 parent 9f287a3 commit e3fd41c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,79 @@ injections:
1010

1111
# Format:
1212
# 'L:meta.<script|style|template>.svelte (meta.lang.<lang> | meta.lang.<langalternative> | ...) - (meta source)'
13-
# patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
13+
# patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
1414
# contentName: source.<lang>, patterns: [{ include: source.<lang> }]}]
1515

1616
# Script Languages
1717
# JavaScript | 'javascript' | 'source.js'
1818
'L:meta.script.svelte meta.lang.javascript - (meta source)':
19-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
19+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
2020
contentName: source.js, patterns: [{ include: source.js }]}]
2121

2222
# TypeScript | 'ts' 'typescript' | 'source.ts'
2323
'L:meta.script.svelte (meta.lang.ts | meta.lang.typescript) - (meta source)':
24-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
24+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
2525
contentName: source.ts, patterns: [{ include: source.ts }]}]
2626

2727
# CoffeeScript | 'coffee' | 'source.coffee'
2828
'L:meta.script.svelte meta.lang.coffee - (meta source)':
29-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
29+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
3030
contentName: source.coffee, patterns: [{ include: source.coffee }]}]
3131

3232
# Default (JavaScript)
3333
'L:meta.script.svelte - meta.lang - (meta source)':
34-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
34+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
3535
contentName: source.js, patterns: [{ include: source.js }]}]
3636

3737
# ----
3838

3939
# Style Languages
4040
# Stylus | 'stylus' | 'source.stylus'
4141
'L:meta.style.svelte meta.lang.stylus - (meta source)':
42-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
42+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
4343
contentName: source.stylus, patterns: [{ include: source.stylus }]}]
4444

4545
# Sass | 'sass' | 'source.sass'
4646
'L:meta.style.svelte meta.lang.sass - (meta source)':
47-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
47+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
4848
contentName: source.sass, patterns: [{ include: source.sass }]}]
4949

5050
# CSS | 'css' | 'source.css'
5151
'L:meta.style.svelte meta.lang.css - (meta source)':
52-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
52+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
5353
contentName: source.css, patterns: [{ include: source.css }]}]
5454

5555
# SCSS | 'scss' | 'source.css.scss'
5656
'L:meta.style.svelte meta.lang.scss - (meta source)':
57-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
57+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
5858
contentName: source.css.scss, patterns: [{ include: source.css.scss }]}]
5959

6060
# Less | 'less' | 'source.css.less'
6161
'L:meta.style.svelte meta.lang.less - (meta source)':
62-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
62+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
6363
contentName: source.css.less, patterns: [{ include: source.css.less }]}]
6464

6565
# PostCSS | 'postcss' | 'source.css.postcss'
6666
'L:meta.style.svelte meta.lang.postcss - (meta source)':
67-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
67+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
6868
contentName: source.css.postcss, patterns: [{ include: source.css.postcss }]}]
6969

7070
# Default (CSS)
7171
'L:meta.style.svelte - meta.lang - (meta source)':
72-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
72+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
7373
contentName: source.css, patterns: [{ include: source.css }]}]
7474

7575
# ----
7676

7777
# Template Languages
7878
# Pug | 'pug' | 'text.pug'
7979
'L:meta.template.svelte meta.lang.pug - (meta source)':
80-
patterns: [{begin: '(?<=>)', end: '(?=</)', name: meta.embedded.block.svelte,
80+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte,
8181
contentName: text.pug, patterns: [{ include: text.pug }]}]
8282

8383
# Default (just introduces a new scope)
8484
'L:meta.template.svelte - meta.lang - (meta source)':
85-
patterns: [{begin: '(?<=>)', end: '(?=</)', patterns: [{ include: '#scope' }]}]
85+
patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', patterns: [{ include: '#scope' }]}]
8686

8787
# ---- LANGUAGE EXTENSIONS
8888

@@ -364,7 +364,8 @@ repository:
364364
# For Svelte element directives. Scopes the 'on' part in `on:click`.
365365
attributes-directives-keywords:
366366
patterns:
367-
# If other keywords are patched in in the future, they can easily be added here.
367+
# If other keywords are patched in in the future, they can be added here but also need to be added
368+
# where attributes-directives-keywords is included.
368369
- { match: on|use|bind, name: keyword.control.svelte }
369370
- { match: transition|in|out|animate, name: keyword.other.animation.svelte }
370371
- { match: let, name: storage.type.svelte }
@@ -385,7 +386,8 @@ repository:
385386

386387
# Matches Svelte element directives, e.g. `on:click|preventDefault={var}`
387388
attributes-directives:
388-
begin: (?<!<)(\w+)(:)([_$[:alpha:]][_\-$[:alnum:]]*)((?:\|.*)?\|\w*)?
389+
# If something is added to attributes-directives-keywords, it must be added to the begin-regex, too.
390+
begin: (?<!<)(on|use|bind|transition|in|out|animate|let|class)(:)([_$[:alpha:]][_\-$[:alnum:]]*)((?:\|.*)?\|\w*)?
389391
beginCaptures:
390392
1: { patterns: [ include: '#attributes-directives-keywords' ] }
391393
2: { name: punctuation.definition.keyword.svelte }

0 commit comments

Comments
 (0)