Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoformat_config_present does not re-evaluate the presence of the prettier config file after vim is started #233

Closed
cjlarose opened this issue Apr 8, 2020 · 0 comments · Fixed by #234

Comments

@cjlarose
Copy link
Contributor

cjlarose commented Apr 8, 2020

Do you want to request a feature or report a bug?

Bug

What is the current/expected behavior?

The logic surrounding autoformat_config_present basically only runs once (when the plugin is loaded). It is desirable for that logic to be deferred until the buffer is actually written in at least two cases:

  1. If you create a prettier config file in the project after you started the vim instance or
  2. If you just happened to have started vim in a different directory, then :cd'ed into the directory where a prettier config file resides (or a subdirectory of such a directory)

The former bug is hopefully straightforward, but I've given more detail for the latter bug below in case it's not clear.

STR:

In .vimrc

let g:prettier#autoformat = 0 " default setting
let g:prettier#autoformat_config_present = 1 " default is 0

Example project structure:

mkdir vim-prettier-pwd-test
mkdir vim-prettier-pwd-test/plugin
echo '{}' > vim-prettier-pwd-test/plugin/.prettierrc
cat > vim-prettier-pwd-test/plugin/index.ts <<'EOF'
/**
 * @format
 */
console.log('hello');
EOF
tree -a vim-prettier-pwd-test
vim-prettier-pwd-test
└── plugin
    ├── .prettierrc
    └── index.ts

1 directory, 2 files

Open vim, :cd (or :lcd or :tcd in nvim), open the file and save

cd vim-prettier-pwd-test
nvim
:cd plugin
:e index.ts
:w

Expected

Prettier runs when you save the buffer

Observed

Prettier does not run

What version of vim-prettier are you using - (output of :PrettierVersion) ?

1.0.0-alpha

What version of prettier are you using - (output of :PrettierCliVersion) ?

2.0.4

What is your prettier executable path - (output of :PrettierCliPath) ?

/Users/chris.larose/vim-prettier-pwd-test/plugin/node_modules/.bin/prettier

Did this work in previous versions of vim-prettier and/or prettier ?

Pretty sure the same behavior has been present since the introduction of autoformat_config_present in #212

@cjlarose cjlarose changed the title autoformat_config_present does not re-evaluate the presense of the prettier config file after vim is started autoformat_config_present does not re-evaluate the presence of the prettier config file after vim is started Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant