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

Allowing for user to choose default text parsing #439

Closed
mparada opened this issue Dec 7, 2022 · 1 comment
Closed

Allowing for user to choose default text parsing #439

mparada opened this issue Dec 7, 2022 · 1 comment

Comments

@mparada
Copy link

mparada commented Dec 7, 2022

Sometimes difftastic will parse a file incorrectly either due to an error in the parser, an error in the file itself or a complicated situation not yet handled by the parsers (e.g. helm templates, which are kind-of yaml files with embedded go-template, see #267 and #377). In those cases it would be helpful if the user could force difftastic to use the default text parsing instead of showing "No syntatic changes."

I envision something like: difft --language default or difft --default-parser

I'm willing to make a PR but I don't know rust and don't know where should I start 🙈

(1) One idea would be to treat the default text parser the same as the other parsers. I would add a default language in the languages enum and then instead of matching to None we would match to this default. For example here:

But that would change the design choice of using None to fallback to text parsing. Another alternative to this idea would be to re-design the whole line_parser to fit the vendor parsers format. I have absolutely no idea how I would do that 😅

(2) Another idea would be adding a --default-parser flag and then ignore language_override. For example here:

let language = language_override.or_else(|| guess(guess_path, guess_src));

would become something like:

let language = if default_parser {
  None;
} else {
  language_override.or_else(|| guess(path, &src));
}

The important point here is side-stepping the guess function.

I tend to prefer Option (2) because it seems less intrusive to me, but it still adds another top level flag which could maybe be covered by an already existing flag. I'll try to implement that one but am very welcome to feedback, specially if I'm tackling this issue completely wrong!

mparada pushed a commit to mparada/difftastic that referenced this issue Dec 7, 2022
The flag `--default-parser` forces the use of the default and fallback
line_parser.

Fixes Wilfred#439
@muescha
Copy link

muescha commented Dec 14, 2022

mhh - i would it named as --language text and listed in the available languages as text

i see there is also a "grammar" for plain text (https://github.com/rspencer01/tree-sitter-text) - I don't know if this makes sense to add it as a language

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 a pull request may close this issue.

2 participants