Fix syntax definition automatic assignment for syntax test files#358
Merged
FichteFoll merged 2 commits intoSublimeText:masterfrom Feb 26, 2022
Merged
Conversation
FichteFoll
reviewed
Feb 26, 2022
Comment on lines
+431
to
+432
| if view.size() == 0 and view.file_name().startswith(sublime.packages_path() + '/'): | ||
| sublime.set_timeout(lambda: self.assign_syntax(view), 100) |
Member
There was a problem hiding this comment.
Hard timeouts like this are usually a thing we should try to avoid. Could we instead loop the function to itself and check for view.is_loading() instead of view.size() == 0? Unfortunately I wasn't able to reliably reproduce the issue (read: not even once) to check whether that also works myself.
Suggested change
| if view.size() == 0 and view.file_name().startswith(sublime.packages_path() + '/'): | |
| sublime.set_timeout(lambda: self.assign_syntax(view), 100) | |
| if view.is_loading() and view.file_name().startswith(sublime.packages_path() + '/'): | |
| sublime.set_timeout(lambda: self.on_load(view), 100) |
Member
There was a problem hiding this comment.
Was able to reproduce. Unfortuantely, view.is_loading is False despite the view still being empty, so my idea doesn't work here.
I honestly wish View.is_loading would be useful anywhere, but so far all I can remember is getting disappointed by it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the bug whereby opening a
syntax_test_file fromOverrideAudit: Open Resourceetc. would open without the syntax being assigned automatically from the syntax test header line.The
on_loadevent listener is fired before the file was read from the.sublime-packagefile, meaning the view is still empty, causing it to miss the syntax test header. So, this commit changes the behavior so that, if it sees that the file being loaded resides within the package catalog, and is empty, then it will re-try after a short delay.