Skip to content

Commit

Permalink
highlighter_compat: Prevent raising of error dialogue during init
Browse files Browse the repository at this point in the history
Affected any systems where the fish executable couldn't be found. Closes #27
  • Loading branch information
Phidica committed Aug 12, 2024
1 parent 73fd9bb commit 1ca9a4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

3.4.1 (ST3 and ST4)
-------------------

Bugfix:
- Systems without fish installed would always raise an error dialogue box when first opening a fish file, due to the compatibility highlighter initialisation failing to establish the system fish version.

3.4.0 (ST3 and ST4)
-------------------

Expand Down
7 changes: 5 additions & 2 deletions Tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def commandOnAbsolutePath(command, settings):
else:
return command

def getFishOutput(args, settings, pipeInput = None):
def getFishOutput(args, settings, pipeInput = None, quiet = False):
# Put command name on an absolute path if needed
command = args[0]
args[0] = commandOnAbsolutePath(command, settings)
Expand All @@ -50,7 +50,10 @@ def getFishOutput(args, settings, pipeInput = None):
if args[0] == command:
msg += " Specify a nonstandard install location in Preferences > " \
"Package Settings > Fish > Settings."
sublime.error_message(msg)
if quiet:
print(msg)
else:
sublime.error_message(msg)
except OSError as ex:
# Right now I only know of this happening when fish is in WSL.
# That's not meant to be supported, so keep the error quiet
Expand Down
17 changes: 9 additions & 8 deletions highlighter_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def __init__(self, view):

# Only first instance will set this
if CompatHighlighter.sysFishVer is None:
out,err = getFishOutput(['fish', '--version'], self.view.settings())
# Request no error to be raised if fish isn't found, since this is still plugin initialisation
out,err = getFishOutput(['fish', '--version'], self.view.settings(), quiet = True)
match = None
if out:
# For builds from source, version string may be e.g. "fish, version 3.0.2-1588-g70fc2611"
Expand Down Expand Up @@ -223,11 +224,7 @@ def on_text_command(self, command_name, args):
self._run_test()

def _should_markup(self):
if self._fish_version() is None:
self.logger.info("Refusing to mark up because targeted fish version unknown")
return False
else:
return True
return self._fish_version() is not None

def _test_draw_region(self, region, selector, regionID):
self.logger.debug("Region {} text = {}".format(region, self.view.substr(region)))
Expand Down Expand Up @@ -373,7 +370,11 @@ def _cache_settings_fish_version(self):
elif versionStr == 'auto':
if CompatHighlighter.sysFishVer == 'not found':
self.settingsFishVer = None
self.logger.error("fish not found! Version couldn't be determined automatically")
self.logger.error("fish not found! Version couldn't be determined " \
"automatically. Set 'compat_highlighter_fish_version' in the " \
"settings file or write a 'fishX.Y' version number on the first " \
"line of this file."
)
elif CompatHighlighter.sysFishVer == 'error':
self.settingsFishVer = None
# Currently, I can't imagine this happening. Prove me wrong!
Expand All @@ -382,7 +383,7 @@ def _cache_settings_fish_version(self):
"Please report a bug using Preferences > Package Settings > Fish " \
"> Report a bug. Include your system information, and the output " \
"of 'fish --version' in your terminal. To work around this error, " \
"set your fish version manually in the settings file."
"set 'compat_highlighter_fish_version' in the settings file."
)
else:
self.settingsFishVer = CompatHighlighter.sysFishVer
Expand Down

0 comments on commit 1ca9a4c

Please sign in to comment.