| 112 | |
| 113 | @singleton() |
| 114 | export class ExtensionService implements IExtensionService { |
| 115 | private extensions: IExtension[] = []; |
| 116 | private readonly colorThemeService: IColorThemeService; |
| 117 | private readonly monacoService: IMonacoService; |
| 118 | private _inactive: Function | undefined; |
| 119 | private readonly localeService: ILocaleService; |
| 120 | /** |
| 121 | * TODO: This property is used for marking the extensions were loaded |
| 122 | * we are going to refactor this logic after redesign the Molecule lifecycle. |
| 123 | */ |
| 124 | private _isLoaded: boolean = false; |
| 125 | |
| 126 | constructor() { |
| 127 | this.colorThemeService = container.resolve(ColorThemeService); |
| 128 | this.monacoService = container.resolve(MonacoService); |
| 129 | this.localeService = container.resolve(LocaleService); |
| 130 | } |
| 131 | |
| 132 | public setLoaded(flag?: boolean): void { |
| 133 | this._isLoaded = flag !== undefined ? flag : true; |
| 134 | } |
| 135 | |
| 136 | public isLoaded(): boolean { |
| 137 | return this._isLoaded; |
| 138 | } |
| 139 | |
| 140 | public getExtension(id: UniqueId): IExtension | undefined { |
| 141 | return this.extensions.find(searchById(id)); |
| 142 | } |
| 143 | |
| 144 | public reset(): void { |
| 145 | this.extensions = []; |
| 146 | } |
| 147 | |
| 148 | public getAllExtensions(): IExtension[] { |
| 149 | return this.extensions.concat(); |
| 150 | } |
| 151 | |
| 152 | public add(extensions: IExtension[]): IExtension[] | null { |
| 153 | if (!extensions || extensions?.length === 0) return null; |
| 154 | /** |
| 155 | * Filtered the exist Extensions |
| 156 | */ |
| 157 | const unloadExtensions = extensions.filter((ext) => { |
| 158 | const isExist = this.extensions.find(searchById(ext.id)); |
| 159 | if (isExist) { |
| 160 | logger.warn( |
| 161 | 'Warning: Unable to load the existed Extension:' + ext.id |
| 162 | ); |
| 163 | } |
| 164 | return !isExist; |
| 165 | }); |
| 166 | if (unloadExtensions.length > 0) { |
| 167 | this.extensions = this.extensions.concat(unloadExtensions); |
| 168 | } |
| 169 | return unloadExtensions; |
| 170 | } |
| 171 |
nothing calls this directly
no outgoing calls
no test coverage detected