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

Syntax highlight in the diff output #32

Closed
vlsi opened this issue Sep 6, 2021 · 9 comments
Closed

Syntax highlight in the diff output #32

vlsi opened this issue Sep 6, 2021 · 9 comments
Labels

Comments

@vlsi
Copy link

vlsi commented Sep 6, 2021

It would be nice if there was syntax highlighting in the diff output, so the code structure is easier to understand.

Sample PL/SQL diff:

git version 2.33.0
diff with git 2.33

difftastic 0.8
diff with difftastic 0.8

delta 0.8.3
diff with delta 0.8.3


PL/SQL diff where the diff is within string literals (the indentation at line 256 looks odd, and I did not notice it before I took the screenshots).
The code is "PL/SQL code generator written in PL/SQL", and I do not expect that PL/SQL code within string literals to be highlighted as PL/SQL :) However, it would be nice if string literals were highlighted differently from the regular code.

git version 2.33.0
git version 2.33.0

difftastic 0.8
difftastic 0.8

delta 0.8.3
delta 0.8.3


Re "string literals vs code" there's a semi-standard extension from IntelliJ: https://www.jetbrains.com/help/idea/using-language-injections.html#use-language-injection-comments

For instance, the following bit in Groovy code (Jenkins Job DSL code) is highlighted as XML in IntelliJ IDEA:

// $/ ... /$ is a multi-line string in Groovy
//  language=xml comment triggers "inject XML into the following literal" in IDEA
+ echo('> config/config.xml', /* language=xml */ $/
<root>
  <profile>
    <datasources>
    </datasources>
  </profile>
</root>
/$) +
@Wilfred
Copy link
Owner

Wilfred commented Sep 7, 2021

Yeah, I think syntax highlighting would be very worthwhile. It's not something I plan to work on until I've got the diffing logic solid, so it's not a high priority for me.

For your specific example, I'm afraid difftastic doesn't support .sql files. There isn't an mature tree-sitter parser for SQL that I'm aware of.

Wilfred added a commit that referenced this issue Oct 3, 2021
@robinmoussu
Copy link

I would also love to get more syntax highlight. The minimal version that you did (dimmed comments and bold keywords) is already great. Thanks a lot for the hard work.

@vlsi
Copy link
Author

vlsi commented Oct 19, 2021

I've upgraded to 0.11.0, and I like word-level diffs:
word-level highlighting in diff

Wilfred added a commit that referenced this issue Jan 23, 2022
Wilfred added a commit that referenced this issue Jan 23, 2022
Wilfred pushed a commit that referenced this issue Apr 17, 2022
Wilfred pushed a commit that referenced this issue Jul 11, 2022
@Wilfred
Copy link
Owner

Wilfred commented Jul 11, 2022

See also #311.

Wilfred pushed a commit that referenced this issue Jul 11, 2022
@nh2
Copy link

nh2 commented Oct 25, 2022

I do not understand whether the commit that closed this issue should fix the following:

I inserted 2 lines into a Nix multi-line string, and difftastic shows the whole string as changed, making it difficult to see which lines are actually changed in git diff:

difftastic:

image

delta:

image

This is on Difftastic 0.34.0, which has commit a5de97a in -- should it look different?

@Wilfred
Copy link
Owner

Wilfred commented Oct 28, 2022

@nh2 currently difftastic treats strings atomically, even when they're big multiline literals. See #178, it would be nice to do something better.

vquelque pushed a commit to vquelque/difftastic that referenced this issue Apr 5, 2023
grunweg pushed a commit to grunweg/difftastic that referenced this issue May 5, 2023
…s/actions/checkout-3

Bump actions/checkout from 2 to 3
Wilfred pushed a commit that referenced this issue Aug 9, 2023
Mark the rule '_if_null_expression' explicitly as inline
@nh2
Copy link

nh2 commented Oct 24, 2023

I inserted 2 lines into a Nix multi-line string

@Wilfred Should #409 (comment) help with this?

E.g. would one need to write code similar to the one added in 9133918 ?

@Wilfred
Copy link
Owner

Wilfred commented Oct 28, 2023

@nh2 I don't think sublanguages help here. In a generic string literal, there's no way for difftastic to know what the language in the string is.

Better handling of multiline comments/string is what will really help here I think.

@nh2
Copy link

nh2 commented Oct 28, 2023

@Wilfred It's shell script in ~95% of the cases. There are also some hints, e.g. the variable name that the string is assigned to.

Separate question though: VSCode auto-detects languages based on heuristics; if it looks like shell or Python, it guesses it. Such thing would certainly help here. Does difftastic have a such functionality one could turn on / do the libraries it uses provide such features?

Wilfred pushed a commit to Thecentury/difftastic that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants