Theia plugin API vs. VS Code extension API

While Theia supports the VS Code extension API (most of it), the Theia plugin API introduces some minor differences. As an example, the plugin functions are “start” and “stop”, while it is “activate” and “deactivate” in VS Code.
As another example, “vscode.commands.registerCommand” expects only an ID, and the command is registered via the package.json, while “theia.commands.registerCommand” expects id and label.

In general you could argue that it is fine that the Theia plugin API is different to VS Code, it could e.g. support more features.
In turn, you could argue that those minor differences just add additional confusion and effort, if they do not provide specific additional value or feature.

If I need to decide as a plugin developer, which API to target, the VS Code extension API has the advantage, that I can target VS Code and Theia, while if I target the Theia extension API, I loose this advantage.

Has there ever been a disucssion arround this, specifically about the question whether the Theia plugin API shall be compatible with the VS Code extension API or not?

[original thread by Jonas Helming]

In general you could argue that it is fine that the Theia plugin API is different to VS Code, it could e.g. support more features.
In turn, you could argue that those minor differences just add additional confusion and effort, if they do not provide specific additional value or feature.

If there are some differences we should eliminate them, please file an issue for command registration.

Theia plugin API should be strict superset of VS Code API.

I was thinking for some time about another approach which allows to run an extension in VS Code and at the same time use extended capabilities without diverging from VS Code API at all:

  • Build VS Code extension

  • if in your Theia product context you need extended APIs:

  • then implement a Theia extension registering commands for such APIs

  • implement npm package based on @types/vscode which expose some entry point like acquireMyCustomApi which returns undefined if commands are not registered or API object if they are present

  • in VS Code extension you call this method if it returns undefined then you are running not in your product context

Such approach does not require theia plugin API anymore, any custom namespaces, allows to statically type check in which context you run.

Something like that:

import vscode from 'vscode';
import acquireMyApi from 'my-api';
const myApi = acquireMyApi();
if (myApi) {
   // my product context, here can call custom commands via myApi and use vscode namespace
} else {
   // we are in VS Code, only vscode namespace is allowed  
}

[Jonas Helming]

[Jonas Helming]

For anybody, who is interested, the discussion on this topic was continue in the above mentioned bug report