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

Improve syntax parsing #1315

Merged
merged 6 commits into from
Jun 20, 2020
Merged

Improve syntax parsing #1315

merged 6 commits into from
Jun 20, 2020

Conversation

kaste
Copy link
Collaborator

@kaste kaste commented Jun 20, 2020

Fixes #1028
Fixes #666

  • Avoid yaml parse errors by extracting the wanted key "file_extensions" via an ordinary regex. This is actually faster as well. By a lot.

  • Additionally, parse "tmLanguage" syntaxes because why not.

  • For a better "guess" for which syntax to use look at actual views currently open. Remember these used syntaxes.

Side fix:

  • Normalize line endings in the help files
  • Normalize abs paths coming from the status view

Fixes #1028

For a lot of files `yaml.safe_load` fails if the lib does not support
the used yaml format.  It is also very slow to parse all syntax files.

Since we only use relatively simple information here, t.i. a single
key, we just run a regex and extract the useful information.
Fixes #666

Note: for the least surprise we first parse the "tmLanguage" files,
followed by "sublime-syntax" so that the latter overrule the former.

Note: we don't have any way to tell which is the currently preferred
syntax.  We just use the last syntax we iterated over.
Since we cannot actually know the correct syntax just by looking at
our map, we just choose the arbitrary `[-1]` last item, we try harder
to just take the syntax using an open view.

If we ever found such a syntax we also remember this choice.
In the status view we show short relative paths to a file. These come
from git and thus have always "/" as the path separator.

Since we construt absolute paths here, we should also `normpath`.
The help docs are saved with mac line endings. We convert to plain
"\n" newline characters because that's internally the format Sublime
uses and wants.
@kaste kaste merged commit dc6f1e1 into master Jun 20, 2020
@kaste kaste deleted the improve-syntax-parsing branch June 20, 2020 20:58
@randy3k
Copy link
Collaborator

randy3k commented Jun 21, 2020

Got this when Sublime Text starts.

Exception in thread Thread-3:
Traceback (most recent call last):
  File "./python3.3/threading.py", line 901, in _bootstrap_inner
  File "./python3.3/threading.py", line 858, in run
  File "/Users/Randy/Dropbox/Sublime Text/Packages/GitSavvy/common/util/file.py", line 51, in _determine_syntax_files
    handle_tm_language_files()
  File "/Users/Randy/Dropbox/Sublime Text/Packages/GitSavvy/common/util/file.py", line 65, in handle_tm_language_files
    for extension in plistlib.readPlistFromBytes(resource).get("fileTypes", []):
  File "./python3.3/plistlib.py", line 104, in readPlistFromBytes
  File "./python3.3/plistlib.py", line 76, in readPlist
  File "./python3.3/plistlib.py", line 378, in parse
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 12, column 0

ST4 4074 on macOS by the way.

@randy3k
Copy link
Collaborator

randy3k commented Jun 21, 2020

It turns out that it was caused by this syntax file. Maybe it was caused by the comments?

@kaste
Copy link
Collaborator Author

kaste commented Jun 21, 2020

Pretty stupid optimistic to not catch errors here. 🙄 Thanks for reporting quickly. Let's see how 2.24.2 goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error loading Syntax File when running GitSavvy: Help Determine syntax when .tmLanguage files are in use
2 participants