dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

parameter g:ale_c_clangformat_options doesn't work on Windows #4525

Open retzzz opened 1 year ago

retzzz commented 1 year ago

Information

VIM version

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Dec 19 2022 23:29:50) MS-Windows 64-bit GUI version with OLE support

Win10 64-bit

What went wrong

I follow ALE document to set parameter:

let g:ale_c_clangformat_style_option = '{BasedOnStyle: Microsoft, ColumnLimit:80,}'

But clang-format doesn't work. The help information of clang-format is as below:

  --style=<string>               - Set coding style. <string> can be:
                                   1. A preset: LLVM, GNU, Google, Chromium, Microsoft,
                                      Mozilla, WebKit.
                                   2. 'file' to load style configuration from a
                                      .clang-format file in one of the parent directories
                                      of the source file (for stdin, see --assume-filename).
                                      If no .clang-format file is found, falls back to
                                      --fallback-style.
                                      --style=file is the default.
                                   3. 'file:<format_file_path>' to explicitly specify
                                      the configuration file.
                                   4. "{key: value, ...}" to set specific parameters, e.g.:
                                      --style="{BasedOnStyle: llvm, IndentWidth: 8}"

Please note the item 4 is using double quotes. I tried to update line 25 of file ale\autoload\ale\fixers\clangformat.vim from:

        let l:style_option = '-style=' . "'" . l:style_option . "'"

to

        let l:style_option = '-style=' . '"' . l:style_option . '"'

then clang-format is working. So I guess this is a bug.

Reproducing the bug

  1. I did this.
  2. Then this happened.

:ALEInfo

Expand let g:ale_c_clangformat_executable = 'clang-format' let g:ale_c_clangformat_options = '' let g:ale_c_clangformat_style_option = '{BasedOnStyle: Microsoft, ColumnLimit:80,}' let g:ale_c_clangformat_use_global = 0 let g:ale_c_clangformat_use_local_file = 0 ... (finished - exit code 1) 'cmd /s/c "clang-format --assume-filename=arch_init.c -style=''{BasedOnStyle: Microsoft, ColumnLimit:80,}'' < C:\Users\e323819\AppData\Local\Temp\VBVB444.tmp\arch_init.c"'
w0rp commented 1 year ago

The bug is specific to Windows. The argument needs to be escaped with ale#Escape. instead of surrounded with single quotes.