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

Does it work on Windows? #44

Closed
alex-shamshurin opened this issue Aug 18, 2017 · 21 comments
Closed

Does it work on Windows? #44

alex-shamshurin opened this issue Aug 18, 2017 · 21 comments
Labels

Comments

@alex-shamshurin
Copy link

Prettier cli works from windows console, but :Prettier does not.

@mitermayer
Copy link
Member

Hi @alex-shamshurin,

Will start looking into this and do a release to fix it.

Thank you for reporting!

@mitermayer mitermayer added the bug label Aug 18, 2017
@alex-shamshurin
Copy link
Author

Sorry, but is there any progress? I think it's only replace slashes...

@mitermayer
Copy link
Member

@alex-shamshurin I will look into this this weekend and do a release to fix it but please feel free to submit a PR in the meantime.

@mitermayer
Copy link
Member

I have just downloaded a windows virtual machine and will investigate this issue tomorrow.

@mitermayer
Copy link
Member

Did not have a chance to look into this yet, if anyone has some time feel free to pick it up. Will try to find some time to look into it tomorrow

@alex-shamshurin
Copy link
Author

Ok, I think it's very easy, but I do not know vim-script

@mitermayer
Copy link
Member

I have just tested this on windows and could not replicate the above described bug.


Using vim from windows powershell:

output


Using gvim:

output

Happy to re-open or create a new issue if having more context around it.

@alex-shamshurin
Copy link
Author

alex-shamshurin commented Aug 22, 2017

Hmm, how to debug it? Prettier really works from command line (from project node_modules.bin) and :Prettier command does not provide any error output. It just do nothing. may be it is expected Prettitier must be globally installed?

@mitermayer
Copy link
Member

mitermayer commented Aug 22, 2017

Hi @alex-shamshurin,

There are 3 ways that vim-prettier can find the prettier executable


A - It looks to find the ./node_modules for the binary in the path of the current parent folder


B - If [A] fails then - It looks for a global prettier installation


C - If [B] fails then - It looks for the prettier installation that is installed inside vim-prettier itself*

* - As per the readme this assumes you have either used vim-plug post-install to do it or gone manually to the vim-prettier folder and did a npm install or yarn install


Would be great if you could provide more information on how is it failing for you so that I can better assist you.

  • Are you starting vim from the folder that has prettier installed ?
  • Do you have prettier installed globally ?
  • Have you installed vim-prettier with a post-install script or did a manual prettier install inside the pluggin folder ?
  • Also after you execute the command :Prettier could please run the command :messages and post here the output ?

@alex-shamshurin
Copy link
Author

alex-shamshurin commented Aug 22, 2017

  1. Yes, prettier is in devDependencies and installed inside my project and it works on my mac and on Linux, but does not work on Windows. It works fine from command line from console node_modules\.bin\prettier <filename>
  2. No
  3. I've just run standart :PlugInstall
  4. No messages! Clean history, no errors, warning, etc

@alex-shamshurin
Copy link
Author

Please reopen this issue, until it solved

@ghost
Copy link

ghost commented Aug 23, 2017

Have you set any of the configuration variables for vim-prettier?

I ask because I've noticed a separate issue where the async version does nothing yet reports no errors.

@mitermayer mitermayer reopened this Aug 23, 2017
@mitermayer
Copy link
Member

mitermayer commented Aug 23, 2017

Hi @alex-shamshurin,

I have re-opened this issue to try to help solving your problem, I still cannot reproduce this issue that you have described. I have however confirmed the bug where PrettierAsync is not working on windows created by @boojinks .

The command :Prettier works as expected with all 3 cases, including finding the local installation of the binary in node_modules.

To better debug this issue would be great to know your vim version ?

Also Could you try running vim with just vim-prettier enabled to see if that could be some incompatibilities with some of your vim settings / plugins ?

Thanks for your patience, happy to work together with you to make sure you are unblocked.

