Skip to content

Commit

Permalink
Adding default fileicon support to language contributions. Fixes #14662
Browse files Browse the repository at this point in the history
  • Loading branch information
Mai-Lapyst committed Mar 12, 2021
1 parent 809e111 commit 4e4246a
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 157 deletions.
16 changes: 15 additions & 1 deletion src/vs/editor/common/services/languagesRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IResolvedLanguage {
extensions: string[];
filenames: string[];
configurationFiles: URI[];
icons: string[];
}

export class LanguagesRegistry extends Disposable {
Expand Down Expand Up @@ -129,7 +130,8 @@ export class LanguagesRegistry extends Disposable {
aliases: [],
extensions: [],
filenames: [],
configurationFiles: []
configurationFiles: [],
icons: []
};
this._languages[langId] = resolvedLanguage;
}
Expand Down Expand Up @@ -227,6 +229,10 @@ export class LanguagesRegistry extends Disposable {
if (lang.configuration) {
resolvedLanguage.configurationFiles.push(lang.configuration);
}

if (lang.icon) {
resolvedLanguage.icons.push(lang.icon);
}
}

public isRegisteredMode(mimetypeOrModeId: string): boolean {
Expand Down Expand Up @@ -275,6 +281,14 @@ export class LanguagesRegistry extends Disposable {
return (language.mimetypes[0] || null);
}

public getIconForMode(modeId: string): string | null {
if (!hasOwnProperty.call(this._languages, modeId)) {
return null;
}
const language = this._languages[modeId];
return (language.icons[0] || null);
}

public extractModeIds(commaSeparatedMimetypesOrCommaSeparatedIds: string | undefined): string[] {
if (!commaSeparatedMimetypesOrCommaSeparatedIds) {
return [];
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/common/services/modeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ILanguageExtensionPoint {
aliases?: string[];
mimetypes?: string[];
configuration?: URI;
icon?: string;
}

export interface ILanguageSelection extends IDisposable {
Expand All @@ -40,6 +41,7 @@ export interface IModeService {
getExtensions(alias: string): string[];
getFilenames(alias: string): string[];
getMimeForMode(modeId: string): string | null;
getIconForMode(modeId: string): string | null;
getLanguageName(modeId: string): string | null;
getModeIdForLanguageName(alias: string): string | null;
getModeIdByFilepathOrFirstLine(resource: URI, firstLine?: string): string | null;
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/common/services/modeServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export class ModeServiceImpl extends Disposable implements IModeService {
return this._registry.getMimeForMode(modeId);
}

public getIconForMode(modeId: string): string | null {
return this._registry.getIconForMode(modeId);
}

public getLanguageName(modeId: string): string | null {
return this._registry.getLanguageName(modeId);
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6498,6 +6498,7 @@ declare namespace monaco.languages {
aliases?: string[];
mimetypes?: string[];
configuration?: Uri;
icon?: string;
}
/**
* A Monarch language definition
Expand Down
12 changes: 11 additions & 1 deletion src/vs/workbench/services/mode/common/workbenchModeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IRawLanguageExtensionPoint {
aliases: string[];
mimetypes: string[];
configuration: string;
icon: string;
}

export const languagesExtPoint: IExtensionPoint<IRawLanguageExtensionPoint[]> = ExtensionsRegistry.registerExtensionPoint<IRawLanguageExtensionPoint[]>({
Expand Down Expand Up @@ -85,6 +86,10 @@ export const languagesExtPoint: IExtensionPoint<IRawLanguageExtensionPoint[]> =
description: nls.localize('vscode.extension.contributes.languages.configuration', 'A relative path to a file containing configuration options for the language.'),
type: 'string',
default: './language-configuration.json'
},
icon: {
description: nls.localize('vscode.extension.contributes.languages.icon', 'A contributed icon name to use as file icon, if no icon theme provides one for the language'),
type: 'string'
}
}
}
Expand Down Expand Up @@ -131,7 +136,8 @@ export class WorkbenchModeServiceImpl extends ModeServiceImpl {
firstLine: ext.firstLine,
aliases: ext.aliases,
mimetypes: ext.mimetypes,
configuration: configuration
configuration: configuration,
icon: ext.icon
});
}
}
Expand Down Expand Up @@ -229,6 +235,10 @@ function isValidLanguageExtensionPoint(value: IRawLanguageExtensionPoint, collec
collector.error(nls.localize('opt.mimetypes', "property `{0}` can be omitted and must be of type `string[]`", 'mimetypes'));
return false;
}
if (typeof value.icon !== 'undefined' && typeof value.icon !== 'string') {
collector.error(nls.localize('opt.icon', "property `{0}` can be omitted and must be of type `string`", 'icon'));
return false;
}
return true;
}

Expand Down
Loading

0 comments on commit 4e4246a

Please sign in to comment.