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

Config Files of the individual formatters not detected? #35

Open
chrisgrieser opened this issue Mar 30, 2023 · 4 comments
Open

Config Files of the individual formatters not detected? #35

chrisgrieser opened this issue Mar 30, 2023 · 4 comments

Comments

@chrisgrieser
Copy link

Thanks for this small nifty tool.

I was wondering how exactly one can use config files for the specific formatters? For example with stylua.

I runcbfmt as cbfmt --config "$some_path". The specified cbfmt.toml is correctly recognized, since adding / removing lua does make a difference. However, I cannot figure out how to make cbfmt make stylua use a config file.

I have a stylua.toml in the same directory as the cbfmt.toml, and also in the nvim-pwd when executting the formatting command (via null-ls). However, cbfmt-run-stylua does not seem to recognize it since it seems to run on default config.

my config example

[languages]
lua = ["stylua --search-parent-directories -"]

I mean, I could explicitly run add a --config to the cbfmt.toml, but that would be really cumbersome.

@lukas-reineke
Copy link
Owner

I have a stylua.toml in the same directory as the cbfmt.toml

The stylua command will be executed from where you run cbfmt. You want to have the config file in that directory. Where cbfmt.toml is does not matter.

and also in the nvim-pwd when executting the formatting command

I assume that is the directory you run cbfmt from? In that case, it should just work. I tested it again now to be sure, and stylua recognizes the config correctly when it is in the same directory I run cbfmt from. (or in a parent directory with -s)

via null-ls

It should not make a difference, but to eliminate as many variables as possible, can you try to just run cbfmt directly?

@chrisgrieser
Copy link
Author

chrisgrieser commented Mar 31, 2023

yeah, so I tried running cbfmt with the command that null-ls does:

# pwd contains the stylua.toml file
cat ./lua/funcs/test.md | cbfmt --stdin-filepath ./lua/funcs/test.md --best-effort --config ../linter-configs/cbfmt.toml

and the output is correctly formatted, stylua used my config file.


When I then run cbfmt from via null-ls, the config file gets ignored. I checked that the pwd in nvim is the same as when I had when in the terminal.

My null-ls config for cbfmt, which should result in the same result as the bash command above:

null_ls.builtins.formatting.cbfmt.with {
	extra_args = { "--config", "/Users/chrisgrieser/.config/linter-configs/cbfmt.toml" },
},

So maybe this is somehow null-ls related? But the thing, the cbfmt file is recognized – otherwise cbfmt would not run.

when I explicitly name a config file, it does work though:

# does not recognize stylua config
[languages]
lua = ["stylua --search-parent-directories -"]

# recognizes stylua config
[languages]
lua = ["stylua --config-path=/Users/chrisgrieser/.config/linter-configs/stylua.toml -"]

@lukas-reineke
Copy link
Owner

Yeah sounds like it's an issue with null-ls. Maybe null-ls runs it in the wrong directory?

I'd open an issue over there

@chrisgrieser
Copy link
Author

chrisgrieser commented Apr 1, 2023

okay. weird thing is, that every other formatter works fine in recognizing the respective config files 🤔

But I guess in that case I'll open an issue with null-ls

I'd have asked whether you could take a look at the respective file from null-ls defining the configs, but I noticed that you added it, so I assume there is no issue there 😅

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

No branches or pull requests

2 participants