Is there a way where I can get all the functions for registered services/contributions with scope public like a library in extensions.
For example, to create new file, let’s say
@inject
private readonly library: TheiaExtensionLibrary;
somefunction () {
this.library.fileService.createNewFile('/path/to/file');
}
Ideally, I would want this to happen by injecting one dependency which just keeps track of all installed extension and their public API’s.
[original thread by Karthik Bhat K]
Not out of the box, you could create such class if you want. Why do you want it? API discoverability?
[Karthik Bhat K]
This is already achieved in executeCommand of command-module
node_modules/@theia/core/src/common/command.ts
this.commands // will give me all the command, and
this.commandRegistry.executeCommand(commandId, ...commandOptions); // will execute the command based on the command Id
However, commands work only for Ctrl + Shift + P
available commands. I want to be able to execute all the public function of each class.
You can create a js proxy around an instance of Container doing such things.
But i don’t know why someone would want to use such dynamic object, there won’t be any content assist and type checking at compile time.
[Karthik Bhat K]
Well that’s because if an external app wants to communicate with self hosted theia ide to send instructions it is required. That’s the use case I have.
I don’t think it is going to work for everything, only for services serving pure JSON objects. Usually we will build a statically typed facade with cleanly defined protocol.