Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add monarch support for sora-editor #580

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

dingyi222666
Copy link
Contributor

@dingyi222666 dingyi222666 commented Apr 12, 2024

This PR introduces the monarch to sora-editor.

Introduction

Monarch is a lightweight, declarative lexical specification-based syntax highlighter designed by the VSCode development team. The main purpose of introducing this library is to leverage Monarch's concise syntax definition and loading speed. Compared to the TextMate module, it offers a 10% - 40% speed advantage when rendering large text code, making it suitable for scenarios that don't require complex highlighting effects but desire dynamically loaded syntax highlighting with a certain level of speed.

Usage

Refer to MainActivity.kt for usage, similar to lang-textmate.

Screenshots and Comparison

Monarch effect and rendering time for View.java

c5dfb5407162bb066d3073679fb44f7f

output1.mp4

TextMate effect and rendering time for View.java

c09072a7b605adbdb02c135ed3c829c7

output.mp4

Other

This PR also implements VSCode theme loading and grammar repository abstraction, which may be useful in the future when rewriting the lang-textmate module to Kotlin implementation.

This commit adds support for the Monarch language system, including the
implementation of MonarchGrammarDefinitionDSL for grammar definition,
and updates to the language-monarch module to handle language loading
and configuration. Theme support for Monarch is also introduced,
allowing for dark and light mode theming consistency with TextMate.
Themes now load colors asynchronously, which prevents blocking the main thread when parsing
and applying theme settings. This optimization enhances the overall performance andresponsiveness of the application when switching or initializing themes.

The TokenTheme adapter was updated to handle the asynchronous loading of theme colors.
MonarchColorScheme was modified to apply themes more efficiently, especially when dealing
with legacy TextMate themes. Additionally, the theme registration and management logic was
refactored to ensure themes are loaded only when necessary.
…kens

Adjust the theme loading function to collect colors into a map when provided with a nullthemeColorsMap. This change simplifies theme loading logic and avoids unnecessary skipping of
values. Additionally, modify the token color reading function to add a default empty token,
ensuring that at least one token is always present. This prevents potential runtime issues due
to empty token lists.
consistency and adhere to coding standards.
…x implementation

Update the regex libraries to the latest versions and modify the implementation in the
MonarchLanguage class to support the additional regex features. Additionally, refactor the
JSON parsing logic in the AutoClosingPairConditional loading process for better clarity.
@dingyi222666 dingyi222666 marked this pull request as ready for review September 25, 2024 02:53
- Remove unnecessary logging statements in AsyncIncrementalAnalyzeManager to clean up the code.
- Adjust if-statement formatting for consistency and better readability.
- Eliminate unused code segments in JsonParseTests and adjust import statements.
- Ensure consistent code formatting across the specified files for enhanced maintainability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant