Giter Club home page Giter Club logo

Comments (13)

rhysd avatar rhysd commented on June 20, 2024

@will

I can't reproduce it yet.
The original formatted source code is this?

In my environment, the space is not appended. Please let me know your Vim and Crystal version.

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

@will
This is log on my desktop. Could you try it in your environment if you can?

~/Dev/github.com/manastech/crystal % cat pg.cr
require "./core_ext/*"
require "./pg/*"

module PG
  def self.connect(conninfo)
    conn = Connection.new(conninfo)
    conn.exec("SET extra_float_digits = 3")
    conn
  end
end

~/Dev/github.com/manastech/crystal % cat pg.cr | crystal tool format -
require "./core_ext/*"
require "./pg/*"

module PG
  def self.connect(conninfo)
    conn = Connection.new(conninfo)
    conn.exec("SET extra_float_digits = 3")
    conn
  end
end

I want to be sure that this is vim-crystal's bug.

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

vim-crystal formatting process is

  1. Get whole buffer and format it with crystal tool format. The result is preserved to g register.
  2. Delete current buffer with gg"_G
  3. Put the g register content by "gp.

I think 3. behavior may depend on some options and I've not noticed that yet.

from vim-crystal.

will avatar will commented on June 20, 2024

Yes that file

I'm using neovim,

~ ➤ vim --version
NVIM 0.0.0-alpha+201508051908 (compiled Aug  6 2015 21:31:10)
Commit: 5a195858657e1c494e77ea868073d2f3664cdb60
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim20150806-83927-pht89k/build/config -I/tmp/neovim20150806-83927-pht89k/src -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include/luajit-2.0 -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include -I/tmp/neovim20150806-83927-pht89k/deps-build/usr/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim20150806-83927-pht89k/build/src/nvim/auto -I/tmp/neovim20150806-83927-pht89k/build/include
Compiled by will@skadi

Optional features included (+) or not (-): +acl   +iconv    +jemalloc
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/nvimrc"
     user vimrc file: "~/.nvimrc"
 2nd user vimrc file: "~/.nvim/nvimrc"
      user exrc file: "~/.exrc"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD/share/nvim"

but also regular (not neo) vim has the same issue

test ➤ /usr/local/Cellar/vim/7.4.826/bin/vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep  3 2015 06:56:16)
MacOS X (unix) version
Included patches: 1-826
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         -gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        -mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: /usr/bin/clang   -L. -L/Users/will/.rbenv/versions/2.2.0/lib  -fstack-protector -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -F/usr/local/Cellar/python/2.7.10_2/Frameworks -framework Python   -lruby-static -framework CoreFoundation -lobjc -L/Users/will/.rbenv/versions/2.2.0/lib

The log you asked for is the same

test ➤ cat pg.cr
require "./core_ext/*"
require "./pg/*"

module PG
  def self.connect(conninfo)
    conn = Connection.new(conninfo)
    conn.exec("SET extra_float_digits = 3")
    conn
  end
end
test ➤ cat pg.cr | crystal tool format -
require "./core_ext/*"
require "./pg/*"

module PG
  def self.connect(conninfo)
    conn = Connection.new(conninfo)
    conn.exec("SET extra_float_digits = 3")
    conn
  end
end
test ➤ diff <(cat pg.cr) <(cat pg.cr | crystal tool format -)
test ➤

Maybe it's something in my rc file? https://github.com/will/dotfiles/blob/master/vimrc

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

Thakn you for the information. I think I can try again.

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

I found that set virtualedit=all causes this problem. I'll fix it.

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

@will

I fixed the bug. Please update this plugin and confirm the bug is fixed in your environment.

from vim-crystal.

will avatar will commented on June 20, 2024

Almost! The first space is gone, but there is still an extra newline at the end

diff --git i/src/pg.cr w/src/pg.cr
index b4a8352..cd2fb6a 100644
--- i/src/pg.cr
+++ w/src/pg.cr
@@ -8,3 +8,4 @@ module PG
     conn
   end
 end
+

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

That's right :(

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

Actually the newline is derived from Vim's odd behavior on empty buffer. POSIX defines that text file must be ended with newline. So, when buffer is empty, Vim adds newline to buffer and it remains after putting the formatted code.

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

@will

I fixed again!

from vim-crystal.

will avatar will commented on June 20, 2024

Just tried it out. Works great, thank you!

from vim-crystal.

rhysd avatar rhysd commented on June 20, 2024

👍

from vim-crystal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.