Skip to content

CodeMirror Blob: fix syntax highlighting error

Warren Gifford requested to merge olafurpg/cm-hl into main

Created by: olafurpg

Previously, syntax highlighting occasionally failed because the occurrences were not correctly ordered when we computed CodeMirror "decorations", causing RangeSetBuilder.finish() to crash with an uncaught exception. This commit addresses the issue with several fixes:

  • Sort occurrences on the client-side so that it's OK if the server returns unordered occurrences
  • Use the higher-level Occurrences class to minimize the risk of making mistakes when working with the low-level range: number[] encoding.
  • Catch exceptions and log a helpful error message if an error gets thrown again while computing decorations, making it easier to troubleshoot similar issues in the future.

Fixes #40352 (closed) Fixes #40355 (closed)

Test plan

Run sg start and browse Java and TypeScript files. All files should render correct highlighting, including backend.ts and client/jetbrains/src/main/java/com/sourcegraph/config/ThemeUtil.java (which don't render correctly currently on sourcegraph.com)

CleanShot 2022-08-17 at 17 54 55 CleanShot 2022-08-17 at 17 56 06

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading