1

I am issuing this command in my extension:

export async function diffCompare(original: string, current: string) {
  await vscode.commands.executeCommand("vscode.diff", vscode.Uri.file(original), vscode.Uri.file(current));
  return;
}

however I am finding that it pops up the side by side display of the original file and the current file just fine but it is not waiting for the diff to be closed before proceeding.
I call the function with this:

  await diffCompare(originalFile, developmentFile);
  const dj = "x";

I admit that I must be doing something wrong but cannot see what that might be. It is dropping immediately into the breakpoint I have set.

Any pointers as to what I am doing wrong would be appreciated.

Mark
  • 143,421
  • 24
  • 428
  • 436
djacks
  • 63
  • 9
  • you have to monitor the close of the diff tab, a quick look at the API does not provide an `onDidxxxxx` that could be used to monitor tab close. – rioV8 Dec 09 '20 at 21:13
  • Does NOT provide...? – djacks Dec 09 '20 at 21:30
  • for Webview you have an `OnDidClose` event, I can't find one for close of Tab – rioV8 Dec 09 '20 at 21:33
  • 1
    would assume that there must be a means of not progressing till the DIFF is marked as complete. In VSCode Command line DIFF there seems to be a parm - WAIT but I can find no mention of it for use in an Extension. – djacks Dec 09 '20 at 21:57
  • 1
    if it is not in the API yet and you can make an argument why it could be useful you can make a feature request – rioV8 Dec 09 '20 at 22:49
  • I assume the diff editor, once opened, is treated like any other editor so there is no special `onDidCloseDiffEditor`. For monitoring the close of an editor tab, see the documentation for `onDidCloseTextDocument` which directs you to use `onDidChangeVisibleTextEditors` which you will have to scan through to see if the diff editor is no longer visible. – Mark Dec 09 '20 at 22:56
  • Not exactly clear what you're doing since I've never used diff but can you use an regular delay? https://stackoverflow.com/questions/37764665/typescript-sleep – boocs Dec 11 '20 at 20:50
  • I need the user to complete his diff editing and to only then return control to the application. There is a WAIT option on the diff command but it is not implemented for use within an extension. – djacks Dec 12 '20 at 21:53
  • If you can't find a solution a workaround would be to create a status bar item when you create a diff. The text could read Click Here to Confirm Diff Edit or something like that. When you click it it can run any command you've created. – boocs Dec 13 '20 at 06:48
  • My diff is invoked via a right click option on a tree item. However it is followed by some other function that requires the diff to have been completed. Unfortunately there is no ability to wait on the diff so it immediately drops into the follow on function giving the user no chance to complete the diff... – djacks Dec 14 '20 at 13:48
  • That's what I meant you could remove that function and have the user click the StatusBarItem to confirm the diff edit and then run the function. Alternative: You might be able to use vscode.workspace.createFileSystemWatcher() as well to watch the file but you may need to turn off auto save. – boocs Dec 16 '20 at 16:29

0 Answers0