Injection of existing services into plug-ins

Using yo @theia/plugin, I have generated a template for theia plugin. My main ts file in the src folder contains the start() and stop() functions; However, I’m confused as to how I can inject Theia’s services such as SelectionService and use them inside the start() function since it is not a class. I want to execute a command only if files with certain extensions are selected (i.e. something along the lines of commands.registerCommand(command, new FileSelection.CommandHandler(selectionService, {execute: selection => someFunction(selection)}). The problem though is that selectionService has to be injected, and I’m not sure how to do it.

Hi Eugene,

the short answer is: you cannot. There is an explanation of extension vs. plugin in Theia here: https://theia-ide.org/docs/authoring_plugins/

/Thomas

1 Like