From 606a0d708a644a69a9588275afa3c8e2c5a47581 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 7 Oct 2024 23:34:58 +0800 Subject: [PATCH] :bento: Add cpp highlight file --- assets/highlighting/cpp.json | 358 +++++++++++++++++++++++++++++++++++ lib/screens/chat.dart | 12 +- 2 files changed, 365 insertions(+), 5 deletions(-) create mode 100644 assets/highlighting/cpp.json diff --git a/assets/highlighting/cpp.json b/assets/highlighting/cpp.json new file mode 100644 index 0000000..546e6ed --- /dev/null +++ b/assets/highlighting/cpp.json @@ -0,0 +1,358 @@ +{ + "name": "C++", + "version": "1.0.0", + "fileTypes": ["cpp", "hpp", "cc", "h"], + "scopeName": "source.cpp", + + "foldingStartMarker": "\\{\\s*$", + "foldingStopMarker": "^\\s*\\}", + + "patterns": [ + { + "name": "meta.preprocessor.script.cpp", + "match": "^\\s*#\\s*(include|define|if|ifdef|ifndef|else|endif|pragma)\\b" + }, + { + "name": "meta.declaration.cpp", + "begin": "^\\w*\\b(namespace|class|struct|enum|typedef|template)\\b", + "beginCaptures": { + "0": { + "name": "keyword.other.declaration.cpp" + } + }, + "end": "(\\{|;)", + "endCaptures": { + "0": { + "name": "punctuation.terminator.cpp" + } + }, + "patterns": [ + { + "include": "#strings" + }, + { + "include": "#comments" + }, + { + "name": "keyword.other.cpp", + "match": "\\b(public|private|protected|virtual|override|final)\\b" + } + ] + }, + { + "include": "#comments" + }, + { + "include": "#punctuation" + }, + { + "include": "#annotations" + }, + { + "include": "#keywords" + }, + { + "include": "#constants-and-special-vars" + }, + { + "include": "#operators" + }, + { + "include": "#strings" + } + ], + + "repository": { + "comments": { + "patterns": [ + { + "name": "comment.block.empty.cpp", + "match": "/\\*\\*/", + "captures": { + "0": { + "name": "punctuation.definition.comment.cpp" + } + } + }, + { + "include": "#comments-doc-oldschool" + }, + { + "include": "#comments-doc" + }, + { + "include": "#comments-inline" + } + ] + }, + "comments-doc-oldschool": { + "patterns": [ + { + "name": "comment.block.documentation.cpp", + "begin": "/\\*\\*", + "end": "\\*/", + "patterns": [ + { + "include": "#comments-doc-oldschool" + }, + { + "include": "#comments-block" + } + ] + } + ] + }, + "comments-doc": { + "patterns": [ + { + "name": "comment.block.documentation.cpp", + "begin": "///", + "while": "^\\s*///", + "patterns": [ + { + "include": "#comments-inline" + } + ] + } + ] + }, + "comments-inline": { + "patterns": [ + { + "include": "#comments-block" + }, + { + "match": "(//.*)$", + "captures": { + "1": { + "name": "comment.line.double-slash.cpp" + } + } + } + ] + }, + "comments-block": { + "patterns": [ + { + "name": "comment.block.cpp", + "begin": "/\\*", + "end": "\\*/", + "patterns": [ + { + "include": "#comments-block" + } + ] + } + ] + }, + "annotations": { + "patterns": [ + { + "name": "storage.type.annotation.cpp", + "match": "__attribute__\\(\\w+\\)" + } + ] + }, + "constants-and-special-vars": { + "patterns": [ + { + "name": "constant.language.cpp", + "match": "\\b(true|false|nullptr)\\b" + }, + { + "name": "variable.language.cpp", + "match": "\\b(this|super)\\b" + }, + { + "name": "constant.numeric.cpp", + "match": "\\b((0(x|X)[0-9a-fA-F]+)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)\\b" + }, + { + "include": "#class-identifier" + }, + { + "include": "#function-identifier" + } + ] + }, + "class-identifier": { + "patterns": [ + { + "match": "\\b(bool|int|char|double|float|long|short|signed|unsigned|void)\\b", + "name": "storage.type.primitive.cpp" + }, + { + "begin": "(\\b[A-Z]\\w*\\b)", + "end": "(?!<)", + "beginCaptures": { + "1": { + "name": "support.class.cpp" + } + }, + "patterns": [ + { + "include": "#type-args" + } + ] + } + ] + }, + "function-identifier": { + "patterns": [ + { + "match": "\\b([a-z_][a-zA-Z0-9_]*)\\s*\\(", + "captures": { + "1": { + "name": "entity.name.function.cpp" + } + } + } + ] + }, + "type-args": { + "begin": "(<)", + "end": "(>)", + "beginCaptures": { + "1": { + "name": "other.source.cpp" + } + }, + "endCaptures": { + "1": { + "name": "other.source.cpp" + } + }, + "patterns": [ + { + "include": "#class-identifier" + }, + { + "match": "," + }, + { + "name": "keyword.declaration.cpp", + "match": "extends" + }, + { + "include": "#comments" + } + ] + }, + "keywords": { + "patterns": [ + { + "name": "keyword.control.cpp", + "match": "\\b(if|else|for|while|do|switch|case|break|continue|goto|return)\\b" + }, + { + "name": "keyword.operator.cpp", + "match": "\\b(sizeof|typeid|decltype|new|delete)\\b" + }, + { + "name": "keyword.control.try.cpp", + "match": "\\b(try|catch|throw)\\b" + }, + { + "name": "keyword.control.cpp", + "match": "\\b(static|inline|virtual|override|const|volatile|explicit|friend|constexpr)\\b" + } + ] + }, + "operators": { + "patterns": [ + { + "name": "keyword.operator.comparison.cpp", + "match": "(==|!=|<=?|>=?)" + }, + { + "name": "keyword.operator.arithmetic.cpp", + "match": "(\\+|\\-|\\*|\\/|%)" + }, + { + "name": "keyword.operator.assignment.cpp", + "match": "(=|\\+=|-=|\\*=|/=|%=)" + }, + { + "name": "keyword.operator.logical.cpp", + "match": "(\\&\\&|\\|\\||!)" + }, + { + "name": "keyword.operator.bitwise.cpp", + "match": "(<<|>>|\\&|\\||\\^|~)" + } + ] + }, + "string-interp": { + "patterns": [ + { + "match": "\\$([a-zA-Z0-9_]+)", + "captures": { + "1": { + "name": "variable.parameter.cpp" + } + } + }, + { + "name": "string.interpolated.expression.cpp", + "begin": "\\$\\{", + "end": "\\}", + "patterns": [ + { + "include": "#constants-and-special-vars", + "name": "variable.parameter.cpp" + }, + { + "include": "#strings" + }, + { + "name": "variable.parameter.cpp", + "match": "[a-zA-Z0-9_]+" + } + ] + }, + { + "name": "constant.character.escape.cpp", + "match": "\\\\." + } + ] + }, + "strings": { + "patterns": [ + { + "name": "string.quoted.double.cpp", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.cpp", + "match": "\\\\." + } + ] + }, + { + "name": "string.quoted.single.cpp", + "begin": "'", + "end": "'", + "patterns": [ + { + "name": "constant.character.escape.cpp", + "match": "\\\\." + } + ] + } + ] + }, + "punctuation": { + "patterns": [ + { + "name": "punctuation.comma.cpp", + "match": "," + }, + { + "name": "punctuation.terminator.cpp", + "match": ";" + } + ] + } + } +} \ No newline at end of file diff --git a/lib/screens/chat.dart b/lib/screens/chat.dart index f7a5500..37f11ff 100644 --- a/lib/screens/chat.dart +++ b/lib/screens/chat.dart @@ -117,11 +117,13 @@ class _ChatListState extends State { final ctrl = ChatEventController(); await ctrl.initialize(); final messages = await ctrl.src.getLastInAllChannels(); - setState(() { - _lastMessages = messages - .map((k, v) => MapEntry(k, v.firstOrNull)) - .cast(); - }); + if (mounted) { + setState(() { + _lastMessages = messages + .map((k, v) => MapEntry(k, v.firstOrNull)) + .cast(); + }); + } } @override