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

The argument --fallback-style={...} for clangd is not working with coc-clangd #362

Open
matevskial opened this issue May 3, 2020 · 11 comments
Labels
config Needs better configurability

Comments

@matevskial
Copy link

Problem

I want to set up a fallback formatter for clangd with the concrete argument --fallback-style={--fallback-style="{BasedOnStyle: LLVM, IndentWidth: 4}"} in file coc-settings.json so the formatted code has indentation width of 4, but then the coc command in nvim :Format still indents the code with indetntation width of 2.

This is the coc-settings.json config file:

{
  "clangd.path":"clangd-9",
  "clangd.arguments":["--fallback-style=\"{BasedOnStyle: LLVM, IndentWidth: 4}\""]
}

Expected behaviour

The coc command in nvim :Format should format the code with indent width 4

Current behaviour

The formatted code is with indent width 2

Screenshot_20200503_133847

@sam-mccall
Copy link
Member

Huh, I was certain that clang-format's --fallback-style was parsed the same way as --style, but it seems --fallback-style must be a predefined style (and clangd follows clang-format here).

We could diverge from clang-format, or change clang-format to allow this too.

@sam-mccall
Copy link
Member

(This is a clangd bug/feature)

@sam-mccall sam-mccall transferred this issue from clangd/coc-clangd May 3, 2020
@sam-mccall sam-mccall added the config Needs better configurability label Jun 15, 2020
@sam-mccall
Copy link
Member

We'll almost certainly address this when we add config files, allowing something like:

Format:
  FallbackStyle:
    BasedOnStyle: LLVM
    IndentWidth: 4

to be placed in a dotfile. It's unlikely we'll fix this in the command-line flag, as we'll likely deprecate that in favor of user config files.

@1m188
Copy link

1m188 commented Aug 7, 2020

when write some personal small files like algorithm practice and so on, it is cumbersome to configure .clang-format every time, may be it's greater to support both config file and command-line flag?

@thebeastxdxd
Copy link

i agree i think you should still support the command line flags, config files (with 1 line) in every project is very cumbersome.

@arminveres
Copy link

Did something change here or is there a solution to this? I'm using native lsp of nvim and the issue seemingly still persists.

@chrinkis
Copy link

chrinkis commented May 2, 2022

At the moment, is there any way to change the (default) format settings, in order to be applied when the .clang-format file is missing?

@GZGavinZhao
Copy link

GZGavinZhao commented May 28, 2022

My current solution is to add a file at $HOME/.clang-format. clangd/clang-format will traverse upwards the filesystem to find the closest .clang-format file, so if you don't have a .clang-format file all the way from your current directory to your $HOME directory, the $HOME/.clang-format file will be picked up and used by clangd/clang-format.

For example:

# ~/.clang-format
---
BasedOnStyle: Microsoft
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left

And my file at ~/CS/Practice/main.cpp becomes:

#include <iostream>

using namespace std;

int N, D;

int main()
{
    int* a;
    cin >> N >> D;
}

For Linux/Windows users, you can put the file at /.clang-format or C:\.clang-format (with sudo). I'm on Mac and it has this whatever system integrity thing that I don't want to break, so I just put it at my home directory.

@tae-soo-kim
Copy link

Why not add the --style option in clang-format to clangd?

@FalcoGer
Copy link

FalcoGer commented Jun 26, 2023

It would be nice if there could be a command line flag for clangd to load the format configuration file from a specified path instead of putting in a string in the command line. All my projects have the same format, and putting a format file into every one, even little test projects that live for less than a day is cumbersome. I would much rather like a fall back format file, such as the $HOME/.config/clangd/config.yaml file, define where the fallback format file lives in that config file, or provide a command line argument on where that file lives.
Having yet another dotfile in my overbloated home directory that consists of 95% dotfiles is not desirable.

@HighCommander4
Copy link

It would be nice if there could be a command line flag for clangd to load the format configuration file from a specified path instead of putting in a string in the command line.

We have #805 open for this.

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

No branches or pull requests

10 participants