-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 a maximum file size for highlighting with an editor setting #4729
Conversation
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
This should be global (under editor config) since all languages will degrade in parsing performance as size increases. And |
I also think this should be a global option and we should also consider setting a default for this. While I really want helix to perform well for large files too, I think there is a ceiling where its just not realistic anymore. That default should probably be MUCH higher then 1MB tough. With #4716 and another PR I am working on locally right now I can still edit the largest file in the linux kernel (24mb) with treesitter enabled with only a small amount of lag and have no noticeable lag during navigation. A good default value might be 150mb to 200mb. A nice QOL feature would be displaying a warning to the user when such a large file is opened like "This file exceed the highlight-limit, treesitter related features like syntax highlighting were automatically disabled." (other editors like intellij do something similar I think) |
I think memory usage is a concern though. |
150~200MB is a reasonable default, that's what I was thinking of using. |
@@ -381,6 +383,7 @@ impl Document { | |||
path: &Path, | |||
encoding: Option<&'static encoding::Encoding>, | |||
config_loader: Option<Arc<syntax::Loader>>, | |||
file_size_limit: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: unsure if this should be a parameter by its own or part of config_loader
.
@@ -1098,8 +1101,12 @@ impl Editor { | |||
let id = if let Some(id) = id { | |||
id | |||
} else { | |||
let mut doc = Document::open(&path, None, Some(self.syn_loader.clone()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: it's possible to open the file and get the metadata from it and pass None
to the function, stopping language config all together. I personally think it's not a good idea to do so.
book/src/configuration.md
Outdated
@@ -57,6 +57,7 @@ on unix operating systems. | |||
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | | |||
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | | |||
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | | |||
| `syntax-max-file-size` | Specify the maximum file size in bytes to enable syntax highlighting | `150000000` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Better setting name?
This sets a default maximum size of 150mb to trigger syntax highlighting while allowing the user to specify an editor setting `syntax-max-file-size` to change the value of the maximum size it will also notify the user once a file is opened if the limit is exceeded.
hl-max-size
to specify maximum file size for highlighting
Problem
syntax highlighting can take so much resources to fire up especially with large files. Trying to open a very large file (100 mb file for example) will takes very long time for helix and will be very slow to navigate through.
This PR adds a language specific settings for the users to specify their desired maximum file size in bytes.
for example,
will stop the highlighting for any C files larger than 1mb.
Another option is making this a global settings, but I feel like making it a language specific provides more flexibility.