1

Since file comparison can be executed from vscode using at least a couple of ways that I am aware of:

  1. code --diff file1 file2
  2. command palette: "File: Compare Active File With..."

I was wondering if there could be an api for comparing two files that I could use in an extension? I couldn't find it in the official page though. Maybe it's in the works/plans already?

Andrei
  • 175
  • 1
  • 9

1 Answers1

4

You can open a diff view programmatically by invoking the "vscode.diff" command with two vscode.Uri instances:

vscode.commands.executeCommand("vscode.diff", uri1, uri2)

There's also optional title and options arguments, see the docs on built-in commands for more info.

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • 1
    I'd also like to add that the uri1, and uri2 are of type vscode.Uri. like: let url1 = vscode.Uri.file("path-to-your-file"); – Andrei Aug 03 '20 at 16:52
  • true! I'd just give a quick example how to create a uri from path. To me that wasn't immediately obvious, I am a noob! :) – Andrei Aug 03 '20 at 17:28