styled-components / vim-styled-components

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

Broken indent in TypeScript with vim-polyglot #75

Closed fcanela closed 3 years ago

fcanela commented 4 years ago

In the first place, thanks for creating & maintaining the plugin. I have recently found an issue with indenting and tracked it down to a conflict of plugins.

What happens: When both plugins are enabled, the indentation level is not preserved when pressing enter to create a new line.

Example:

  const blabla = 'blabla'
// The new line is created at this indentation level

Expected:

  const blabla = 'blabla'
  // I would expect it having 2 spaces at start, maintaining the indentation level

The auto-indentation after curly braces is also disabled.

if (true) {
// The new line is created at this indentation level

Expected:

if (true) {
  // The new line is expected to be at this indentation level

All the expected behaviors occur when I disable vim-styled-components and stop when I reenable it. The behavior affected .ts files but not .js.

Minimal init.vim to replicate:

call plug#begin('~/.local/share/nvim/plugged')                                                                                           
Plug 'sheerun/vim-polyglot'                                                                                                              
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }                                                                     
call plug#end() 

I am using NVIM v0.3.8 under Ubuntu 18.04.

I think this could be related to issue #74. I have also tried to apply the code of #62 to my init.vim without success.

stevematney commented 4 years ago

I thought this might be caused by a conflict with yats.vim which is what vim-polyglot uses for TypeScript syntax highlighting and indentation, but when you load just yats.vim and vim-styled-components, indentation works fine. It seems that the conflict is with code specific to vim-polyglot.

Jayphen commented 4 years ago

I'm experiencing this too.

I notice when I run :verbose set indentexpr? with this plugin disabled, I can see Last set from <snip>/vim-polyglot/indent/typescript.vim line 19

If I enable this plugin and run the command again, I see Last set from <snip>/vim-polyglot/after/indent/javascript.vim.

I have no idea what this means, but perhaps it helps debugging.

edit: https://github.com/styled-components/vim-styled-components/blob/main/after/indent/typescript.vim erm, is it this?

If I comment out the above, the indenting works.

Personally I've removed the indent/typescript.vim file from the plugin locally, because I only use css-in-js in typescriptreact files anyway. Keen to know if there's a proper solution

insidewhy commented 4 years ago

If I load vim-styled-components after vim-jsx-pretty, then indentation works in more places, like function bodies. But still doesn't work in json. Had to stop using vim-styled-components.

insidewhy commented 4 years ago

@stevematney BTW this happens without using vim-polyglot, I'm just using plugged here.

cj commented 4 years ago

Just remove https://github.com/styled-components/vim-styled-components/blob/main/after/indent/typescriptreact.vim#L1 from all the files in the indent folder.

alex-shamshurin commented 4 years ago

The same issue is here. Is there any update ?

joaohenrique-hs commented 4 years ago

The same issue is here too :/

joaohenrique-hs commented 4 years ago

When I open another file with other types, when come back to typescript file, indentation works perfectly, even using vim-styled-components

fleischie commented 3 years ago

I merged a PR that advertised to fix this issue. I did not test it, but it is available on the develop branch. If you want you can check it out.

joaohenrique-hs commented 3 years ago

In my tests, it's working perfectly!!! Thanks for the fix :)

richardxia commented 3 years ago

Is there any chance that the fix can be merged from the develop branch into the main branch? I also tested the develop branch, and it fixed the issue for me as well.

I also noticed that the only other change present in develop that's not in main is the message in the README about this project needing a maintainer. Since GitHub only shows the default branch's README by default, that message is not currently being displayed on the main page of the project. You might get more volunteers if you just merged develop into main so that message is more visible. (I sadly don't think I can volunteer because I don't really know vimscript, but I appreciate the work you've done!)

fleischie commented 3 years ago

Cut a new release with the proposed changes, @richardxia thanks for letting me know...

richardxia commented 3 years ago

Thank you!