styled-components / vim-styled-components

Vim bundle for http://styled-components.com based javascript files.
300 stars 24 forks source link

Plugin hangs and maxes CPU upon inserting a newline in a JS file #39

Closed b0o closed 6 years ago

b0o commented 6 years ago

After upgrading to 493190e, this plugin is causing (neo)vim to hang.

Any time I try to insert a line break, e.g. by pressing o in normal mode or <return> in insert mode, vim immediately hangs and starts maxing out the CPU. I have to manually kill the vim process.

I have tried to edit several different JS files with the same results, from a very simple file which consists of only the following line...

let foo = "bar"

...to more complex files which contain JSX and styled-components tags, all with the same results.

Downgrading to 1344c3d resolves the problem.

Environment details:

neovim:

NVIM v0.2.2
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Wconversion -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.2.2/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

system (arch linux):

Linux 4.16.8-1-ARCH x86_64 GNU/Linux

plugin manager: dein.vim

I can provide additional details if necessary.

fleischie commented 6 years ago

Oh, wow. What a thorough issue report. Thank you for your effort. 🙂

Unfortunately I am aware of this but wasn't able to fix it, yet. This particular behavior is due to a infinite recursion between vim-styled-component's and vim-jsx's indenting function, that call each other.

The official, recommended quick-fix is to downgrade to the commit you mentioned.

I am working on it though. ✌️

b0o commented 6 years ago

@fleischie Glad to hear! I really appreciate your work on this plugin, it's made my life a lot easier!

fleischie commented 6 years ago

Hey @b0o can you test out the latest develop HEAD? (or more specific ~07c4752~ad1e7ea)

Let me know, if it still hangs. I have to admit, I am getting very mixed results in my tests but this seems to work on my machine fairly reliant. :smile:

b0o commented 6 years ago

Unfortunately 07c4752 still hangs for me

fleischie commented 6 years ago

Did you have the time to check the other commit/newer HEAD? I put more effort into it, after seeing the suggested commit didn't fix it, but broke the indenting on all of the jsx files? 😛

fleischie commented 6 years ago

Now I'm relatively positive, that the current develop branch is in a usable state.

No pressure, but if it works for you as well, I might just make another release of this. :smile:

b0o commented 6 years ago

@fleischie Sorry for the delayed response - 2880d81 works!

By the way, since you seem to have develop as the default branch, I think most plugin managers will install/update to the latest HEAD from there rather than the most recent release. Maybe you should make master default so that unstable code isn't automatically installed when people update their vim plugins?

fleischie commented 6 years ago

@b0o As you may have noticed. I took your advice and made main the default branch, now. I appreciate it, that you (unlike me) paid attention. :sweat_smile: :+1:

dkarter commented 6 years ago

@fleischie this breaks updates and installation using VimPlug. I solved this using:

  Plug 'styled-components/vim-styled-components', { 'branch': 'main', 'for': 'javascript.jsx' }

You may want to update the README to the above or change the branch name to master instead of main (master is more standard and more likely to work out of the box for most plugin managers).

fleischie commented 6 years ago

@dkarter Thanks for the heads up, yeah vim-plug handles it a little different than the other alternatives (by directly supplying a branch name).