提交 e4b70bca 编写于 作者: B Benjamin Pasero

fix #69334

上级 ba066625
......@@ -12,9 +12,11 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { FileKind } from 'vs/platform/files/common/files';
export function getIconClasses(modelService: IModelService, modeService: IModeService, resource: uri | undefined, fileKind?: FileKind): string[] {
// we always set these base classes even if we do not have a path
const classes = fileKind === FileKind.ROOT_FOLDER ? ['rootfolder-icon'] : fileKind === FileKind.FOLDER ? ['folder-icon'] : ['file-icon'];
if (resource) {
// Get the path and name of the resource. For data-URIs, we need to parse specially
let name: string | undefined;
let path: string | undefined;
......@@ -22,17 +24,19 @@ export function getIconClasses(modelService: IModelService, modeService: IModeSe
const metadata = DataUri.parseMetaData(resource);
name = metadata.get(DataUri.META_DATA_LABEL);
path = name;
}
else {
} else {
name = cssEscape(basenameOrAuthority(resource).toLowerCase());
path = resource.path.toLowerCase();
}
// Folders
if (fileKind === FileKind.FOLDER) {
classes.push(`${name}-name-folder-icon`);
}
// Files
else {
// Name & Extension(s)
if (name) {
classes.push(`${name}-name-file-icon`);
......@@ -42,8 +46,9 @@ export function getIconClasses(modelService: IModelService, modeService: IModeSe
}
classes.push(`ext-file-icon`); // extra segment to increase file-ext score
}
// Configured Language
let configuredLangId: string | null = getConfiguredLangId(modelService, resource);
let configuredLangId: string | null = getConfiguredLangId(modelService, modeService, resource);
configuredLangId = configuredLangId || (path ? modeService.getModeIdByFilepathOrFirstLine(path) : null);
if (configuredLangId) {
classes.push(`${cssEscape(configuredLangId)}-lang-file-icon`);
......@@ -53,16 +58,32 @@ export function getIconClasses(modelService: IModelService, modeService: IModeSe
return classes;
}
export function getConfiguredLangId(modelService: IModelService, resource: uri): string | null {
export function getConfiguredLangId(modelService: IModelService, modeService: IModeService, resource: uri): string | null {
let configuredLangId: string | null = null;
if (resource) {
const model = modelService.getModel(resource);
if (model) {
const modeId = model.getLanguageIdentifier().language;
if (modeId && modeId !== PLAINTEXT_MODE_ID) {
configuredLangId = modeId; // only take if the mode is specific (aka no just plain text)
let modeId: string | null = null;
// Data URI: check for encoded metadata
if (resource.scheme === Schemas.data) {
const metadata = DataUri.parseMetaData(resource);
const mime = metadata.get(DataUri.META_DATA_MIME);
if (mime) {
modeId = modeService.getModeId(mime);
}
}
// Any other URI: check for model if existing
else {
const model = modelService.getModel(resource);
if (model) {
modeId = model.getLanguageIdentifier().language;
}
}
if (modeId && modeId !== PLAINTEXT_MODE_ID) {
configuredLangId = modeId; // only take if the mode is specific (aka no just plain text)
}
}
return configuredLangId;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册