Skip to content

Commit 62364f1

Browse files
committed
added hl-max-size to specify maximum file size for highlighting
This should help users to specify the max size for the documents since highlighting takes too much resources when file size increases. This setting is language specific. Thus, can be configured in languages.toml
1 parent 7367abd commit 62364f1

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

book/src/languages.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ These configuration keys are available:
6262
| `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) |
6363
| `formatter` | The formatter for the language, it will take precedence over the lsp when defined. The formatter must be able to take the original file as input from stdin and write the formatted file to stdout |
6464
| `max-line-length` | Maximum line length. Used for the `:reflow` command |
65+
| `hl-max-size` | Maximum file size in bytes for syntax highlighting |
6566

6667
### File-type detection and the `file-types` key
6768

helix-core/src/syntax.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ pub struct LanguageConfiguration {
122122
#[serde(default, skip_serializing, deserialize_with = "deserialize_auto_pairs")]
123123
pub auto_pairs: Option<AutoPairs>,
124124

125-
pub rulers: Option<Vec<u16>>, // if set, override editor's rulers
125+
pub rulers: Option<Vec<u16>>, // if set, override editor's rulers
126+
pub hl_max_size: Option<usize>, // maximum file size in bytes for highlighting
126127
}
127128

128129
#[derive(Debug, PartialEq, Eq, Hash)]

helix-view/src/document.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,13 @@ impl Document {
681681
loader: Option<Arc<helix_core::syntax::Loader>>,
682682
) {
683683
if let (Some(language_config), Some(loader)) = (language_config, loader) {
684+
if let Some(max_size) = language_config.hl_max_size {
685+
if self.text.len_bytes() > max_size {
686+
self.syntax = None;
687+
self.language = Some(language_config);
688+
return;
689+
}
690+
}
684691
if let Some(highlight_config) = language_config.highlight_config(&loader.scopes()) {
685692
let syntax = Syntax::new(&self.text, highlight_config, loader);
686693
self.syntax = Some(syntax);

0 commit comments

Comments
 (0)