Theia可以通过多种不同的方式进行扩展。命令允许packages提供可以被其它包调用的唯一命令,还可以向这些命令添加快捷键和上下文,使得它们只能在某些特定的条件下被调用(如窗口获取焦点、当前选项等)。
在Theia中添加命令要将命令添加到Theia,必须实现CommandContribution类,如:
java-commands.ts
@injectable() export class JavaCommandContribution implements CommandContribution { ... registerCommands(commands: CommandRegistry): void { commands.registerCommand(SHOW_JAVA_REFERENCES, { execute: (uri: string, position: Position, locations: Location[]) => commands.executeCommand(SHOW_REFERENCES.id, uri, position, locations) }); commands.registerCommand(APPLY_WORKSPACE_EDIT, { execute: (changes: WorkspaceEdit) => !!this.workspace.applyEdit && this.workspace.applyEdit(changes) }); } }