From de9fbec1ade05a6fa6161ce1478a85be05530012 Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Wed, 21 Oct 2026 13:51:38 +0000 Subject: [PATCH] Handle syntax without syntax or indent files A syntax in the config without a syntax file, like postcss, showed E484 on opening a file. Skip loading it, with a warning in debug. A syntax without an indent file used cindent, which broke indent of languages like pug, stylus without their plugins, or toml. Keep the indent instead. Lines outside blocks still use cindent. --- autoload/vue.vim | 4 ++++ indent/vue.vim | 5 +++++ test/cases/no-syntax-indent-file.vim | 15 +++++++++++++++ test/cases/no-syntax-indent-file.vue | 15 +++++++++++++++ test/run.vim | 6 ++++-- 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/cases/no-syntax-indent-file.vim create mode 100644 test/cases/no-syntax-indent-file.vue diff --git a/autoload/vue.vim b/autoload/vue.vim index 0f08ba6..f4fe80f 100644 --- a/autoload/vue.vim +++ b/autoload/vue.vim @@ -263,6 +263,10 @@ endfunction " Load all syntax files in 'runtimepath' " Useful if there is no default syntax file provided by vim function! vue#LoadFullSyntax(group, syntax) + if empty(globpath(&runtimepath, 'syntax/'.a:syntax.'.vim')) + call vue#Warn(a:syntax.': syntax not found in runtimepath') + return + endif call vue#Log(a:syntax.': load full') call s:SetCurrentSyntax(a:syntax) execute 'syntax include '.a:group.' syntax/'.a:syntax.'.vim' diff --git a/indent/vue.vim b/indent/vue.vim index aece7f8..f66bd3d 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -75,6 +75,11 @@ function! s:GetBlockIndent(syntax) let indentexpr = get(s:indent, syntax) if !empty(indentexpr) let ind = eval(indentexpr) + elseif has_key(s:indent, syntax) + " No indent file for syntax in config, keep indent as cindent may break + " languages like pug or toml + call vue#LogWithLnum('indentexpr not found for '.syntax.', keep indent') + let ind = -1 else call vue#LogWithLnum('indentexpr not found for '.syntax.', use cindent') let ind = cindent(v:lnum) diff --git a/test/cases/no-syntax-indent-file.vim b/test/cases/no-syntax-indent-file.vim new file mode 100644 index 0000000..ef233b3 --- /dev/null +++ b/test/cases/no-syntax-indent-file.vim @@ -0,0 +1,15 @@ +" postcss has no syntax or indent file, toml has no indent file. They have +" their blocks and keep indent +let g:vim_vue_plugin_config = { + \'syntax': { + \ 'template': ['html'], + \ 'style': ['css', 'postcss'], + \ 'i18n': ['toml'], + \}, + \} + +function! Check() + call ExpectBlock('color: blue', 'style', 'postcss', 'postcssStyleBlock') + call ExpectBlock('hello', 'i18n', 'toml', 'tomlI18nBlock') + call ExpectIndentEachLine() +endfunction diff --git a/test/cases/no-syntax-indent-file.vue b/test/cases/no-syntax-indent-file.vue new file mode 100644 index 0000000..4c68d4a --- /dev/null +++ b/test/cases/no-syntax-indent-file.vue @@ -0,0 +1,15 @@ + + + + + +[en] + hello = "hi" + diff --git a/test/run.vim b/test/run.vim index 1179998..55e6eaa 100644 --- a/test/run.vim +++ b/test/run.vim @@ -92,7 +92,8 @@ function! ExpectTag(lnum, tag) endfunction " Call GetVueIndent() for each non-blank line from line 2 as when typing it, -" which shows errors hidden by 'indentexpr', and check the indent +" which shows errors hidden by 'indentexpr', and check the indent. -1 keeps +" the indent function! ExpectIndentEachLine() for lnum in range(2, line('$')) if getline(lnum) =~ '^\s*$' @@ -101,7 +102,8 @@ function! ExpectIndentEachLine() call cursor(lnum, 1) let v:lnum = lnum try - call ExpectEqual(GetVueIndent(), indent(lnum), + let ind = GetVueIndent() + call ExpectEqual(ind == -1 ? indent(lnum) : ind, indent(lnum), \ printf('GetVueIndent() at line %d', lnum)) catch call Fail(printf('GetVueIndent() at line %d: %s', lnum, v:exception))