Skip to content

Improved config path resolution#18

Open
ricardobeat wants to merge 3 commits into
lmichaudel:mainfrom
ricardobeat:rtomasi/config-resolution
Open

Improved config path resolution#18
ricardobeat wants to merge 3 commits into
lmichaudel:mainfrom
ricardobeat:rtomasi/config-resolution

Conversation

@ricardobeat
Copy link
Copy Markdown

@ricardobeat ricardobeat commented May 25, 2026

I noticed that when formatting a single file, the .c3fmt config is not picked up from a parent directory:

.c3fmt
  src/
    config.c3
c3fmt src/config.c3 # formats with .c3fmt config
cd src
c3fmt config.c3  # formats with default config

The same happens when opening a standalone .c3 file in an editor (Zed in my case) and formatting via --stdin.

This PR fixes that by:

  • walking up the directory tree to find a .c3fmt file
  • adding --stdin-filepath to provide the file path to the formatter along --stdin

Incidentally this allows having a global config at $HOME/.c3fmt - which I find quite useful as my preference deviates from the defaults.

Example Zed config:

"languages": {
    "C3": {
      "formatter": {
        "external": {
          "command": "c3fmt",
          "arguments": ["--stdin", "--stdin-filepath", "{buffer_path}"],
        },
      },
    }

@ManuLinares
Copy link
Copy Markdown
Contributor

Hi, I don't think this is handled correctly here, I think is better if you open an issue.

@lmichaudel
Copy link
Copy Markdown
Owner

What is wrong in your opinion @ManuLinares ?

I didn't know popular formatters had this features, but it seems to be pretty common (clang-format does it apparently).

I don't really like the idea of a --stdin-filepath flag, kinda counter-intuitive. Maybe you can instead set the working directory for c3fmt to the file directory inside your Zed configuration ?

@ricardobeat
Copy link
Copy Markdown
Author

ricardobeat commented May 26, 2026

@lmichaudel this approach is used by Prettier and mentioned in the Zed documentation: https://zed.dev/docs/reference/all-settings#formatter

The other option is to provide formatting via the LSP server, slightly slower but also doable. I'm trying to improve the editor experience in small steps :)

If you prefer I can separate this change from the path resolution, which is useful in its own right.

@lmichaudel
Copy link
Copy Markdown
Owner

Ok I buy it 👍

I will still wait for @ManuLinares opinion before merging that though.

@ManuLinares
Copy link
Copy Markdown
Contributor

adding "--stdin-filepath" is fine, no I was referring at the code itself, it's bad, that's why I was proposing ricardo to make an issue instead and lucas (or somebody else) can implement it correctly. 👍️

@ricardobeat ricardobeat force-pushed the rtomasi/config-resolution branch from 9dedd0a to 0a6697e Compare May 28, 2026 23:56
@ricardobeat
Copy link
Copy Markdown
Author

@ManuLinares thanks for the candor! I'm new to the language and trying to speed-run it with AI. I've refactored the code to use the stdlib, simplify the loop, match the existing style, and removed unnecessary comments.

Hope this is better, otherwise feel free to close and I'll open an issue instead.

@ManuLinares
Copy link
Copy Markdown
Contributor

Seems fine now but haven't properly tested it.

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

Successfully merging this pull request may close these issues.

3 participants