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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion plugins/syntaxtest_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ class AssignSyntaxTestSyntaxListener(sublime_plugin.EventListener):
PLAIN_TEXT = "Packages/Text/Plain text.tmLanguage"

def on_load(self, view):
if view.size() == 0 and view.file_name().startswith(sublime.packages_path() + '/'):
sublime.set_timeout(lambda: self.assign_syntax(view), 100)
Comment on lines +431 to +432
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.

return

self.assign_syntax(view)
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved

def assign_syntax(self, view):
test_header = get_syntax_test_tokens(view)
if not test_header:
return
Expand All @@ -447,7 +454,7 @@ def on_load(self, view):
view.assign_syntax(self.PLAIN_TEXT)

# just base name specified
elif not current_syntax.endswith(test_syntax):
elif not current_syntax.endswith('/' + test_syntax):
syntax_candidates = sublime.find_resources(test_syntax)
if syntax_candidates:
logger.debug("Found the following candidates for %r: %r",
Expand Down