rhysd / vim-clang-format

Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, and so on.
http://clang.llvm.org/docs/ClangFormat.html
1.08k stars 123 forks source link

Error on Windows #14

Open kbenzie opened 10 years ago

kbenzie commented 10 years ago

I've been using this plugin on linux happily for months, thanks. However I'm sometimes required to do development on Windows at work.

I have clang-format on my path but am getting the following error message in Windows gvim 7.4.

screenshot from 2014-10-27 16 52 44

I tried installing Shougo/vimproc.vim as advised in the documentation but got the same error.

Any idea what would be causing this issue?

rhysd commented 10 years ago

Hi, thank you for your report.

clang-format command's failure raises the error. Could you confirm that clang-format command can format the C++ code properly in your command line? And please tell me the version of clang-format.

Unfortunately, I don't have Windows environment. I can't do debug by my hands.

kbenzie commented 10 years ago

Hi,

I can confirm that calling clang-format from the command line works as expected. The version is a snapshot from llvm.org

clang-format version 3.6.0 (218712)

I have the following setting in my .vimrc

let g:clang_format#code_style='google'

My intuition is that vim-clang-format was unable to find clang-format on the path for some reason. Is there some way to provide this path as a vim setting?

rhysd commented 10 years ago

Hi. Thank you for your information.

Is there some way to provide this path as a vim setting?

g:clang_format#command is available. Please try it.

let g:clang_format#command = "path/to/your-clang-format"
rhysd commented 9 years ago

I'll close this issue because of no response. If anyone encounters this issue, please reopen this issue.

jonvaldes commented 9 years ago

Hi rhysd, I'm afraid I have the same problem. Windows7, Vim7.4, plugin freshly cloned from github and installed by manually copying files to vimfiles dir.

The error I get is a little different, though:

Error detected while processing function clang_format#replace..<SNR>77_error_message:
line    1:
clang-format has failed to format

I have tried setting the clang_format#command variable as you suggested, and then I get a different error:

Error detected while processing function clang_format#replace..clang_format#format..<SNR>77_system:
line    8:
E484: Can't open file C:\Users\juanval\AppData\Local\Temp\VIo8430.tmp

Any ideas? Thanks!

rhysd commented 9 years ago

@jonvaldes

Thank you for your report. The error seems to occur here where vim-clang-format executes clang-format command. And :help E484 says that it is an error when Vim can't read a temporary file at calling system(). In Windows, some additional special character must be escaped. So it seems to be the reason that vim-clang-format doesn't escape them in Windows. :help E848 also says using shellescape() may resolve the issue. I'll make new branch and use shellescape() in it.

rhysd commented 9 years ago

@jonvaldes

I tried to fix this issue in fix/issues/14 branch. Could you try it? I can't test it on my side because I don't have Windows PC.

jonvaldes commented 9 years ago

@rhysd Just tried it, but I get the same issue. However, if I move clang-format to c:\ or I make sure it's in the path, I still get the original error:

Error detected while processing function clang_format#replace..<SNR>78_error_message:
line    1:
clang-format has failed to format.

So I guess that wouldn't be because of weird characters...

rhysd commented 9 years ago

@jonvaldes

Thank you for your try. It seems that command should also be escaped. I implemented it in b175afa.

Error detected while processing function clang_format#replace..78_error_message: line 1: clang-format has failed to format.

This error message derives from the failure of executing clang-format command. So, to determine it is an issue of vim-clang-format side or clang-format side, it is needed to execute the same command in cmd.exe manually and check the result.

jonvaldes commented 9 years ago

@rhysd I've tried that commit, but I still get the same error :( I need to go back to work on my own stuff, so for the moment I've resorted to a crappy .bat file. That'll work for the moment.

If you try any more possible fixes for this issue, I'll gladly check them out and see if they work for me.

glacjay commented 9 years ago

When I format my code using :12verbose ClangFormat, I got these:

...
调用 shell 执行: "D:/tool/LLVM/bin/clang-format.exe  -lines=1:48 -style='{BasedOnStyle: mozilla, IndentWidth: 4, UseTab: false}'  -- <D:\temp\VIiDCBA.tmp >D:\temp\VIoDCBB.tmp 2>&1"
...
function clang_format#replace..clang_format#format 返回 'error: -offset, -length and -lines can only be used for single file.'
...

And my LLVM version is 3.6.1.

Commander14 commented 9 years ago

Has anyone ever successfully gotten vim-clang-format to work on Windows with gvim? I have the same temp file issue and none of the suggestions here fix it.

zzhiyi commented 9 years ago

I encountered this problem just after an Vundle PluginUpdate, so I think the problem is in those plugins. There is a dependency call vimproc. After an update, the builded dll(Check for vimproc_win64.dll or vimproc_win32.dll in $VIM/bundle/vimproc.vim/autoload/) for Windows is lost. Thus after you updated the plugin or you just fresh installed vimproc you need to build the vimproc dll. You can build it by cd into vimproc.vim folder and exec "./tools/update-dll-mingw.bat". The building require mingw32 installed(Check vimproc building instructions). After building the required dll, the problem solved.

salva-b commented 7 years ago

Hi, I think I've got the same issue trying to run vim-clang-format into gvim 8.0 with vimproc already installed:

Error detected while processing function clang_format#replace[2]..<SNR>89_verify_command:
line    3:
clang-format has failed to format
SimplyKnownAsG commented 7 years ago

I actually don't run into this problem with projects that have a .clang-format. So, I opened vim with vim -V9details.log thread.cpp in a place without .clang-format and tried :w a bunch of times and got this info:

Calling shell to execute: "^"clang-format^"  -lines=1:26 -style='{BasedOnStyle: google, IndentWidth: 4, UseTab: false, }' -assume-filename=^"thread.cpp^"  -- <C:\Users\g\temp\VIiE2CC.tmp >C:\Users\g\temp\VIoE2CD.tmp 2>&1"
Error detected while processing function clang_format#replace[18]..<SNR>42_error_message:
line    1:

To me it looks like style=' should be using double quotes for windows. I ran the command outside:

C:\Users\g\temp>copy thread.cpp threadin.cpp
        1 file(s) copied.

C:\Users\g\temp>^"clang-format^"  -lines=1:26 -style='{BasedOnStyle: google, IndentWidth: 4, UseTab: false, }' -assume-filename=^"thread.cpp^"  -- < threadin.cpp > threadout.cpp
error: -offset, -length and -lines can only be used for single file.

modifying to use double quotes:

C:\Users\g\temp>"clang-format"  -lines=1:26 -style="{BasedOnStyle: google, IndentWidth: 4, UseTab: false, }" -assume-filename=^"thread.cpp^"  -- < threadin.cpp > threadout.cpp
:: no error
SimplyKnownAsG commented 6 years ago

I believe this is no longer an issue, and can be closed due to cc9b5d8f

sonicXconst1 commented 4 years ago

Hello! I've got the same error in neovim (both nvim and nvim-qt). Win10, vimproc installed and compiled. I use ":ClangFormat" to run clang-format (10.0.0)

image

vimrc file doesn't customise the clang-format style settings. .clang-format craeted by --dump-config.