-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Erroneous newlines using efm in neovim #181
Comments
Same here, happen with prettier for yaml, but also black for python. NVIM versionNVIM v0.5.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /Library/Developer/CommandLineTools/usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET
_MATCH_LIMIT -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconvers
ion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=alwa
ys -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LE
VEL=3 -I/Users/gjeusel/src/neovim/build/config -I/Users/gjeusel/src/neovim/src -I/Users/gjeusel/src/neovim/.deps/us
r/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include -I/opt/homebrew/opt/gettext/include
-I/Users/gjeusel/src/neovim/build/src/nvim/auto -I/Users/gjeusel/src/neovim/build/include
Compiled by [email protected]
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/share/nvim"
Notes:
|
Just noticed I get this problem with The details of this #include "ast.hpp"
#include <string>
std::string print_ast(const AstNode &node, const std::string &prefix, const std::string child_prefix) {
} Output: #include "ast.hpp"
#include <string>
std::string print_ast(const AstNode &node, const std::string &prefix,
const std::string child_prefix) {} Expected (i.e. what I get from running #include "ast.hpp"
#include <string>
std::string print_ast(const AstNode &node, const std::string &prefix,
const std::string child_prefix) {} |
I confirm that I have the same problem with pandoc/yaml, black/python, prettier/json,ts... |
I have two machines. One at home - Linux, another at work - Windows (using powershell). Neovim configurations are the same. And I have a similar issue, but only on a Windows machine and only with files that have windows (\r\n) line endings. If I change line endings to Linux style (\n), formatting works correctly without extra blank lines. On Linux, formatting works regardless eol type. Edit: |
Spent some time looking into this issue and wrote my findings in a neovim issue: neovim/neovim#16842 (comment) cc @mattn @lukas-reineke as you two may be interested |
diff --git a/langserver/diff.go b/langserver/diff.go
index 01d1df3..5bec701 100644
--- a/langserver/diff.go
+++ b/langserver/diff.go
@@ -218,7 +218,7 @@ func shortestEditSequence(a, b []string) ([][]int, int) {
}
func splitLines(text string) []string {
- lines := strings.SplitAfter(text, "\n")
+ lines := strings.Split(text, "\n")
if lines[len(lines)-1] == "" {
lines = lines[:len(lines)-1]
} I'm not sure but does this works good? |
@mattn Unfortunately, it doesn't seem to fix the bug... I haven't gone deep into the diff algorithm. But I can reproduce the problem with a sub-minimal example of version: 2
tools:
sed: &sed
format-command: sed s/[[:blank:]]*$//g
format-stdin: true
languages:
text:
- <<: *sed With the configuration above, the following text file (
is formatted into
with the log of
It looks like the diff code generates an extra delete op? although I'm not sure if it's normal or not. |
Looks like this was fixed in neovim: neovim/neovim#17037 |
Problem
Sometimes when running formatters through EFM in neovim, extra newlines are inserted that would not appear if the formatter was run directly from the command line.
One example of this is running
prettier
to format a table, but this problem seems to be present regardless of which formatter is being run through EFM.Below I'll detail one specific example of this when I used prettier.
Configuration
Using efm within
nvim
with this config:My full configuration can be found here.
NVIM version
EFM version:
efm-langserver 0.0.37 (rev: 9c36ed8/go1.17.1)
Steps to reproduce
Create an empty project directory and install prettier in it:
Add the following file (e.g.
example.md
):Output of
vim.lsp.buf.formatting()
:Expected result
Running
./node_modules/.bin/prettier example.md
:The text was updated successfully, but these errors were encountered: