【Hacker News搬运】Difftastic, a structural diff tool that understands syntax
-
Title: Difftastic, a structural diff tool that understands syntax
Difftastic,一个理解语法的结构差异工具
Text:
Url: https://difftastic.wilfred.me.uk/
Difftastic 是一个结构化的差异工具,它能够理解语法。该工具通过比较文件的语法结构,而不是逐行对比,来生成更准确的差异结果,使得人类更容易阅读。Difftastic 使用 tree-sitter 解析代码,与逐行的文本差异工具不同,它能理解内部表达式没有发生变化的情况。它还可以忽略格式化变化,如代码格式化工具将某物分成了多行,Difftastic 能够显示实际发生变化的内容。此外,它能够可视化包裹变化,例如添加了包裹器,Difftastic 能够精确匹配分隔符,即使内部内容发生变化,它仍然可以显示额外的包裹器。Difftastic 还显示实际的行号,使用户能够了解变化发生在哪些行。Difftastic 是完全开源的,采用 MIT 许可证,用户可以下载、修改并与朋友分享。该工具由 Wilfred Hughes 使用 Emacs 和咖啡制作。
Post by: jiripospisil
Comments:
kstrauser: For those who don't already know, this is built on tree-sitter (<a href="https://tree-sitter.github.io/tree-sitter/" rel="nofollow">https://tree-sitter.github.io/tree-sitter/</a>) which does for parsing what LSP does for analysis. That is, it provides a standard interface for turning code into an AST and then making that AST available to clients like editors and diff tools. Instead of a neat tool like this having to support dozens of languages, it can just support tree-sitter and automatically work with anything that tree-sitter supports. And if you're developing a new language, you can create a tree-sitter parser for it, and now every tool that speaks tree-sitter knows how to support your language.<p>Those 2 <i>massive</i> innovations are leading to an explosion of tooling improvements like this. Now every editor, diff tool, or whatever can support dozens or hundreds of languages without having to duplicate all the work of every other similar tool. That's freaking amazing.
kstrauser: 对于那些没有;我还不知道,这是建立在树保姆(<a href=“https://;/;树保姆.github.io/,树保姆/”rel=“nofollow”>https://;#xx2F;tree-sitter.github.io/;树保姆ȏ;</a>)之上的,用于解析LSP的分析功能。也就是说,它提供了一个标准接口,用于将代码转换为AST,然后使该AST可用于编辑器和diff工具等客户端。不像这样一个整洁的工具必须支持几十种语言,它可以只支持树保姆,并自动处理树保姆支持的任何东西。如果你;在重新开发一种新语言时,您可以为它创建一个树保姆解析器,现在每个使用树保姆的工具都知道如何支持您的语言<p> 这些2<i>大规模</i>创新正在导致像这样的工具改进爆炸式增长。现在,每个编辑器、diff工具或其他任何工具都可以支持数十或数百种语言,而不必复制其他类似工具的所有工作。那个;It’太神奇了。
bloopernova: Related, updating difftastic and friends if you installed via cargo:<p><pre><code> cargo install cargo-update
cargo install-update --list
cargo install-update --all
</code></pre>
Other fun Rust projects available via cargo:<p><a href="https://mise.jdx.dev/" rel="nofollow">https://mise.jdx.dev/</a> mise-en-place, a drop-in replacement for asdf <a href="https://asdf-vm.com/" rel="nofollow">https://asdf-vm.com/</a> that is really fast and flexible.<p><a href="https://github.com/ajeetdsouza/zoxide">https://github.com/ajeetdsouza/zoxide</a> is a fantastic cd replacement, which stores where you cd to, and you can then do a partial match like "z hel" might take you to "~/projects/helloworld".<p><a href="https://github.com/bootandy/dust">https://github.com/bootandy/dust</a> is a compliment to "du", shows which directories are using the most disk space.bloopernova: 相关,更新difftastic和朋友如果你通过货物安装:<p><pre><code>货物安装货物更新货物安装更新--列表货物安装更新--全部</code></pre>其他有趣的Rust项目可通过cargo获得:<p><a href=“https://;/;mise.jdx.dev/”rel=“nofollow”>https:///;mise.jdx.dev</a> mise到位,是asdf的一个替代品<a href=“https://;/;asdf vm.com/”rel=“nofollow”>https:///;asdf vm.com/</a> 这是非常快速和灵活的<p> <a href=“https://;/;github.com/:ajeetdsouza/!zoxide”>https:///;github.com/;ajeetdouza/;zoxide</a>是一个非常棒的cd替换,它将cd存储到哪里,然后您可以进行部分匹配,如";z hel”;可能会带你去“~/;项目;你好世界”<p> <a href=“https://;/;github.com/:bootandy/!dust”>https:///;github.com/;bootandy/;灰尘</a>是对“灰尘”的赞美;du”;,显示哪些目录使用了最多的磁盘空间。
mlavrent: I’m almost not sure why tools like git don’t ship with this as default. Been using difft for about a year now, and my main complaint is that it makes it hard to go back and use other diff tools when I don’t have difft available :).<p>I am curious if there’s been any work on semantic diff tools as well (for when eg the syntax changes but the meaning is the same). It seems like an intractable problem in the general but maybe it’s doable and/or useful for smaller DSLs or subsets of some languages?
mlavrent: 我几乎不知道为什么像git这样的工具没有将其作为默认值。我已经使用difft大约一年了,我的主要抱怨是,当我没有difft时,很难回去使用其他diff工具:)<p> 我很好奇是否也有关于_semantic_diff工具的工作(例如,当语法发生变化但含义相同时)。一般来说,这似乎是一个棘手的问题,但也许它是可行的;或者对较小的DSL或某些语言的子集有用?
gexla: Thanks for this. I'll give it a try. And for diffs in a different context, I really like Beyond Compare.
gexla: 谢谢你。I-;I’我试试看。对于不同背景下的差异,我真的很喜欢Beyond Compare。
domenkozar: In devenv.sh:<p><pre><code> difftastic.enable = true;</code></pre>
domenkozar: 在devenv.sh中:<p><pre><code>difftastic.enable=true</代码></pre>