styled-components / vim-styled-components

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

E363: pattern uses more memory than 'maxmempattern' #28

Closed mxstbr closed 6 years ago

mxstbr commented 7 years ago

Getting this error when opening any (?) JS file:

screen shot 2017-09-01 at 8 43 21 am

These files don't even contain any styled components!

fleischie commented 7 years ago

Hi Max, every JS file? Yes, probably. 😑

The way this plugin works is by checking, whether something is required/imported from a supported API by searching for a specific regular expression on every javascript file. The default memory is 1000 bytes and the error message basically indicates, that the search has to keep more than 1000 bytes in memory to check, whether this is the case.

I will have to tweak the regular expression to be not as inclusive but at the same time inclusive enough to not let all the edge case import/require statements fall off.

Currently it checks for (assume libraries is the list of supported library names):

import(.|\n)*from.*[libraries]

or

require(.|\n)*'[libraries]

Or it's an unmatched parenthesis thing? Like in this similar issue on vim-markdown. I have to check, thanks for the notification. 😊

mxstbr commented 7 years ago

I feel like assuming that any styled.div call with a tagged template literal likely has styles after it is fine, why do we check for imports?

fleischie commented 7 years ago

I thought checking for imports is the smallest common denominator.

The plugin does not specifically highlights CSS rules in tagged template literals, but CSS rules in all template strings, if the import statement is present.

But now that you mention it, maybe it makes more sense to only inject CSS rules into tagged template literals? But then again, how to know whether it's only API-conform tagged template literals?

mxstbr commented 7 years ago

I think there's just three cases where they should be highlighted as CSS:

styled.x`

`

styled(X)`

`

Comp.extend`

`
fleischie commented 7 years ago

What about css, injectGlobal, etc.?

There already was a discussion about whether to whitelist the tagged templates and I wasn't really convinced. (See #21.)

Do you have a lot of plugins and/or give an example file, that displays the maxmempattern errors? So I can better test? Also what's your environment? Vim Version, OS, etc.

fleischie commented 6 years ago

@mxstbr If you are still interested in this issue, I discussed a complete rewrite of this plugin in this comment on #21.

I hope that a complete rewrite will mitigate this memory pattern issue.

fleischie commented 6 years ago

Update: Please see whether #30 helps you with this error.

omeid commented 6 years ago

30 solves the problem for me.

nvim --version
NVIM v0.2.2
nerfologist commented 6 years ago

I also run into this error when running various commands on a non-styled component .js file.

30 solves the problem for me too.

fleischie commented 6 years ago

Next week I'll probably merge #30 after fixing some long-standing issues. Hopefully this should fix this for good for now.

f3270 commented 4 years ago

I just solved this issue by adding:

set maxmempattern = 2000000

to my vimrc.

In my case the symptom was inserting a '[' char on a long markdown file (~4K lines).

Found the solution here:

https://www.zhihu.com/question/60367881

You can also check :help maxmempattern