Skip to content

Commit

Permalink
Prompt only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jan 18, 2018
1 parent 6a26447 commit c65e758
Showing 1 changed file with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ interface IExtensionsContent {

const empty: { [key: string]: any; } = Object.create(null);
const milliSecondsInADay = 1000 * 60 * 60 * 24;
const choiceOk = localize('ok', "OK");
const choiceNever = localize('neverShowAgain', "Don't show again");
const choiceClose = localize('close', "Close");

Expand Down Expand Up @@ -267,8 +266,6 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
private _suggest(model: ITextModel): void {
const uri = model.uri;
let hasSuggestion = false;
let mimeTypes = guessMimeTypes(uri.fsPath);
let fileExtension = paths.extname(uri.fsPath);

if (!uri || uri.scheme !== Schemas.file) {
return;
Expand Down Expand Up @@ -387,24 +384,46 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
(importantTipsPromise || TPromise.as(null)).then(() => {
const fileExtensionSuggestionIgnoreList = <string[]>JSON.parse(this.storageService.get
('extensionsAssistant/fileExtensionsSuggestionIgnore', StorageScope.GLOBAL, '[]'));
let mimeTypes = guessMimeTypes(uri.fsPath);
let fileExtension = paths.extname(uri.fsPath);
if (fileExtension) {
fileExtension = fileExtension.substr(1); // Strip the dot
}

if (hasSuggestion ||
!fileExtension ||
mimeTypes.length !== 1 ||
mimeTypes[0] !== MIME_UNKNOWN ||
fileExtensionSuggestionIgnoreList.indexOf(fileExtension) > -1
) {
return;
}

if (!hasSuggestion &&
fileExtension &&
fileExtensionSuggestionIgnoreList.indexOf(fileExtension) === -1 &&
mimeTypes.length === 1 &&
mimeTypes[0] === MIME_UNKNOWN) {
const keywords = this.getKeywordsForExtension(fileExtension);
this._galleryService.query({ text: `tag:"__ext_${fileExtension}" ${keywords.map(tag => `tag:"${tag}"`)}` }).then(pager => {
if (!pager || !pager.firstPage || !pager.firstPage.length) {
return;
}

let message = localize('showLanguageExtensions', "Search Marketplace Extensions for '{0}'...", fileExtension);
// Suggest the search only once as this is not a strong recommendation
fileExtensionSuggestionIgnoreList.push(fileExtension);
this.storageService.store(
'extensionsAssistant/fileExtensionsSuggestionIgnore',
JSON.stringify(fileExtensionSuggestionIgnoreList),
StorageScope.GLOBAL
);


const message = localize('showLanguageExtensions', "The Marketplace has extensions that can help with '.{0}' files", fileExtension);

const searchMarketplaceAction = this.instantiationService.createInstance(ShowLanguageExtensionsAction, fileExtension);

const options = [
choiceOk,
choiceNever,
localize('searchMarketplace', "Search Marketplace"),
choiceClose
];

this.choiceService.choose(Severity.Info, message, options, 2).done(choice => {
this.choiceService.choose(Severity.Info, message, options, 1).done(choice => {
switch (choice) {
case 0:
/* __GDPR__
Expand All @@ -417,21 +436,6 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
searchMarketplaceAction.run();
break;
case 1:
fileExtensionSuggestionIgnoreList.push(fileExtension);
this.storageService.store(
'extensionsAssistant/fileExtensionsSuggestionIgnore',
JSON.stringify(fileExtensionSuggestionIgnoreList),
StorageScope.GLOBAL
);
/* __GDPR__
"fileExtensionSuggestion:popup" : {
"userReaction" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"extensionId": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('fileExtensionSuggestion:popup', { userReaction: 'neverShowAgain', fileExtension: fileExtension });
break;
case 2:
/* __GDPR__
"fileExtensionSuggestion:popup" : {
"userReaction" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
Expand All @@ -450,7 +454,7 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
*/
this.telemetryService.publicLog('fileExtensionSuggestion:popup', { userReaction: 'cancelled', fileExtension: fileExtension });
});
}
});
});
});
}
Expand Down

0 comments on commit c65e758

Please sign in to comment.