We have just released version 0.8.6 of SemanticDiff - our Visual Studio Code extension and GitHub App. This update adds support for generating programming language aware diffs for Java. Other notable improvements include more options to expand context lines and support for more invariances.
If you are using the GitHub App, all updates have already been rolled out and no action is required on your part. VS Code users will usually receive the update automatically when the editor checks for extension updates. If not, you can get the latest packages from the Visual Studio Marketplace:
The most significant change in SemanticDiff 0.8.6 is that it can now generate programming language aware diffs for Java. What this means in practice is that you can reformat your Java code and SemanticDiff should display an empty diff as it ignores style-only changes. This is especially useful if your files also contain other modifications that would be easily missed in a standard diff amidst all the format changes.
If you haven’t used SemanticDiff yet, here is a screenshot of a toy example to demonstrate what this looks like:
On the right side a new parameter has been added, while the existing ones have been split into multiple lines. SemanticDiff highlights only the newly added parameter and indicates that the old line is mapped to multiple lines in the new code.
This toy example shows only a subset of the supported features. The full list of invariances (i.e. changes that are not displayed in the diff) include:
- Adding/Removing whitespaces or line breaks outside of strings and comments
- Adding/Removing optional commas
- Adding/Removing unnecessary parenthesis
- Exchanging numeric literals with equivalent ones in different bases
- Exchanging escaped characters in a string/char with an equivalent representation (e.g. the literal)
As with any other supported language, SemanticDiff can also detect and highlight moved code blocks in Java:
Expand Context Lines
By default SemanticDiff mimics git’s behavior and only shows 3 lines of context around changes. So far you had two options if you wanted to view more of the surrounding code: You could either move your cursor near a hunk header and click the “Show More” button to expand 20 lines, or you could click on a scope (function/class/struct name, etc.) in the hunk header to fully expand it.
This release gives you another option that is useful if you want to expand larger areas in a diff. There is a new button in the middle of the hunk header that expands all the code substituted by that header. So if you click the button in the last hunk header, it will add all the remaining code till the end of the document. All previous buttons expand the code between the current hunk and the previous hunk (or the beginning of the document).
If you are using the Visual Studio Code extension, you can now also expand all context by selecting the “Expand Context Lines” button from the action menu.
If you want to collapse the context lines again, you can select the “Collapse Context Lines” menu item.
SemanticDiff hides changes that don’t affect program execution to help you focus on the relevant changes. This release continues that idea and adds another invariance: SemanticDiff can now compare integers independently of their base. This means that the diff algorithm knows that
128 are the same numbers.
For example, SemanticDiff 0.8.6 treats the following two Python snippets as identical and does not display any changes:
result = 0x157 + 1_2_6 * 0b1011_0001 + 0o644
result = 343 + 0x7E * 0o261 + 0b1101_00100
This release also introduces two minor changes:
SemanticDiff can now be used in a restricted VS Code workspace. We do not believe that our extension poses any danger when used with untrusted code. The code is not evaluated nor can it have any other adverse effects on your system.
We fixed a bug in the comment handling code that could cause changes in comments to be displayed incorrectly.
We hope you enjoyed this update. If you encounter any issues, please let us know in our issue tracker.