Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed May 31, 2023
1 parent a8ef81e commit 9ef31ac
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,24 @@ export class FileBasedRecommendations extends ExtensionRecommendations {
this._register(disposableTimeout(() => this.promptRecommendations(uri, model), 0));
}

private promptRecommendations(uri: URI, model: ITextModel): void {
if (this.promptImportantRecommendations(uri, model)) {
return;
}

this.promptRecommendedExtensionForFileExtension(uri, extname(uri).toLowerCase());
}

/**
* Prompt the user to either install the recommended extension for the file type in the current editor model
* or prompt to search the marketplace if it has extensions that can support the file type
*/
private promptRecommendations(uri: URI, model: ITextModel, extensionRecommendations?: IStringDictionary<IFileOpenCondition[]>): void {
private promptImportantRecommendations(uri: URI, model: ITextModel, extensionRecommendations?: IStringDictionary<IFileOpenCondition[]>): boolean {
const pattern = extname(uri).toLowerCase();
extensionRecommendations = extensionRecommendations ?? this.recommendationsByPattern.get(pattern) ?? this.fileOpenRecommendations;
const extensionRecommendationEntries = Object.entries(extensionRecommendations);
if (extensionRecommendationEntries.length === 0) {
return;
return false;
}

const processedPathGlobs = new Map<string, boolean>();
Expand Down Expand Up @@ -246,10 +254,6 @@ export class FileBasedRecommendations extends ExtensionRecommendations {
}
}

if (Object.keys(matchedRecommendations).length) {
this.promptFromRecommendations(uri, model, matchedRecommendations);
}

this.recommendationsByPattern.set(pattern, recommendationsByPattern);
if (Object.keys(unmatchedRecommendations).length) {
if (listenOnLanguageChange) {
Expand All @@ -258,14 +262,21 @@ export class FileBasedRecommendations extends ExtensionRecommendations {
// re-schedule this bit of the operation to be off the critical path - in case glob-match is slow
disposables.add(disposableTimeout(() => {
if (!disposables.isDisposed) {
this.promptRecommendations(uri, model, unmatchedRecommendations);
this.promptImportantRecommendations(uri, model, unmatchedRecommendations);
disposables.dispose();
}
}, 0));
}));
disposables.add(model.onWillDispose(() => disposables.dispose()));
}
}

if (Object.keys(matchedRecommendations).length) {
this.promptFromRecommendations(uri, model, matchedRecommendations);
return true;
}

return false;
}

private promptFromRecommendations(uri: URI, model: ITextModel, extensionRecommendations: IStringDictionary<IFileOpenCondition[]>): void {
Expand Down Expand Up @@ -304,8 +315,6 @@ export class FileBasedRecommendations extends ExtensionRecommendations {
this.promptRecommendedExtensionForFileType(languageName && isImportantRecommendationForLanguage && language !== PLAINTEXT_LANGUAGE_ID ? localize('languageName', "{0} language", languageName) : basename(uri), language, [...importantRecommendations])) {
return;
}

this.promptRecommendedExtensionForFileExtension(uri, extname(uri).toLowerCase());
}

private promptRecommendedExtensionForFileType(name: string, language: string, recommendations: string[]): boolean {
Expand Down

0 comments on commit 9ef31ac

Please sign in to comment.