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

Merged
merged 40 commits into from
Dec 9, 2024
Merged

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.
@MohammedKHC0
Copy link
Contributor

This looks great! Why it's not merged yet??

This commit merges `surroundingPairs` into `autoClosingPairs` in Monarch language configuration to simplify symbol pair matching.

The logic for handling symbol pairs has been updated to consider both `surroundingPairs` and `autoClosingPairs` when determining matching pairs. If a pair is defined in both lists, the `notIn` property from both definitions is merged.

Additionally, the behavior of auto-closing pairs has been refined. Now, auto-closing pairs will not be completed if no text is selected, preventing unintended insertions. This change aligns the behavior with common editor practices and improves user experience.
This commit fixes an issue where auto-closing pairs defined in Monarch language configurations were not being properly matched due to an incorrect flag in the SymbolPairEx initialization. The isMonarch flag is now correctly set to true, ensuring that auto-closing pair logic functions as intended within Monarch language definitions.
@Rosemoe
Copy link
Owner

Rosemoe commented Dec 8, 2024

This looks great! Why it's not merged yet??

I'm planning to test monarch support, and I will merge this PR after that.

@Rosemoe Rosemoe merged commit ff34828 into Rosemoe:main Dec 9, 2024
1 of 2 checks passed
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.

3 participants