Skip to content

Commit

Permalink
Syntax highlighting for string method names
Browse files Browse the repository at this point in the history
Attempt to fix microsoft#154
  • Loading branch information
chadhietala committed Jun 27, 2016
1 parent dcfc96b commit c4930a9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.insertSpaces": true
}
}
4 changes: 2 additions & 2 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ repository:

method-declaration:
name: meta.method.declaration.ts
begin: '\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
begin: '\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:(\[*)(`|'|"*)(.*)(`|'|"*)(\]*)\s*(\??)))?\s*(?=\(|\<)'
beginCaptures:
'1': { name: storage.modifier.ts } # captures keyword (abstract)
'2': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'3': { name: storage.modifier.ts } # captures keyword (async)
'4': { name: storage.type.property.ts } # captures keyword (get|set)
'5': { name: keyword.operator.ts } # captures keyword (new)
'6': { name: storage.type.ts } # captures keyword (constructor)
'7': { name: entity.name.function.ts } # captures method name ([a-zA-Z_$][\.\w$]*)
'7': { name: entity.name.function.ts } # captures method name (\[*)(`|'|"*)([a-zA-Z_$][\.\w$]*)(`|'|"*)(\]*)
'8': { name: keyword.operator.ts } # captures (\??)
end: '(?=\}|;|,)|(?<=\})'
patterns:
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/Issue154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[2, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
[8, 1]: source.ts meta.declaration.object.ts meta.object.body.ts string.single.ts
[14, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
[20, 1]: source.ts meta.declaration.object.ts meta.object.body.ts string.double.ts
[26, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
[32, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts entity.name.function.ts
35 changes: 35 additions & 0 deletions tests/cases/Issue154.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class TestCase0 {
^^['123']() {
this.registerComponent('foo-bar');
}
}

class TestCase1 {
^^'$'() {
this.registerComponent('foo-bar');
}
}

class TestCase2 {
^^[`foo`]() {
this.registerComponent('foo-bar');
}
}

class TestCase3 {
^^"foo"() {
this.registerComponent('foo-bar');
}
}

class TestCase4 {
^^["foo"]() {
this.registerComponent('foo-bar');
}
}

class TestCase5 {
^^foo() {
this.registerComponent('foo-bar');
}
}
4 changes: 2 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ function addTestCase(file: string, generatedText: string, baselinesText: string)
it('should be the same', () => {
chai.expect(compareText(generatedText, baselinesText)).to.true;
})
})
}
})
}

0 comments on commit c4930a9

Please sign in to comment.