From c28dbd488a4558df1f3d921776dec429a7d2db91 Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Wed, 21 Oct 2026 14:02:58 +0000 Subject: [PATCH 1/2] Fix indent after an empty tag with '>' in attributes A line like update(e)} /> was taken as an empty tag without '/>', as '>' in '=>' matched its end, so the next line was indented one level less. Skip '>' in {...} and quotes, and don't take '/>' as the end of an empty tag. --- indent/svelte.vim | 5 ++++- test/cases/shared-empty-tag.svelte | 10 ++++++++++ test/cases/shared-empty-tag.vim | 7 +++++++ .../{lang-attr.svelte => shared-lang-attr.svelte} | 0 test/cases/{lang-attr.vim => shared-lang-attr.vim} | 0 ...ultiline-tag.svelte => shared-multiline-tag.svelte} | 0 .../{multiline-tag.vim => shared-multiline-tag.vim} | 0 ...custom-lang.svelte => shared-no-syntax-file.svelte} | 0 .../{custom-lang.vim => shared-no-syntax-file.vim} | 0 ...width-zero.svelte => shared-shiftwidth-zero.svelte} | 0 ...{shiftwidth-zero.vim => shared-shiftwidth-zero.vim} | 0 11 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/cases/shared-empty-tag.svelte create mode 100644 test/cases/shared-empty-tag.vim rename test/cases/{lang-attr.svelte => shared-lang-attr.svelte} (100%) rename test/cases/{lang-attr.vim => shared-lang-attr.vim} (100%) rename test/cases/{multiline-tag.svelte => shared-multiline-tag.svelte} (100%) rename test/cases/{multiline-tag.vim => shared-multiline-tag.vim} (100%) rename test/cases/{custom-lang.svelte => shared-no-syntax-file.svelte} (100%) rename test/cases/{custom-lang.vim => shared-no-syntax-file.vim} (100%) rename test/cases/{shiftwidth-zero.svelte => shared-shiftwidth-zero.svelte} (100%) rename test/cases/{shiftwidth-zero.vim => shared-shiftwidth-zero.vim} (100%) diff --git a/indent/svelte.vim b/indent/svelte.vim index 4403ec1..67daee5 100644 --- a/indent/svelte.vim +++ b/indent/svelte.vim @@ -23,7 +23,10 @@ let s:svelte_tag_end = '\v^\<\/(script|style)' let s:template_tag = '\v^\s*\<\/?template' " https://developer.mozilla.org/en-US/docs/Glossary/Empty_element let s:empty_tagname = '(area|base|br|col|embed|hr|input|img|keygen|link|meta|param|source|track|wbr)' -let s:empty_tag = '\v\C\<'.s:empty_tagname.'[^/]*\>' +" Empty tag ending with '>' but not '/>'. '>' in {...} like {(e) => f(e)} or +" in quotes doesn't end the tag +let s:empty_tag = '\v\C\<'.s:empty_tagname + \ .'>(\{[^}]*\}|"[^"]*"|''[^'']*''|[^\>{"''/]|/(\>)@!)*\>' let s:empty_tag_start = '\v\<'.s:empty_tagname.'[^\>]*$' let s:empty_tag_end = '\v^\s*[^\<\>\/]*\>\s*' let s:tag_start = '^<$' diff --git a/test/cases/shared-empty-tag.svelte b/test/cases/shared-empty-tag.svelte new file mode 100644 index 0000000..f8f731c --- /dev/null +++ b/test/cases/shared-empty-tag.svelte @@ -0,0 +1,10 @@ +
+ update(e)} /> +

x

+ +

y

+ a +

z

+ b ? 'a' : 'b'}> +

w

