|
1 | 1 | import logging
|
2 | 2 | import re
|
3 | 3 | from collections import namedtuple
|
| 4 | +from fnmatch import fnmatch |
| 5 | +from sublime_lib.resource_path import ResourcePath |
4 | 6 |
|
5 | 7 | import sublime
|
6 | 8 | import sublime_plugin
|
@@ -266,6 +268,12 @@ def match_selector(selector, offset=0):
|
266 | 268 | ):
|
267 | 269 | result = self._complete_branch_point()
|
268 | 270 |
|
| 271 | + elif match_selector( |
| 272 | + "meta.extends", |
| 273 | + -1, |
| 274 | + ): |
| 275 | + result = self._complete_syntax_file() |
| 276 | + |
269 | 277 | # Auto-completion for variables in match patterns using 'variables' keys
|
270 | 278 | elif match_selector("keyword.other.variable"):
|
271 | 279 | result = self._complete_variable()
|
@@ -299,6 +307,45 @@ def _complete_context(self, prefix, locations):
|
299 | 307 | kind=TPL_CONTEXT.kind,
|
300 | 308 | )
|
301 | 309 |
|
| 310 | + def _complete_syntax_file(self): |
| 311 | + completions = [] |
| 312 | + kind = (sublime.KIND_ID_VARIABLE, 's', 'Syntax') |
| 313 | + |
| 314 | + settings = sublime.load_settings("PackageDev.sublime-settings") |
| 315 | + excludes = settings.get("settings.exclude_syntax_patterns", []) |
| 316 | + if not isinstance(excludes, list): |
| 317 | + excludes = [] |
| 318 | + |
| 319 | + try: |
| 320 | + my_folder = str(ResourcePath.from_file_path(self.view.file_name()).parent) |
| 321 | + except (TypeError, ValueError): |
| 322 | + my_folder = "" |
| 323 | + |
| 324 | + for syntax in sublime.list_syntaxes(): |
| 325 | + if any(fnmatch(syntax.path, pattern) for pattern in excludes): |
| 326 | + continue |
| 327 | + # add relative resource path completion (file name of siblings) |
| 328 | + if my_folder: |
| 329 | + folder, file = syntax.path.rsplit("/", 1) |
| 330 | + if folder == my_folder: |
| 331 | + completions.append( |
| 332 | + sublime.CompletionItem( |
| 333 | + trigger=file, |
| 334 | + kind=kind, |
| 335 | + annotation="hidden" if syntax.hidden else "" |
| 336 | + ) |
| 337 | + ) |
| 338 | + # add full resource path |
| 339 | + completions.append( |
| 340 | + sublime.CompletionItem( |
| 341 | + trigger=syntax.path, |
| 342 | + kind=kind, |
| 343 | + annotation="hidden" if syntax.hidden else "" |
| 344 | + ) |
| 345 | + ) |
| 346 | + |
| 347 | + return completions |
| 348 | + |
302 | 349 | def _complete_keyword(self, prefix, locations):
|
303 | 350 |
|
304 | 351 | def match_selector(selector, offset=0):
|
|
0 commit comments