styled-components / vim-styled-components

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

Vim hangs when trying to create styled component #63

Closed omatviiv closed 4 years ago

omatviiv commented 5 years ago

Installed vim-styled-components today June 14, 2019. My env: macOS-Mojave@10.14.5, vim@8.0.1283

  1. When opening file that contains styled component vim opens it with some delay. Each :e on the same file also is delayed.
  2. Trying to edit styled component causes vim to hang and the only way to get vim back is Ctrl-c.

These issues happen only when vim-styled-components is installed (double checked this). I was checking out down the commits tree to get to the working stage of the vim-styled-components, so the first commit that doesn't have the issues described is b5ec6ec51745701f26a206be129fdacf8fecc3ad

Sorry I didn't have more time to investigate deeper, seems like one of the commits that follow b5ec6ec51745701f26a206be129fdacf8fecc3ad is breaking something.

fleischie commented 5 years ago

Hello. Thanks for reporting this issue.

May I ask you for your .vimrc, and optimally a file you observed this behavior for? It would help me to start investigating this issue.

Additionally could you elaborate on what you mean by "hanging"? Is it not responding for a certain amount of time? How long approximately?

I appreciate anything that would help me get started. 🙇

omatviiv commented 5 years ago

First, workaround for this issue for me is to checkout this commit b5ec6ec, maybe someone will find it useful.

vimrc.txt Hi Karl, yes please find attached .vimrc (renamed it to vimrc.txt to be able to attach). I use pathogen to manage vim plugins and in the vimrc there is a section <PLUGINS></PLUGINS> where I store plugins related configurations plus I store there a list of plugins that I use across my environments they are just commented out git clone commands (I do this way because I keep my vimrc on gitlab repo for convenience).

To be honest I didn't make clean test for this particular issue by uninstalling all vim plugins and installing only vim-styled-components. But not all of those plugins I use on the environment where I found this issue. If you wont be able to reproduce this issue let me know I will try on my end with clean setup.

This is the file I had issues with (but it was reproducing for all js files with styled component i guess):

01  import React from 'react';
02  import PropTypes from 'prop-types';
03  import styled from 'styled-components';
04  
05  export const Wrapper = styled.div.attrs({
06    className: 'last-edit',
07  })`
08    color: rgb(0, 102, 204);
09    height: 19px;
10    padding: 0 10px;
11    align-self: flex-end;
12    text-align: right;
13  `;
14  
15  const LastEdit = ({time}) => (
16    <Wrapper>
17      last update: {
18        time && time.toLocaleString ? time.toLocaleString() : 'invalid time'
19      }
20    </Wrapper>
21  );
22  LastEdit.propTypes = {
23    time: PropTypes.object,
24  };
25  
26  export default LastEdit;

On file opening or :e delay was maybe 10 seconds maybe more. When editing styled component, vim was not responding I guess because it was doing something which was blocking vim thread. Pressing ctrl-c stops that job and vim is back to work but syntax highlighting was only applied from line 01 to 05 inclusively. I can't be 100% sure that there is infinite loop somewhere but I was waiting for around 1 or 2 minutes and my patience ended I stopped terminal then found out that it was not necessary because ctrl-c gets vim back to work...

To be more specific for editing styled component I mean go to line 5 and press o, then vim hangs.

fleischie commented 5 years ago

Hey @Oleh-Matviiv ,

I guess you are using the default vim that comes with macOS, right?

I tried to use profiling to find the reason for the slowdown (which I only experienced with the built-in vim), but that feature is not available. I then tried neovim, and to compile vim from the sources (with profiling), only to find the slowdown disappearing. 😞

If you are using the packaged vim version, try installing vim from homebrew and see if that fixes the issue. If not, see if you can setup profiling (if it is available see :help profile for an introduction).

Maybe this gives you a hint, why your specific vim + vimrc + vim-styled-components combination might slow down so significantly. If you have found out anything more specific, but need more help, just report back here, and I see what I can do. 🙏

omatviiv commented 4 years ago

Hello Karl,

Sorry for coming back on this issue so late, thanks for your time and patience, I didn't have time to reinstall vim from sources (a lot have changed in my carrier last months...).

I recently bought new mac where simply installed vim using brew and the issue is not present there. Taking into account that I even no longer have environment where it reproduced I think there is no need to further investigate it. Maybe it was caused by some older version of vim itself and not your plugin.

Again thanks for the effort.

fleischie commented 4 years ago

Glad to hear your appreciation. 😊 Thanks for your follow-up, though. 🙇