Skip to content

file content is stripped when formatting with folds closed #124

@zanona

Description

@zanona

Related with #102, it seems that depending on the code structure coc-prettier will partially remove file contents instead of formatting whenever folding is enabled.

The file being test against is the following, however I had the same sort of behaviour with different structures, where the content is partially/fully stripped:

module.exports = function () {

return;
};

Please bear in mind this happens only with syntax folding enabled on load and running :CocCommand prettier.formatFile or through coc.preferences.formatOnSaveFiletypes

I have been able to reproduce this under a clean installation under a container with the following image:

FROM node:alpine
WORKDIR /root

RUN apk add vim git

# install coc.vim
RUN mkdir -p ~/.vim/pack/coc/start
RUN cd ~/.vim/pack/coc/start && git clone --depth 1 https://github.com/neoclide/coc.nvim.git

# define ~/.vimrc
RUN echo "set background=dark" >> ~/.vimrc
RUN echo "set foldmethod=syntax" >> ~/.vimrc
RUN echo "set foldlevelstart=0" >> ~/.vimrc
RUN echo "let javaScript_fold=1" >> ~/.vimrc

# prepare coc-prettier auto-install
RUN echo "let g:coc_global_extensions = [ 'coc-prettier' ]" >> ~/.vimrc

# add test file 
RUN printf 'module.exports = function(){\n\nreturn;\n};\n' > ~/test.js

To reproduce:

  • docker build . -t vim-coc-test
  • docker -it --rm vim-coc-test vim test.js
  • wait coc-prettier installation and press q once done
  • with test.js open and folding closed, run vim command :CocCommand prettier.formatFile
  • press any key and you will see content has been removed

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions