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

Language Detection based only on the second file causes inconvenience in certain workflows #783

Open
zzh1996 opened this issue Nov 15, 2024 · 0 comments

Comments

@zzh1996
Copy link

zzh1996 commented Nov 15, 2024

Description

Currently, Difftastic relies on the second file to determine the programming language for the diff (Language Detection feature). However, in various use cases, this behavior can be inconvenient, especially when the second file contents are piped dynamically or don't have an associated file extension. Here’s a typical example of such a scenario:

$ difft 1.c <(pbpaste)

In the above case, since the second file comes from pbpaste (through process substitution), the language detection doesn't recognize it as C code, even though both files contain the same content. This causes the diff to fallback to a plain text comparison, completely bypassing the syntax tree-based diff.

For example, when comparing the same content between 1.c (a C file) and a file 2 with no extension, the language detection leads to inconsistent behavior depending on the order of the files:

$ difft 1.c 2
2 --- Text
No changes.

$ difft 2 1.c
1.c --- C
No changes.

The same occurs with arbitrary file names or content piped dynamically.

Steps to Reproduce

  1. Create a C file (1.c) with any C code content.
  2. Compare it with another file (2) that contains the same content but lacks an extension, or compare it with dynamic input, i.e., via process substitution (<(pbpaste)).

Expected behavior: The language should be inferred from the file having a recognizable extension.

Additional Information

$ difft --version
Difftastic 0.61.0
Toolchain: 1.82.0
System:    macos aarch64
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

1 participant