Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -3,9 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import uri from 'vs/base/common/uri';
import { URI as uri } from 'vs/base/common/uri';
import * as resources from 'vs/base/common/resources';
import { IconLabel, IIconLabelValueOptions, IIconLabelCreationOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@@ -22,8 +20,8 @@ import { FileKind, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/fi
import { ITextModel } from 'vs/editor/common/model';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Event, Emitter } from 'vs/base/common/event';
import { DataUri } from 'vs/workbench/common/resources';
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
import { ILabelService } from 'vs/platform/label/common/label';
import { getIconClasses, getConfiguredLangId } from 'vs/editor/common/services/getIconClasses';
export interface IResourceLabel {
name: string;
@@ -56,7 +54,7 @@ export class ResourceLabel extends IconLabel {
@IModelService private modelService: IModelService,
@IDecorationsService protected decorationsService: IDecorationsService,
@IThemeService private themeService: IThemeService,
@IUriDisplayService protected uriDisplayService: IUriDisplayService
@ILabelService protected labelService: ILabelService
) {
super(container, options);
@@ -139,6 +137,10 @@ export class ResourceLabel extends IconLabel {
return true; // same resource but different kind (file, folder)
}
if (newResource && this.computedPathLabel !== this.labelService.getUriLabel(newResource)) {
return true;
}
if (newResource && oldResource) {
return newResource.toString() !== oldResource.toString();
}
@@ -191,7 +193,7 @@ export class ResourceLabel extends IconLabel {
iconLabelOptions.title = this.options.title;
} else if (resource && resource.scheme !== Schemas.data /* do not accidentally inline Data URIs */) {
if (!this.computedPathLabel) {
this.computedPathLabel = this.uriDisplayService.getLabel(resource);
this.computedPathLabel = this.labelService.getUriLabel(resource);
}
iconLabelOptions.title = this.computedPathLabel;
@@ -274,9 +276,9 @@ export class FileLabel extends ResourceLabel {
@IDecorationsService decorationsService: IDecorationsService,
@IThemeService themeService: IThemeService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IUriDisplayService uriDisplayService: IUriDisplayService
@ILabelService labelService: ILabelService
) {
super(container, options, extensionService, configurationService, modeService, modelService, decorationsService, themeService, uriDisplayService);
super(container, options, extensionService, configurationService, modeService, modelService, decorationsService, themeService, labelService);
}
setFile(resource: uri, options?: IFileLabelOptions): void {
@@ -298,76 +300,9 @@ export class FileLabel extends ResourceLabel {
let description: string;
const hidePath = (options && options.hidePath) || (resource.scheme === Schemas.untitled && !this.untitledEditorService.hasAssociatedFilePath(resource));
if (!hidePath) {
description = this.uriDisplayService.getLabel(resources.dirname(resource), true);
description = this.labelService.getUriLabel(resources.dirname(resource), { relative: true });
}
this.setLabel({ resource, name, description }, options);
}
}
export function getIconClasses(modelService: IModelService, modeService: IModeService, resource: uri, 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 name of the resource. For data-URIs, we need to parse specially
let name: string;
if (resource.scheme === Schemas.data) {
const metadata = DataUri.parseMetaData(resource);
name = metadata.get(DataUri.META_DATA_LABEL);
} else {
name = cssEscape(resources.basenameOrAuthority(resource).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`);
const dotSegments = name.split('.');
for (let i = 1; i < dotSegments.length; i++) {
classes.push(`${dotSegments.slice(i).join('.')}-ext-file-icon`); // add each combination of all found extensions if more than one
}
classes.push(`ext-file-icon`); // extra segment to increase file-ext score
}
// Configured Language
let configuredLangId = getConfiguredLangId(modelService, resource);
configuredLangId = configuredLangId || modeService.getModeIdByFilenameOrFirstLine(name);
if (configuredLangId) {
classes.push(`${cssEscape(configuredLangId)}-lang-file-icon`);
}
}
}
return classes;
}
function getConfiguredLangId(modelService: IModelService, resource: uri): string {
let configuredLangId: string;
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)
}
}
}
return configuredLangId;
}
function cssEscape(val: string): string {
return val.replace(/\s/g, '\\$&'); // make sure to not introduce CSS classes from files that contain whitespace
}