vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Rich command detection extension API

Open Tyriar opened this issue 9 months ago • 0 comments

Reliability has been a problem for the shellIntegration.executeCommand API, this is because shell integration isn't a switch but a spectrum. Here are some examples we may encounter:

a. The shell has built-in general shell integration and reports 133;A, 133;B, 133;C and 133;D

  • This means we know the positions of everything, but cannot reliably get the command line b. The shell has partial shell integration (due to lack of hooks) and reports 633;A, 633;B and 633;D
  • This means we don't know when the command is executed, but we do know where the command and output is c. The shell has full vscode shell integration and reports 633;A, 633;B, 633;C, 633;E and 633;D (in that order)
  • This means we would not know the command line when it's executed, but do when the execution end event fires d. The shell has full vscode shell integration and reports 633;A, 633;B, 633;E, 633;C and 633;D (in that order)
  • This is ideal

The change https://github.com/microsoft/vscode/pull/242894 adds a new sequence which allows the shell integration script to declare ahead of time whether the command detection sequences will appear in an exact order and in particular have the 633 E sequence appear before the 633 C one. This is required because we cannot verify this before a command executes, but we must know in order for an extension to decide whether they want to actually use executeCommand or not.

We have 2 ways forward here:

  1. Only enable .shellIntegration when rich command line reporting is enabled. This would mean that extensions cannot interact with any of the examples above except for d.
  2. Provide a new flag somewhere that indicates whether it supports rich command detection. This would mean extensions can decide whether they want to only support rich (and reliable) command detection terminals and use a different approach if not.

Tyriar avatar Mar 07 '25 14:03 Tyriar