sheerun / vim-polyglot

A solid language pack for Vim.
5.59k stars 298 forks source link

Javascript indentation #392

Closed nidzola closed 4 years ago

nidzola commented 5 years ago

Does this bug happen when you install plugin without vim-polyglot? No Describe the bug: When I add vim-polyglot plugin, the indentation for javascript blocks stops to work. To Reproduce:

  componentWillMount () {
    const { session, dispatch, randomMethod } = this.props .  <--- place cursor anywhere on this line and press O (for entering the insertation mode)
    randomMethod(session.token)
  }

desired behaviour:

  componentWillMount () {
    const { session, dispatch, randomMethod } = this.props
    | <-- cursor is placed here
    randomMethod(session.token)
  }

actual behavour:

  componentWillMount () {
    const { session, dispatch, randomMethod } = this.props
| <-- cursor is placed here
    randomMethod(session.token)
  }

part of my ~/.vimrc with plugins and stuff related with indent etc.:


...
set wrap
set textwidth=79
set tabstop=2
set expandtab
set shiftwidth=2
set autoindent
set smartindent

filetype on
filetype plugin on
filetype indent on

...
" Unmanaged plugin (manually installed and updated)
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'vim-airline/vim-airline'
Plug 'justinmk/vim-sneak'
Plug 'tpope/vim-surround'
Plug 'dyng/ctrlsf.vim'
Plug 'tpope/vim-fugitive'
Plug 'morhetz/gruvbox'
Plug 'w0rp/ale'
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
Plug 'unblevable/quick-scope'
"Plug 'sheerun/vim-polyglot'
Plug 'jiangmiao/auto-pairs'
Plug 'mileszs/ack.vim'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'
Plug 'mhinz/vim-startify'
Plug 'ntpeters/vim-better-whitespace'
Plug 'Yggdroot/indentLine'
Plug 'tpope/vim-cucumber'
Plug 'tpope/vim-rhubarb'
Plug 'ludovicchabant/vim-gutentags'
Plug 'Valloric/YouCompleteMe'
Plug 'docunext/closetag.vim'
Plug 'mattn/emmet-vim'
Plug 'vim-scripts/argtextobj.vim'
Plug 'vim-scripts/SearchComplete'
Plug 'tpope/vim-endwise'
"  Initialize plugin system
call plug#end()

Edit: Apparently this issue only exists in Vim 8.1, switching to Neovim resolves the problem.

sheerun commented 5 years ago

Does it happen when you use pangloss/vim-javascript directly instead of vim-polyglot?

sheerun commented 5 years ago

I've tested it and it seems to work properly for my installation. Please check if some other plugin is not interfering

mderrien29 commented 5 years ago

Just wanted to say i came across the same issue with typescript files and neovim.

Removing vim-polyglot solved it.

if isdirectory('/usr/local/opt/fzf')
  Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
else
  Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
  Plug 'junegunn/fzf.vim'
endif
let g:make = 'gmake'
if exists('make')
        let g:make = 'make'
endif
Plug 'Shougo/vimproc.vim', {'do': g:make}

"" Vim-Session
Plug 'xolox/vim-misc'
Plug 'xolox/vim-session'

"" random
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-sensible'
Plug 'Raimondi/delimitMate'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/grep.vim'
Plug 'scrooloose/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'Yggdroot/indentLine'
Plug 'itchyny/lightline.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'chrisbra/colorizer'
Plug 'prettier/vim-prettier', { 'do': 'npm install' }
Plug 'christoomey/vim-tmux-navigator'
Plug 'bling/vim-bufferline'
Plug 'whiteinge/diffconflicts'
Plug 'itchyny/vim-parenmatch'

"" Text objs
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-entire'
Plug 'kana/vim-textobj-function'

" colorscheme
Plug 'dracula/vim', { 'as': 'dracula' }

"" LANGUAGE SUPPORT
Plug 'HerringtonDarkholme/yats.vim'
Plug 'burnettk/vim-angular'
Plug 'posva/vim-vue'
Plug 'w0rp/ale'
Plug 'Valloric/MatchTagAlways'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & npm install'  }
Plug 'mzlogin/vim-markdown-toc'
sidneyw commented 4 years ago

Has there been any investigation into this issue? I am experiencing this with typescript files in neovim as well. The resolution is to remove polyglot.

andwilley commented 4 years ago

Turning off jsx solved this issue in javascript for me.

let g:polyglot_disabled = ['jsx']

This was helpful in diagnosing the issue:

https://stackoverflow.com/a/18670672

running:

:verbose set indentexpr?

resulted in:

indentexpr=GetJsxIndent()                                                                                                                                                                   
        Last set from ~/.vim/bundle/vim-polyglot/after/indent/javascript.vim line 23
sheerun commented 4 years ago

I believe this this fixed now, could you confirm?

andwilley commented 4 years ago

after running :PluginUpdate (vundle) and uncommenting the above polyglot-disabled line, this is still an issue for me.

sheerun commented 4 years ago

Could you post your .vimrc?

andwilley commented 4 years ago

https://github.com/andwilley/vim-settings/blob/master/.vimrc

andwilley commented 4 years ago

When I get a chance I'll check this on my personal computer as well. There may be something specific to my setup at work that is not playing nice with polyglot.

andwilley commented 4 years ago

Indentation works fine on my setup at home after the update. I'll look into what the issue could still be at work. Thanks for looking into this.

Nohac commented 4 years ago

I also had this issue with typescript. I figured out that removing Plug 'styled-components/vim-styled-components', { 'branch': 'main' } made it work properly again. And after some playing around, I figured out that loading styled-components before polyglot also worked.

sidneyw commented 4 years ago

I also had this issue with typescript. I figured out that removing Plug 'styled-components/vim-styled-components', { 'branch': 'main' } made it work properly again. And after some playing around, I figured out that loading styled-components before polyglot also worked.

This worked for me. Thanks for looking into this @sheerun!

sheerun commented 4 years ago

This was @Nohac not me :)

mjc-gh commented 4 years ago

I'm experiencing an issue for Typescript with JSX markup (.tsx file types). I am using latest version of vim-polyglot via janus. I also have vim-styled-components installed via Janus customizations, which means it's loaded after vim-polyglot. Removing styled-components does not seem to change my indenting of JSX markup.

image

Without vim-styled-components when I run verbose set indentexpr? I see:

  indentexpr=GetTypescriptIndent()
        Last set from ~/.vim/janus/vim/langs/vim-polyglot/indent/typescript.vim

With vim-styled-components, I see:

  indentexpr=GetStyledIndent()
        Last set from ~/.janus/vim-styled-components/after/indent/javascript.vim

But again, with or without vim-styled-components, I do not see any changes in indenting of the JSX markup in my tsx files.

sheerun commented 4 years ago

well, it's clear that this is a bug in vim-styled-components. it seems it messes up tsx / jsx indentation, that's why it only works if it's loaded first (vim-polyglot overrides indentation to correct value). I cannot do much about it, so I'm closing it. I suggest contributing to vim-styled-components or opening issue there if it bothers someone

sheerun commented 4 years ago

If someone sees some other javascript indentation issue, please open another issue, this thread is too long already and lists multiple indentation issues instead of one