[clang] [clang-format] Fix working -assume-filename with .clang-format-ignore (PR #113100)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 23 02:27:52 PDT 2024


mydeveloperday wrote:

> > Also, the main purpose of -assume-filename is to set the language for input from stdin, and IMO the pseudo filename should not be filtered out by any .clang-format-ignore file.
> 
> It is also worth noting that if the `-style=file` option is specified, it will look for `.clang-format`/`_clang-format` file in the same or parent directory based on the pathname specified by the `-assume-filename` option.
> 
> Since the specification is such for `.clang-format`/`_clang-format` file, users would naturally expect the same behavior for `.clang-format-ignore` file, wouldn't they?

I'm a little confused..

So it seems you are saying... that an IDE that is using clang-format, formats the contents of the editor using stdin  to clang-format, sort of like

```
echo "editor_buffer" | clang-format 
```
and because it knows editor_buffer came from c:/project/myproject/src/lib/myfile.cxx  its passing

```
echo "editor_buffer" | clang-format --assume-filename c:/project/myproject/src/lib/myfile.cxx
```

I presume in both case the IDE reads the output and puts it back in the editor rather than writing it to the file incase the user isn't ready to save just yet.

which means if you are running with --stage=file its using that assume-filename to get the directory of that assume-file and then look up that tree for a .clang-format

```
echo "buffer" | clang-format --style=file --assume-filename c:/project/myproject/src/lib/myfile.cxx
```

However what you are saying is, its not using that assume-filename to locate the .clang-format-ignore file? which if it had might have seen that myfile.* should have been ignored.

Hence in the IDE it reformats myfile.* meaning you can't save it unformatted

Did I understand that correctly? (its likely exactly what you said...)





https://github.com/llvm/llvm-project/pull/113100


More information about the cfe-commits mailing list