Skip to content

input: Skip highlighting for plain text and unregistered languages#2567

Merged
huacnlee merged 3 commits into
longbridge:mainfrom
zanmato:plain-highlighter
Jul 15, 2026
Merged

input: Skip highlighting for plain text and unregistered languages#2567
huacnlee merged 3 commits into
longbridge:mainfrom
zanmato:plain-highlighter

Conversation

@zanmato

@zanmato zanmato commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Closes #2566

Description

Plain text and other unregistered languages, like a code fence in markdown, falls back to JSON currently. Which is a lot of unnecessary parsing, and also causes quite a big memory overhead.

Screenshot

Before After
Before After

How to Test

  • Generate a big text file
(for i in $(seq 1 999999); do echo 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; done) > big_lorem.txt
  • Disable linter and color provider in the editor
--- a/crates/story/examples/editor.rs
+++ b/crates/story/examples/editor.rs
@@ -713,7 +713,7 @@ impl Example {
             editor.lsp.code_action_providers = vec![lsp_store.clone(), Rc::new(TextConvertor)];
             editor.lsp.hover_provider = Some(lsp_store.clone());
             editor.lsp.definition_provider = Some(lsp_store.clone());
-            editor.lsp.document_color_provider = Some(lsp_store.clone());
+            // editor.lsp.document_color_provider = Some(lsp_store.clone());
 
             editor
         });
@@ -731,7 +731,7 @@ impl Example {
         Self::load_files(tree_state.clone(), PathBuf::from("./"), cx);
 
         let _subscriptions = vec![cx.subscribe(&editor, |this, _editor, _: &InputEvent, cx| {
-            this.lint_document(cx);
+            // this.lint_document(cx);
         })];
 
         Self {
  • Run the editor example, open the big text file and compare memory usage

I've also checked various other files in the editor example

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

Comment thread crates/ui/src/highlighter/languages.rs Outdated

let (language, query, injection, locals) = match self {
Self::Plain => (tree_sitter_json::LANGUAGE, "", "", ""),
Self::Plain => unreachable!(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can use debug_assert!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced it with debug_assert

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the added matches! instead and just return the new plain config in the original match

@huacnlee
huacnlee merged commit 3de68cd into longbridge:main Jul 15, 2026
3 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.

Editor memory usage skyrockets with large files, UI lags a lot

2 participants