From 71f3172f91805243fa6d93c24dbc7a9cf65b2e00 Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Mon, 6 Jun 2016 09:58:20 -0700 Subject: [PATCH] Syntax highlighting for string method names Attempt to fix #154 --- .vscode/settings.json | 2 +- TypeScript.YAML-tmLanguage | 4 ++-- tests/baselines/Issue154.txt | 6 ++++++ tests/cases/Issue154.ts | 35 +++++++++++++++++++++++++++++++++++ tests/test.ts | 4 ++-- 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/Issue154.txt create mode 100644 tests/cases/Issue154.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 765a941b..aae5bd0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ // Place your settings in this file to overwrite default and user settings. { "editor.insertSpaces": true -} \ No newline at end of file +} diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 2ac792ec..5d8fe54d 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -154,7 +154,7 @@ 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) @@ -162,7 +162,7 @@ repository: '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 (\[*)(`|'|"*)(.*)(`|'|"*)(\]*) '8': { name: keyword.operator.ts } # captures (\??) end: '(?=\}|;|,)|(?<=\})' patterns: diff --git a/tests/baselines/Issue154.txt b/tests/baselines/Issue154.txt new file mode 100644 index 00000000..b9f934d2 --- /dev/null +++ b/tests/baselines/Issue154.txt @@ -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 diff --git a/tests/cases/Issue154.ts b/tests/cases/Issue154.ts new file mode 100644 index 00000000..474827b5 --- /dev/null +++ b/tests/cases/Issue154.ts @@ -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'); + } +} diff --git a/tests/test.ts b/tests/test.ts index 3ccf0393..11daaf07 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -24,5 +24,5 @@ function addTestCase(file: string, generatedText: string, baselinesText: string) it('should be the same', () => { chai.expect(compareText(generatedText, baselinesText)).to.true; }) - }) -} \ No newline at end of file + }) +}