Ubisam-MobileGit/tasks/049-cpp-highlighting-and-multiline-comments.md
choiminyeong 10b38a3ac4 TASK-049: C/C++ highlighting and multi-line comment coloring
Adds a CPP language, preprocessor coloring, hex and digit-separator numbers, and block-comment state carried across lines. CodeBlock now highlights a file once instead of on every recomposition.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 13:17:33 +09:00

3.8 KiB

TASK-049: C/C++ syntax highlighting and multi-line comment coloring

Status: implemented; see Evidence for check results; device confirmation pending Owner: Claude Reviewer: human product owner

Outcome

The human product owner's team mainly reads C# and C++ in this app. C/C++ files currently fall back to plain, uncolored text, and a block comment that spans several lines is only colored on its first and last line (TASK-048's recorded known limitation). After this task C/C++ sources are highlighted, and a multi-line comment keeps its comment color on every line it covers, in every language that has block comments.

Scope

  • Included: a CPP language (.c .h .cc .cpp .cxx .hpp .hh .hxx .inl .ipp) with its keyword set; preprocessor directives (#include, #pragma, #define, C#'s #region ...) in their own color, with an #include <...> target colored as a string; cross-line block-comment state (/* */ and <!-- -->) carried from one line to the next; numbers with digit separators (30_000, 1'000'000) and hex literals; unit tests for all of the above.
  • Excluded: a real parser. Multi-line strings (C++ raw strings, C# verbatim/raw strings, Python triple quotes) still only color on the line where they start. Type/method coloring, the Visual Studio palette, the header/source pairing view and the standalone full-screen viewer belong to the redesign tasks that follow.

Writable paths

  • app/src/main/java/com/ubisam/ubgitea/feature/codebrowser/content/SyntaxHighlighter.kt
  • app/src/main/java/com/ubisam/ubgitea/feature/codebrowser/CodeBrowserScreen.kt (CodeBlock only)
  • app/src/test/java/com/ubisam/ubgitea/feature/codebrowser/content/SyntaxHighlighterTest.kt
  • tasks/049-cpp-highlighting-and-multiline-comments.md, docs/development-log.md

Acceptance criteria

  • .c .h .cc .cpp .cxx .hpp .hh .hxx .inl .ipp files resolve to the C/C++ language.
  • C/C++ keywords, strings, numbers, line comments and block comments are colored.
  • #include <chrono> colors the directive as preprocessor and <chrono> as a string.
  • Every line inside a multi-line /* ... */ or <!-- ... --> comment is colored as a comment, and code after the closing delimiter on the same line is highlighted normally.
  • A /* inside a string literal or after // does not open a comment.
  • Highlighting is computed once per file, not on every recomposition.
  • Unit tests cover the criteria above.
  • Confirmed on the human product owner's device against real C++ sources.

Security and privacy

No additional concerns. No network, storage or logging is touched.

Required checks

./gradlew compileDebugKotlin compileDebugUnitTestKotlin testDebugUnitTest assembleDebug lintDebug

Evidence

Recorded on 2026-09-28 in the worktree awesome-pascal-3f2ada, on top of 39be1b7 plus the still-uncommitted TASK-045..048 changes copied from the main checkout, using Android Studio's bundled JDK (D:\AndroidStudio\jbr, OpenJDK 21):

  • ./gradlew compileDebugKotlin compileDebugUnitTestKotlin testDebugUnitTest -- passed; 289 tests, 0 failures, 0 errors, 0 skipped. New SyntaxHighlighterTest: 21 tests, all passing.
  • ./gradlew assembleDebug lintDebug -- passed; lint 0 errors, 40 warnings.
  • SyntaxHighlighter.kt: new CPP language and extension mapping; tokenizeLines (Compose-free, carries open block-comment state across lines); highlightLines; preprocessor role and color; number pattern extended to hex and digit separators. highlightLine kept as a single-line wrapper.
  • CodeBrowserScreen.kt: CodeBlock highlights the whole file once inside remember and renders the cached lines in both the wrap and no-wrap branches.
  • Not done: installing on a device. No device was connected to this session.

Review findings

None yet.