@alex-shamshurin
Copy link
Author

My vim version is:
vim-version

I've disabled all other plugins except vim-prettier and it still does not work and says nothing.
All I new about vim-script it's a echom command. So what I suggest, - I can insert echom to some functions to debug. In what functions should I insert it to find out what happened and why the plugin is silent?

@alex-shamshurin
Copy link
Author

Also I have disabled all plugin settings and it did not help

@alex-shamshurin
Copy link
Author

alex-shamshurin commented Aug 24, 2017

Hmm, I added some debug points to prettitier.vim and I discovered that when I run :Prettitier (NOT :PrettitierAsync) it goes to async instead of sync mode


    if l:async && v:version >= 800 && exists('*job_start')
      echom "Before Async"
      call s:Prettier_Exec_Async(l:cmd, l:startSelection, l:endSelection)
    else
      echom "Before Sync"
      call s:Prettier_Exec_Sync(l:cmd, l:startSelection, l:endSelection)
    endif

result is "Before Async"

function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
  echom "In Exec ASync"
  if s:prettier_job_running != 1
      let s:prettier_job_running = 1
      call job_start(a:cmd, {
        \ 'in_io': 'buffer',
        \ 'in_top': a:startSelection,
        \ 'in_bot': a:endSelection,
        \ 'in_name': bufname('%'),
        \ 'err_cb': {channel, msg -> s:Prettier_Job_Error(msg)},
        \ 'close_cb': {channel -> s:Prettier_Job_Close(channel, a:startSelection, a:endSelection)}})
  endif
endfunction

message is "In Exec ASync

if change l:async=0 it works

function! prettier#Prettier(...) abort
  echom "In Prettier"
  let l:execCmd = s:Get_Prettier_Exec()
  echom l:execCmd
  let l:async = a:0 > 0 ? a:1 : 0
  **let l:async = 0**
 ....

It then goes to sync mode and did job. So please fix it!

@ghost
Copy link

ghost commented Aug 24, 2017

I suspected it might be the same problem I was having.

I don't have access to put in a pull request at the moment but the below should fix it for you.

function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
  if s:prettier_job_running != 1
      let s:prettier_job_running = 1

      if has('win32') || has('win64') 
          let l:correct_cmd = 'cmd.exe /c ' . a:cmd
      else
          let l:correct_cmd = a:cmd
      endif
      
      call job_start(l:correct_cmd, {
        \ 'in_io': 'buffer',
        \ 'in_top': a:startSelection,
        \ 'in_bot': a:endSelection,
        \ 'in_name': bufname('%'),
        \ 'err_cb': {channel, msg -> s:Prettier_Job_Error(msg)},
        \ 'close_cb': {channel -> s:Prettier_Job_Close(channel, a:startSelection, a:endSelection)}})
  endif
endfunction

If it does, could you do me a massive favour and put in a PR?

Thank you.

@mitermayer
Copy link
Member

mitermayer commented Aug 24, 2017

Thank you both of you @boojinks and @alex-shamshurin for working together on this issue, will test the above code and submit a PR for it.

One thing that I cannot understand is why on @alex-shamshurin he was going to the async code path, the default vim-prettier async setting is to have async disabled, unless he has added the async setting to his .vimrc regardless will submit a fix and do a release for async now.

@alex-shamshurin do you have this line on your .vimrc ?

g:prettier#exec_cmd_async=1

Once again thank you all for working together on this issue :)

@alex-shamshurin
Copy link
Author

Yes, I have this option set.

@alex-shamshurin
Copy link
Author

I disabled that option and :Prettitier works fine now, even without patching the file with let l:async = 0. But I was confused because this config works fine on Mac and on Linux. I think on windows it should ignore g:prettier#exec_cmd_async=1 or somehow need repair async mode as @boojinks suggested.

@mitermayer
Copy link
Member

@alex-shamshurin I have just done a release for version 0.0.14 with that fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants