This commit is contained in:
Sandeep Somavarapu 2024-05-14 15:15:38 +02:00 committed by GitHub
parent b2e6cd0212
commit bdddba5a82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 56 additions and 13 deletions

View file

@ -79,7 +79,13 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS
return this._whenExtensionsReady;
}
async scanExtensions(language?: string, profileLocation?: URI, extensionDevelopmentLocations?: URI[], languagePackId?: string): Promise<IExtensionDescription[]> {
async scanExtensions(
language?: string,
profileLocation?: URI,
workspaceExtensionLocations?: URI[],
extensionDevelopmentLocations?: URI[],
languagePackId?: string
): Promise<IExtensionDescription[]> {
performance.mark('code/server/willScanExtensions');
this._logService.trace(`Scanning extensions using UI language: ${language}`);
@ -88,7 +94,7 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS
const extensionDevelopmentPaths = extensionDevelopmentLocations ? extensionDevelopmentLocations.filter(url => url.scheme === Schemas.file).map(url => url.fsPath) : undefined;
profileLocation = profileLocation ?? this._userDataProfilesService.defaultProfile.extensionsResource;
const extensions = await this._scanExtensions(profileLocation, language ?? platform.language, extensionDevelopmentPaths, languagePackId);
const extensions = await this._scanExtensions(profileLocation, language ?? platform.language, workspaceExtensionLocations, extensionDevelopmentPaths, languagePackId);
this._logService.trace('Scanned Extensions', extensions);
this._massageWhenConditions(extensions);
@ -117,16 +123,17 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS
return extension;
}
private async _scanExtensions(profileLocation: URI, language: string, extensionDevelopmentPath: string[] | undefined, languagePackId: string | undefined): Promise<IExtensionDescription[]> {
private async _scanExtensions(profileLocation: URI, language: string, workspaceInstalledExtensionLocations: URI[] | undefined, extensionDevelopmentPath: string[] | undefined, languagePackId: string | undefined): Promise<IExtensionDescription[]> {
await this._ensureLanguagePackIsInstalled(language, languagePackId);
const [builtinExtensions, installedExtensions, developedExtensions] = await Promise.all([
const [builtinExtensions, installedExtensions, workspaceInstalledExtensions, developedExtensions] = await Promise.all([
this._scanBuiltinExtensions(language),
this._scanInstalledExtensions(profileLocation, language),
this._scanWorkspaceInstalledExtensions(language, workspaceInstalledExtensionLocations),
this._scanDevelopedExtensions(language, extensionDevelopmentPath)
]);
return dedupExtensions(builtinExtensions, installedExtensions, developedExtensions, this._logService);
return dedupExtensions(builtinExtensions, [...installedExtensions, ...workspaceInstalledExtensions], developedExtensions, this._logService);
}
private async _scanDevelopedExtensions(language: string, extensionDevelopmentPaths?: string[]): Promise<IExtensionDescription[]> {
@ -138,6 +145,19 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS
return [];
}
private async _scanWorkspaceInstalledExtensions(language: string, workspaceInstalledExtensions?: URI[]): Promise<IExtensionDescription[]> {
const result: IExtensionDescription[] = [];
if (workspaceInstalledExtensions?.length) {
const scannedExtensions = await Promise.all(workspaceInstalledExtensions.map(location => this._extensionsScannerService.scanExistingExtension(location, ExtensionType.User, { language })));
for (const scannedExtension of scannedExtensions) {
if (scannedExtension) {
result.push(toExtensionDescription(scannedExtension, false));
}
}
}
return result;
}
private async _scanBuiltinExtensions(language: string): Promise<IExtensionDescription[]> {
const scannedExtensions = await this._extensionsScannerService.scanSystemExtensions({ language, useCache: true });
return scannedExtensions.map(e => toExtensionDescription(e, false));
@ -319,9 +339,16 @@ export class RemoteExtensionsScannerChannel implements IServerChannel {
case 'scanExtensions': {
const language = args[0];
const profileLocation = args[1] ? URI.revive(uriTransformer.transformIncoming(args[1])) : undefined;
const extensionDevelopmentPath = Array.isArray(args[2]) ? args[2].map(u => URI.revive(uriTransformer.transformIncoming(u))) : undefined;
const languagePackId: string | undefined = args[3];
const extensions = await this.service.scanExtensions(language, profileLocation, extensionDevelopmentPath, languagePackId);
const workspaceExtensionLocations = Array.isArray(args[2]) ? args[2].map(u => URI.revive(uriTransformer.transformIncoming(u))) : undefined;
const extensionDevelopmentPath = Array.isArray(args[3]) ? args[3].map(u => URI.revive(uriTransformer.transformIncoming(u))) : undefined;
const languagePackId: string | undefined = args[4];
const extensions = await this.service.scanExtensions(
language,
profileLocation,
workspaceExtensionLocations,
extensionDevelopmentPath,
languagePackId
);
return extensions.map(extension => transformOutgoingURIs(extension, uriTransformer));
}
case 'scanSingleExtension': {

View file

@ -68,6 +68,7 @@ export interface IWorkbenchExtensionManagementService extends IProfileAwareExten
onDidEnableExtensions: Event<IExtension[]>;
getExtensions(locations: URI[]): Promise<IResourceExtension[]>;
getInstalledWorkspaceExtensionLocations(): URI[];
getInstalledWorkspaceExtensions(includeInvalid: boolean): Promise<ILocalExtension[]>;
canInstall(extension: IGalleryExtension | IResourceExtension): Promise<boolean>;

View file

@ -448,6 +448,10 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
return result;
}
getInstalledWorkspaceExtensionLocations(): URI[] {
return this.workspaceExtensionManagementService.getInstalledWorkspaceExtensionsLocations();
}
async getInstalledWorkspaceExtensions(includeInvalid: boolean): Promise<ILocalExtension[]> {
return this.workspaceExtensionManagementService.getInstalled(includeInvalid);
}
@ -837,7 +841,7 @@ class WorkspaceExtensionsManagementService extends Disposable {
}
private async initialize(): Promise<void> {
const existingLocations = this.getWorkspaceExtensionsLocations();
const existingLocations = this.getInstalledWorkspaceExtensionsLocations();
if (!existingLocations.length) {
return;
}
@ -943,7 +947,7 @@ class WorkspaceExtensionsManagementService extends Disposable {
}>('workspaceextension:uninstall');
}
private getWorkspaceExtensionsLocations(): URI[] {
getInstalledWorkspaceExtensionsLocations(): URI[] {
const locations: URI[] = [];
try {
const parsed = JSON.parse(this.storageService.get(WorkspaceExtensionsManagementService.WORKSPACE_EXTENSIONS_KEY, StorageScope.WORKSPACE, '[]'));

View file

@ -19,6 +19,7 @@ import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/c
import { getErrorMessage } from 'vs/base/common/errors';
import { IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
export class CachedExtensionScanner {
@ -32,6 +33,7 @@ export class CachedExtensionScanner {
@IExtensionsScannerService private readonly _extensionsScannerService: IExtensionsScannerService,
@IUserDataProfileService private readonly _userDataProfileService: IUserDataProfileService,
@IWorkbenchExtensionManagementService private readonly _extensionManagementService: IWorkbenchExtensionManagementService,
@IWorkbenchEnvironmentService private readonly _environmentService: IWorkbenchEnvironmentService,
@ILogService private readonly _logService: ILogService,
) {
this.scannedExtensions = new Promise<IExtensionDescription[]>((resolve, reject) => {
@ -60,7 +62,7 @@ export class CachedExtensionScanner {
const result = await Promise.allSettled([
this._extensionsScannerService.scanSystemExtensions({ language, useCache: true, checkControlFile: true }),
this._extensionsScannerService.scanUserExtensions({ language, profileLocation: this._userDataProfileService.currentProfile.extensionsResource, useCache: true }),
this._extensionManagementService.getInstalledWorkspaceExtensions(false)
this._environmentService.remoteAuthority ? [] : this._extensionManagementService.getInstalledWorkspaceExtensions(false)
]);
let scannedSystemExtensions: IScannedExtension[] = [],

View file

@ -15,6 +15,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import { ILogService } from 'vs/platform/log/common/log';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IActiveLanguagePackService } from 'vs/workbench/services/localization/common/locale';
import { IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
class RemoteExtensionsScannerService implements IRemoteExtensionsScannerService {
@ -25,8 +26,9 @@ class RemoteExtensionsScannerService implements IRemoteExtensionsScannerService
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
@IRemoteUserDataProfilesService private readonly remoteUserDataProfilesService: IRemoteUserDataProfilesService,
@IActiveLanguagePackService private readonly activeLanguagePackService: IActiveLanguagePackService,
@IWorkbenchExtensionManagementService private readonly extensionManagementService: IWorkbenchExtensionManagementService,
@ILogService private readonly logService: ILogService,
@IActiveLanguagePackService private readonly activeLanguagePackService: IActiveLanguagePackService
) { }
whenExtensionsReady(): Promise<void> {
@ -42,7 +44,13 @@ class RemoteExtensionsScannerService implements IRemoteExtensionsScannerService
return await this.withChannel(
async (channel) => {
const profileLocation = this.userDataProfileService.currentProfile.isDefault ? undefined : (await this.remoteUserDataProfilesService.getRemoteProfile(this.userDataProfileService.currentProfile)).extensionsResource;
const scannedExtensions = await channel.call<IRelaxedExtensionDescription[]>('scanExtensions', [platform.language, profileLocation, this.environmentService.extensionDevelopmentLocationURI, languagePack]);
const scannedExtensions = await channel.call<IRelaxedExtensionDescription[]>('scanExtensions', [
platform.language,
profileLocation,
this.extensionManagementService.getInstalledWorkspaceExtensionLocations(),
this.environmentService.extensionDevelopmentLocationURI,
languagePack
]);
scannedExtensions.forEach((extension) => {
extension.extensionLocation = URI.revive(extension.extensionLocation);
});

View file

@ -2193,6 +2193,7 @@ export class TestWorkbenchExtensionManagementService implements IWorkbenchExtens
toggleAppliationScope(): Promise<ILocalExtension> { throw new Error('Not Supported'); }
installExtensionsFromProfile(): Promise<ILocalExtension[]> { throw new Error('Not Supported'); }
whenProfileChanged(from: IUserDataProfile, to: IUserDataProfile): Promise<void> { throw new Error('Not Supported'); }
getInstalledWorkspaceExtensionLocations(): URI[] { throw new Error('Method not implemented.'); }
getInstalledWorkspaceExtensions(): Promise<ILocalExtension[]> { throw new Error('Method not implemented.'); }
installResourceExtension(): Promise<ILocalExtension> { throw new Error('Method not implemented.'); }
getExtensions(): Promise<IResourceExtension[]> { throw new Error('Method not implemented.'); }