Skip to content

Fix syntax definition automatic assignment for syntax test files#358

Merged
FichteFoll merged 2 commits intoSublimeText:masterfrom
forkeith:fix_syntax_not_being_set_for_test_files
Feb 26, 2022
Merged

Fix syntax definition automatic assignment for syntax test files#358
FichteFoll merged 2 commits intoSublimeText:masterfrom
forkeith:fix_syntax_not_being_set_for_test_files

Conversation

@keith-hall
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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