MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.77k stars 259 forks source link

What version of clang-format is used / can I use the system clang-format? #930

Open MarcelRobitaille opened 1 year ago

MarcelRobitaille commented 1 year ago

Observed behavior

I want to use the setting SpacesInLineCommentPrefix in my .clang-format file. I can see that it's only available as of clang 13. This setting works flawlessly if I run clang-format from the command line. However, when I press ff, which I have bound in vim to lua vim.lsp.buf.format(), nothing happens when this setting is enabled. Not just this setting for comments isn't applied, but the formatting isn't working at all, even for things that used to work like indentation. If I take this setting out of .clang-format and press ff, everything else is working.

It's like clang-format is erroring out, but nothing is printed in Vim. I checked :messages and I don't see anything in the LSP log file even with my log level set to debug (vim.lsp.set_log_level("debug")).

I saw in #910 that ccls uses the LLVM clang-format. However, I don't have /usr/lib/llvm-14/bin/clang-format on my computer. I don't know how to figure out which clang-format it's trying to use. When I do which clang-format, I get /usr/bin/clang-format. Is there any way to get it to use that clang-format? I don't have any of CMAKE_PREFIX_PATH, LLVM_INCLUDE_DIR, LLVM_BUILD_INCLUDE_DIR why I try to echo them in my terminal.

Expected behavior

The setting SpacesInLineCommentPrefix in .clang-format should not break formatting. There should be some way to setting ccls to use a different clang-format binary. There should be some error message when formatting fails.

Steps to reproduce

  1. Put this in .clang-format:
    SpacesInLineCommentPrefix:
      Minimum: 1
      Maximum: 1
  2. Trigger LSP formatting

System information

MarcelRobitaille commented 1 year ago

BTW do you accept donations?

findNextStep commented 1 year ago

ccls complie with libclang in your computer, it may be not in /usr/lib/llvm-14/bin/clang-format. it depend on where ccls complie https://github.com/MaskRay/ccls/blob/master/src/messages/textDocument_formatting.cc here is source code abort how ccls work with clang-format. if you get ccls from apt source, it depend on apt source

metablaster commented 6 months ago

The option SpacesInLineCommentPrefix works only for single line comments and does not work if comments span multiple lines regardless if // style or /**/ style is used.

In addition the option ReflowComments must be set to true

Expected behavior is for this option to work on any amount of lines of comments.