+
diff --git a/test/cases/shared-empty-tag.vim b/test/cases/shared-empty-tag.vim new file mode 100644 index 0000000..b378874 --- /dev/null +++ b/test/cases/shared-empty-tag.vim @@ -0,0 +1,7 @@ +" Empty tags like with or without '/>', and '>' in attribute +" expressions +let g:test_flatten = 1 + +function! Check() + call ExpectIndentEachLine() +endfunction diff --git a/test/cases/lang-attr.svelte b/test/cases/shared-lang-attr.svelte similarity index 100% rename from test/cases/lang-attr.svelte rename to test/cases/shared-lang-attr.svelte diff --git a/test/cases/lang-attr.vim b/test/cases/shared-lang-attr.vim similarity index 100% rename from test/cases/lang-attr.vim rename to test/cases/shared-lang-attr.vim diff --git a/test/cases/multiline-tag.svelte b/test/cases/shared-multiline-tag.svelte similarity index 100% rename from test/cases/multiline-tag.svelte rename to test/cases/shared-multiline-tag.svelte diff --git a/test/cases/multiline-tag.vim b/test/cases/shared-multiline-tag.vim similarity index 100% rename from test/cases/multiline-tag.vim rename to test/cases/shared-multiline-tag.vim diff --git a/test/cases/custom-lang.svelte b/test/cases/shared-no-syntax-file.svelte similarity index 100% rename from test/cases/custom-lang.svelte rename to test/cases/shared-no-syntax-file.svelte diff --git a/test/cases/custom-lang.vim b/test/cases/shared-no-syntax-file.vim similarity index 100% rename from test/cases/custom-lang.vim rename to test/cases/shared-no-syntax-file.vim diff --git a/test/cases/shiftwidth-zero.svelte b/test/cases/shared-shiftwidth-zero.svelte similarity index 100% rename from test/cases/shiftwidth-zero.svelte rename to test/cases/shared-shiftwidth-zero.svelte diff --git a/test/cases/shiftwidth-zero.vim b/test/cases/shared-shiftwidth-zero.vim similarity index 100% rename from test/cases/shiftwidth-zero.vim rename to test/cases/shared-shiftwidth-zero.vim From 179ccc043fc5959d084d8bb30056f05591b23b41 Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Wed, 21 Oct 2026 14:02:58 +0000 Subject: [PATCH 2/2] Add shared test cases with vim-vue-plugin Name cases for scenarios also in vim-vue-plugin as shared-*, adding ones for syntax merge, undo and initial indent, and lang="typescript" in shared-lang-attr. test/shared.sh lists shared cases in only one of the plugins, as a warning in a separate job on GitHub Actions. --- .github/workflows/test.yml | 8 +++++++ .gitignore | 1 + README.md | 2 ++ test/cases/shared-initial-indent.svelte | 15 +++++++++++++ test/cases/shared-initial-indent.vim | 10 +++++++++ test/cases/shared-lang-attr.svelte | 8 +++++++ test/cases/shared-lang-attr.vim | 4 +++- test/cases/shared-syntax-merge.svelte | 11 +++++++++ test/cases/shared-syntax-merge.vim | 10 +++++++++ test/cases/shared-undo.svelte | 1 + test/cases/shared-undo.vim | 17 ++++++++++++++ test/shared.sh | 30 +++++++++++++++++++++++++ 12 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 test/cases/shared-initial-indent.svelte create mode 100644 test/cases/shared-initial-indent.vim create mode 100644 test/cases/shared-syntax-merge.svelte create mode 100644 test/cases/shared-syntax-merge.vim create mode 100644 test/cases/shared-undo.svelte create mode 100644 test/cases/shared-undo.vim create mode 100755 test/shared.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 784dd11..902c861 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,3 +26,11 @@ jobs: run: ./test/run.sh env: SVELTE_TEST_EDITORS: ${{ matrix.neovim && 'nvim' || 'vim' }} + + shared: + name: shared cases with vim-vue-plugin + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check shared cases + run: ./test/shared.sh diff --git a/.gitignore b/.gitignore index 137ca65..ac7a121 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ test.svelte .idea test/deps/ doc/tags +test/other/ diff --git a/README.md b/README.md index 2feafce..5fbe57e 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,8 @@ Each case is a `.svelte` file in [test/cases](test/cases), with an optional `.vi Tests also run on GitHub Actions for each push and pull request, with Vim 8.2.0000, the latest Vim, Neovim 0.9.5 and the latest Neovim. +Cases named `shared-*` are for scenarios also in [vim-vue-plugin][3], which handles blocks in the same way. `./test/shared.sh` lists shared cases in only one of them, as a warning on GitHub Actions, so a fix in one plugin can be checked in the other. + ## See also - [vim-svelte-theme][11] svelte syntax color diff --git a/test/cases/shared-initial-indent.svelte b/test/cases/shared-initial-indent.svelte new file mode 100644 index 0000000..267810b --- /dev/null +++ b/test/cases/shared-initial-indent.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/test/cases/shared-initial-indent.vim b/test/cases/shared-initial-indent.vim new file mode 100644 index 0000000..78f3123 --- /dev/null +++ b/test/cases/shared-initial-indent.vim @@ -0,0 +1,10 @@ +" initial_indent by tag.syntax, not for other syntax in the same tag +let g:vim_svelte_plugin_config = { + \ 'syntax': {'style': ['css', 'scss']}, + \ 'initial_indent': ['style.scss'], + \} +let g:test_flatten = 1 + +function! Check() + call ExpectIndentEachLine() +endfunction diff --git a/test/cases/shared-lang-attr.svelte b/test/cases/shared-lang-attr.svelte index 0e0e3ef..d2b372b 100644 --- a/test/cases/shared-lang-attr.svelte +++ b/test/cases/shared-lang-attr.svelte @@ -2,6 +2,14 @@ let count: number = 0; + + + +

{count}

diff --git a/test/cases/shared-syntax-merge.vim b/test/cases/shared-syntax-merge.vim new file mode 100644 index 0000000..7a7895a --- /dev/null +++ b/test/cases/shared-syntax-merge.vim @@ -0,0 +1,10 @@ +" Each key of syntax replaces the default of the same key, so style keeps +" css +let g:vim_svelte_plugin_config = {'syntax': {'script': ['typescript']}} +let g:test_flatten = 1 + +function! Check() + call ExpectBlock('let count', 'script', 'typescript', 'typescriptSvelteScript') + call ExpectBlock('{count}', 'template', 'html', 'htmlSvelteTemplate') + call ExpectBlock('color: red', 'style', 'css', 'cssSvelteStyle') +endfunction diff --git a/test/cases/shared-undo.svelte b/test/cases/shared-undo.svelte new file mode 100644 index 0000000..d87d760 --- /dev/null +++ b/test/cases/shared-undo.svelte @@ -0,0 +1 @@ +

Hello

diff --git a/test/cases/shared-undo.vim b/test/cases/shared-undo.vim new file mode 100644 index 0000000..e5a91fd --- /dev/null +++ b/test/cases/shared-undo.vim @@ -0,0 +1,17 @@ +" Undo settings when filetype changes +let g:vim_svelte_plugin_config = {'foldexpr': 1} +packadd matchit + +function! Check() + call ExpectEqual(&l:foldmethod, 'expr', 'foldmethod') + call ExpectEqual(&l:indentexpr, 'GetSvelteIndent()', 'indentexpr') + call ExpectEqual(exists('b:match_words'), 1, 'b:match_words') + setlocal filetype=text + call ExpectEqual(&l:foldmethod, 'manual', 'foldmethod after undo') + call ExpectEqual(&l:indentexpr, '', 'indentexpr after undo') + call ExpectEqual(exists('b:match_words'), 0, 'b:match_words after undo') + call ExpectEqual(exists('b:syng_str'), 0, 'b:syng_str after undo') + if !has('nvim') + call ExpectEqual(&l:matchpairs, &g:matchpairs, 'matchpairs after undo') + endif +endfunction diff --git a/test/shared.sh b/test/shared.sh new file mode 100755 index 0000000..2518ab6 --- /dev/null +++ b/test/shared.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# List shared-* test cases missing in either vim-svelte-plugin or +# vim-vue-plugin. Both plugins work in the same way for blocks, so a case for +# a scenario in one plugin should be in the other with the same name. Only +# warn, as the other plugin may be updated later +# ./test/shared.sh +cd "$(dirname "$0")/.." || exit 1 +other=vim-vue-plugin + +dir=test/other/$other +rm -rf "$dir" +git clone -q --depth 1 "https://github.com/leafOfTree/$other" "$dir" || exit 0 + +list() { + ls "$1"/test/cases/shared-*.vim 2>/dev/null | sed 's#.*/##; s#\.vim$##' | sort +} +list . > test/other/mine +list "$dir" > test/other/theirs + +missing=0 +for name in $(comm -23 test/other/mine test/other/theirs); do + echo "::warning::$name is not in $other" + missing=1 +done +for name in $(comm -13 test/other/mine test/other/theirs); do + echo "::warning::$name in $other is not here" + missing=1 +done +[ $missing -eq 0 ] && echo "Shared cases are the same as $other" +exit 0