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

Fix syntax definition automatic assignment for syntax test files #358

Merged

Conversation

keith-hall
Copy link
Member

This fixes the bug whereby opening a syntax_test_ file from OverrideAudit: Open Resource etc. would open without the syntax being assigned automatically from the syntax test header line.

The on_load event listener is fired before the file was read from the .sublime-package file, 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.

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)
Copy link
Member

@FichteFoll FichteFoll Feb 26, 2022

Choose a reason for hiding this comment

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

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)

Copy link
Member

Choose a reason for hiding this comment

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

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.

@FichteFoll FichteFoll added this to the 3.3.2 milestone Feb 26, 2022
@FichteFoll FichteFoll merged commit 8335998 into SublimeText:master Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants