fix PrettyJsonLintListener

This commit converts `PrettyJsonLintListener` into a `ViewEventListener`,
so it contains `self.view` member, required by mixed in `PrettyJsonBaseCommand`
class.
This commit is contained in:
deathaxe 2024-07-31 15:03:47 +02:00
parent eef27b88ab
commit 37464164b3
1 changed files with 5 additions and 4 deletions

View File

@ -6,15 +6,16 @@ from .PrettyJson import PrettyJsonBaseCommand
s = sublime.load_settings("Pretty JSON.sublime-settings") s = sublime.load_settings("Pretty JSON.sublime-settings")
class PrettyJsonLintListener(sublime_plugin.EventListener, PrettyJsonBaseCommand): class PrettyJsonLintListener(sublime_plugin.ViewEventListener, PrettyJsonBaseCommand):
def on_post_save(self, view): def on_post_save(self):
if not s.get("validate_on_save", True): if not s.get("validate_on_save", True):
return return
as_json = s.get("as_json", ["JSON"]) as_json = s.get("as_json", ["JSON"])
if any(syntax in view.settings().get("syntax") for syntax in as_json): view_syntax = self.view.settings().get("syntax")
if any(syntax in view_syntax for syntax in as_json):
self.clear_phantoms() self.clear_phantoms()
json_content = view.substr(sublime.Region(0, view.size())) json_content = self.view.substr(sublime.Region(0, self.view.size()))
try: try:
self.json_loads(json_content) self.json_loads(json_content)
except Exception as ex: except Exception as ex: