From 033df1b169d9b48ba9a1d760b309bbaab79fd635 Mon Sep 17 00:00:00 2001 From: Ian Emnace Date: Tue, 19 Mar 2019 14:50:15 +0800 Subject: [PATCH] Enforce order of pre-processor syntax files The plugin's current behavior is reliant on the order of loading pre-processor syntax files. In particular, Vader tests are failing for SCSS snippets; SASS syntax identifiers are applied instead. Unfortunately, no ordering information can be embedded in a Dictionary, so s:language_config must be turned into a List. In the unconfigured case (no g:vue_disable_pre_processors, no g:vue_pre_processors), pre_processors can be initialized to a well-ordered List of languages (ordered as they appear in s:language_config), instead of the unstable keys() on a dict. Random access of language config is faster from a dict, though, so a dict is rebuilt in s:language_dict. Going through the s:language_config List for every pre-processor in pre_processors is O(m * n), as opposed to building s:language_dict once then looping through pre-processors once for O(m + n) (since dict access is constant time). --- syntax/vue.vim | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/syntax/vue.vim b/syntax/vue.vim index 4946b9d..ab43aed 100644 --- a/syntax/vue.vim +++ b/syntax/vue.vim @@ -42,30 +42,33 @@ function! s:register_language(language, tag, ...) endif endfunction -let s:language_config = { - \ 'less': ['less', 'style'], - \ 'pug': ['pug', 'template', s:attr('lang', '\%(pug\|jade\)')], - \ 'slm': ['slm', 'template'], - \ 'handlebars': ['handlebars', 'template'], - \ 'haml': ['haml', 'template'], - \ 'typescript': ['typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)'], - \ 'coffee': ['coffee', 'script'], - \ 'stylus': ['stylus', 'style'], - \ 'sass': ['sass', 'style'], - \ 'scss': ['scss', 'style'], - \ } - +let s:language_config = [ + \ {'lang': 'less', 'args': ['less', 'style']}, + \ {'lang': 'pug', 'args': ['pug', 'template', s:attr('lang', '\%(pug\|jade\)')]}, + \ {'lang': 'slm', 'args': ['slm', 'template']}, + \ {'lang': 'handlebars', 'args': ['handlebars', 'template']}, + \ {'lang': 'haml', 'args': ['haml', 'template']}, + \ {'lang': 'typescript', 'args': ['typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)']}, + \ {'lang': 'coffee', 'args': ['coffee', 'script']}, + \ {'lang': 'stylus', 'args': ['stylus', 'style']}, + \ {'lang': 'sass', 'args': ['sass', 'style']}, + \ {'lang': 'scss', 'args': ['scss', 'style']}, + \ ] +let s:language_dict = {} +for item in s:language_config + let s:language_dict[item.lang] = item.args +endfor if !exists("g:vue_disable_pre_processors") || !g:vue_disable_pre_processors if exists("g:vue_pre_processors") let pre_processors = g:vue_pre_processors else - let pre_processors = keys(s:language_config) + let pre_processors = map(copy(s:language_config), {k, v -> v.lang}) endif for language in pre_processors - if has_key(s:language_config, language) - call call("s:register_language", get(s:language_config, language)) + if has_key(s:language_dict, language) + call call("s:register_language", get(s:language_dict, language)) endif endfor endif