mirror of
https://github.com/posva/vim-vue.git
synced 2025-12-07 18:14:26 +08:00
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).
This commit is contained in:
@@ -42,30 +42,33 @@ function! s:register_language(language, tag, ...)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:language_config = {
|
let s:language_config = [
|
||||||
\ 'less': ['less', 'style'],
|
\ {'lang': 'less', 'args': ['less', 'style']},
|
||||||
\ 'pug': ['pug', 'template', s:attr('lang', '\%(pug\|jade\)')],
|
\ {'lang': 'pug', 'args': ['pug', 'template', s:attr('lang', '\%(pug\|jade\)')]},
|
||||||
\ 'slm': ['slm', 'template'],
|
\ {'lang': 'slm', 'args': ['slm', 'template']},
|
||||||
\ 'handlebars': ['handlebars', 'template'],
|
\ {'lang': 'handlebars', 'args': ['handlebars', 'template']},
|
||||||
\ 'haml': ['haml', 'template'],
|
\ {'lang': 'haml', 'args': ['haml', 'template']},
|
||||||
\ 'typescript': ['typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)'],
|
\ {'lang': 'typescript', 'args': ['typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)']},
|
||||||
\ 'coffee': ['coffee', 'script'],
|
\ {'lang': 'coffee', 'args': ['coffee', 'script']},
|
||||||
\ 'stylus': ['stylus', 'style'],
|
\ {'lang': 'stylus', 'args': ['stylus', 'style']},
|
||||||
\ 'sass': ['sass', 'style'],
|
\ {'lang': 'sass', 'args': ['sass', 'style']},
|
||||||
\ 'scss': ['scss', '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_disable_pre_processors") || !g:vue_disable_pre_processors
|
||||||
if exists("g:vue_pre_processors")
|
if exists("g:vue_pre_processors")
|
||||||
let pre_processors = g:vue_pre_processors
|
let pre_processors = g:vue_pre_processors
|
||||||
else
|
else
|
||||||
let pre_processors = keys(s:language_config)
|
let pre_processors = map(copy(s:language_config), {k, v -> v.lang})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for language in pre_processors
|
for language in pre_processors
|
||||||
if has_key(s:language_config, language)
|
if has_key(s:language_dict, language)
|
||||||
call call("s:register_language", get(s:language_config, language))
|
call call("s:register_language", get(s:language_dict, language))
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user