Skip to content

Commit

Permalink
Expand path pattern based pipeline syntax detection to include *.gitl…
Browse files Browse the repository at this point in the history
…ab-ci.yml and Gitlab composite actions.
  • Loading branch information
Jason Heeris authored and keith-hall committed Aug 16, 2023
1 parent b404705 commit fad273c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions set_syntax_on_load_or_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
import sublime_plugin
from pathlib import Path

# Some CI pipeline scopes can be deduced from their path when given more context
# than just an extension. This maps a given path pattern to a scope to apply.
# The first one that matches will be applied (note that dicts are
# insertion-ordered as of Python 3.7), but in general they should not overlap.
SCOPE_PATH_PATTERNS = {
'**/.github/workflows/**': 'scope:source.yaml.pipeline.github-actions',
'**/.github/actions/**/*': 'scope:source.yaml.pipeline.github-actions',
'*.gitlab-ci.yml': 'scope:source.yaml.pipeline.gitlab',
}


class YamlFileOpenedEventListener(sublime_plugin.ViewEventListener):
@classmethod
Expand All @@ -16,5 +26,7 @@ def on_save_async(self):

def set_syntax_if_filepath_applicable(self):
if filename := self.view.file_name():
if Path(filename).match('**/.github/workflows/**'):
self.view.assign_syntax('scope:source.yaml.pipeline.github-actions')
for pattern, scope in SCOPE_PATH_PATTERNS.items():
if Path(filename).match(pattern):
self.view.assign_syntax(scope)
break

0 comments on commit fad273c

Please sign in to comment.