diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 6fdaa524..af3099ad 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -1031,8 +1031,8 @@ def DocRangeFormat(fname: string, line1: number, line2: number, canFallback: boo if canFallback util.WarnMsg('Formatting unsupported; falling back to built-in.') execute $'keepjumps normal! {line1}Ggq{line2}G' - elseif !&filetype->empty() - util.ErrMsg($'Language server for "{&filetype}" file type supporting "documentRangeFormatting" feature is not found') + # elseif !&filetype->empty() + # util.ErrMsg($'Language server for "{&filetype}" file type supporting "documentRangeFormatting" feature is not found') else util.ErrMsg('No language server supporting "documentRangeFormatting" feature is found') endif @@ -1051,10 +1051,10 @@ def DocFormat(fname: string, canFallback: bool) if canFallback util.WarnMsg('Formatting unsupported; falling back to built-in.') execute 'keepjumps normal! 1GgqG' - elseif !&filetype->empty() - util.ErrMsg($'Language server for "{&filetype}" file type supporting "documentFormatting" feature is not found') - # else - # util.ErrMsg('No language server supporting "documentFormatting" feature is found') + # elseif !&filetype->empty() + # util.ErrMsg($'Language server for "{&filetype}" file type supporting "documentFormatting" feature is not found') + else + util.ErrMsg('No language server supporting "documentFormatting" feature is found') endif enddef @@ -1289,6 +1289,12 @@ enddef export def FormatExpr(): number var lspserver: dict = buf.CurbufGetServerChecked('documentRangeFormatting') if lspserver->empty() + if &formatexpr == 'lsp#lsp#FormatExpr()' + defer execute("setl formatexpr='lsp#lsp#FormatExpr()'") + setl formatexpr='' + execute $'keepjumps normal! {v:lnum}Ggq{v:lnum + v:count - 1}G' + return 0 + endif return 1 endif diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index c17787f0..5b2d4918 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -146,11 +146,12 @@ def g:Test_LspFormat() bw! # empty file - assert_equal('', execute('LspFormat')) + assert_equal('Error: No language server supporting "documentFormatting" feature is found', + execute('LspFormat')->split("\n")[0]) # file without an LSP server edit a.raku - assert_equal('Error: Language server for "raku" file type supporting "documentFormatting" feature is not found', + assert_equal('Error: No language server supporting "documentFormatting" feature is found', execute('LspFormat')->split("\n")[0]) :%bw! @@ -164,7 +165,11 @@ def g:Test_LspFormatExpr() setline(1, [' int i;', ' int j;']) :redraw! normal! ggVGgq - assert_equal(['int i;', 'int j;'], getline(1, '$')) + if v:version == 900 + g:WaitForAssert(() => assert_equal([' int i;', ' int j;'], getline(1, '$'))) + elseif g:WaitForAssert(() => assert_equal(['int i;', 'int j;'], getline(1, '$'))) + g:WaitForAssert(() => assert_equal([' int i; int j;'], getline(1, '$'))) + endif # empty line/file deletebufline('', 1, '$')