From c78836e29f689214453eb13e8db7e0479e438bcd Mon Sep 17 00:00:00 2001 From: K9i Date: Fri, 17 Apr 2026 11:11:48 +0900 Subject: [PATCH] fix: add missing doc comment grammars --- grammars/swift.json | 12 ++++++++ grammars/typescript.json | 12 ++++++++ test/syntax_highlight_test.dart | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/grammars/swift.json b/grammars/swift.json index 196cb16..239f32e 100644 --- a/grammars/swift.json +++ b/grammars/swift.json @@ -67,6 +67,18 @@ } ] }, + "swiftdoc": { + "patterns": [ + { + "name": "entity.name.tag.documentation.swift", + "match": "(-\\s+[A-Za-z]+:)|@[a-zA-Z]+" + }, + { + "name": "markup.inline.raw.swift", + "match": "`[^`]+`" + } + ] + }, "keywords": { "patterns": [ { diff --git a/grammars/typescript.json b/grammars/typescript.json index 7cda738..782dc1c 100644 --- a/grammars/typescript.json +++ b/grammars/typescript.json @@ -70,6 +70,18 @@ } ] }, + "tsdoc": { + "patterns": [ + { + "name": "entity.name.tag.documentation.typescript", + "match": "@[a-zA-Z]+" + }, + { + "name": "markup.inline.raw.typescript", + "match": "`[^`]+`" + } + ] + }, "keywords": { "patterns": [ { diff --git a/test/syntax_highlight_test.dart b/test/syntax_highlight_test.dart index 8b13789..60e866b 100644 --- a/test/syntax_highlight_test.dart +++ b/test/syntax_highlight_test.dart @@ -1 +1,51 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:syntax_highlight/syntax_highlight.dart'; +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + late HighlighterTheme theme; + + setUpAll(() async { + await Highlighter.initialize(['typescript', 'swift']); + theme = await HighlighterTheme.loadLightTheme(); + }); + + group('documentation comments', () { + test('highlights TypeScript doc comments without throwing', () { + const source = ''' +/** + * @remarks Example + */ +export function answer(): number { + return 42; +} +'''; + + final span = Highlighter( + language: 'typescript', + theme: theme, + ).highlight(source); + + expect(span.toPlainText(), source); + }); + + test('highlights Swift doc comments without throwing', () { + const source = ''' +/** + * - Returns: Example + */ +func answer() -> Int { + 42 +} +'''; + + final span = Highlighter( + language: 'swift', + theme: theme, + ).highlight(source); + + expect(span.toPlainText(), source); + }); + }); +}