Skip to content

Commit

Permalink
use content pattern instead of remotes (#177186)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Mar 15, 2023
1 parent 4566ce4 commit 4b8edee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/vs/base/common/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export interface IConfigBasedExtensionTip {
configScheme?: string;
recommendations: IStringDictionary<{
name: string;
remotes?: string[];
contentPattern?: string;
important?: boolean;
isExtensionPack?: boolean;
whenNotInstalled?: string[];
Expand Down
32 changes: 9 additions & 23 deletions src/vs/platform/extensionManagement/common/extensionTipsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigBasedExtensionTip as IRawConfigBasedExtensionTip } from 'vs/base/common/product';
import { joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { getDomainsOfRemotes } from 'vs/platform/extensionManagement/common/configRemotes';
import { IConfigBasedExtensionTip, IExecutableBasedExtensionTip, IExtensionManagementService, IExtensionTipsService, ILocalExtension } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IFileService } from 'vs/platform/files/common/files';
import { IProductService } from 'vs/platform/product/common/productService';
Expand Down Expand Up @@ -62,21 +61,15 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
continue;
}
try {
const content = await this.fileService.readFile(joinPath(folder, configPath));
const recommendationByRemote: Map<string, IConfigBasedExtensionTip> = new Map<string, IConfigBasedExtensionTip>();
Object.entries(tip.recommendations).forEach(([key, value]) => {
if (isNonEmptyArray(value.remotes)) {
for (const remote of value.remotes) {
recommendationByRemote.set(remote, {
extensionId: key,
extensionName: value.name,
configName: tip.configName,
important: !!value.important,
isExtensionPack: !!value.isExtensionPack,
whenNotInstalled: value.whenNotInstalled
});
}
} else {
let content: string | undefined;
const getContent = async () => {
if (content === undefined) {
content = (await this.fileService.readFile(joinPath(folder, configPath))).value.toString();
}
return content;
};
for (const [key, value] of Object.entries(tip.recommendations)) {
if (!value.contentPattern || new RegExp(value.contentPattern, 'mig').test(await getContent())) {
result.push({
extensionId: key,
extensionName: value.name,
Expand All @@ -86,13 +79,6 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
whenNotInstalled: value.whenNotInstalled
});
}
});
const domains = getDomainsOfRemotes(content.value.toString(), [...recommendationByRemote.keys()]);
for (const domain of domains) {
const remote = recommendationByRemote.get(domain);
if (remote) {
result.push(remote);
}
}
} catch (error) { /* Ignore */ }
}
Expand Down

0 comments on commit 4b8edee

Please sign in to comment.