Merge remote-tracking branch 'origin/master' into tyriar/101_hot_exit

This commit is contained in:
Daniel Imms
2016-10-05 14:11:49 -07:00
703 changed files with 50489 additions and 61644 deletions

View File

@@ -10,7 +10,7 @@ import URI from 'vs/base/common/uri';
import {IFileService} from 'vs/platform/files/common/files';
/**
* An editor model that just represents a resource and mime for a resource that can be loaded.
* An editor model that just represents a resource that can be loaded.
*/
export class BinaryEditorModel extends EditorModel {
private name: string;

View File

@@ -6,12 +6,10 @@
import nls = require('vs/nls');
import {TPromise} from 'vs/base/common/winjs.base';
import types = require('vs/base/common/types');
import {once} from 'vs/base/common/event';
import URI from 'vs/base/common/uri';
import {getPathLabel, IWorkspaceProvider} from 'vs/base/common/labels';
import {isBinaryMime} from 'vs/base/common/mime';
import {EditorModel, IFileEditorInput, EditorInput, BaseDiffEditorInput} from 'vs/workbench/common/editor';
import {EditorModel, EditorInput, BaseDiffEditorInput, TEXT_DIFF_EDITOR_ID, BINARY_DIFF_EDITOR_ID} from 'vs/workbench/common/editor';
import {BaseTextEditorModel} from 'vs/workbench/common/editor/textEditorModel';
import {DiffEditorModel} from 'vs/workbench/common/editor/diffEditorModel';
import {TextDiffEditorModel} from 'vs/workbench/common/editor/textDiffEditorModel';
@@ -109,23 +107,7 @@ export class DiffEditorInput extends BaseDiffEditorInput {
}
public getPreferredEditorId(candidates: string[]): string {
// Find the right diff editor for the given isBinary/isText state
const useBinaryEditor = this.forceOpenAsBinary || this.isBinary(this.originalInput) || this.isBinary(this.modifiedInput);
return !useBinaryEditor ? 'workbench.editors.textDiffEditor' : 'workbench.editors.binaryResourceDiffEditor';
}
private isBinary(input: EditorInput): boolean {
let mime: string;
// Find mime by checking for IFileEditorInput implementors
const fileInput = <IFileEditorInput>(<any>input);
if (types.isFunction(fileInput.getMime)) {
mime = fileInput.getMime();
}
return mime && isBinaryMime(mime);
return this.forceOpenAsBinary ? BINARY_DIFF_EDITOR_ID : TEXT_DIFF_EDITOR_ID;
}
private createModel(refresh?: boolean): TPromise<DiffEditorModel> {

View File

@@ -5,14 +5,14 @@
'use strict';
import {TPromise} from 'vs/base/common/winjs.base';
import {MIME_TEXT} from 'vs/base/common/mime';
import {PLAINTEXT_MODE_ID} from 'vs/editor/common/modes/modesRegistry';
import {EditorModel, EditorInput} from 'vs/workbench/common/editor';
import {StringEditorModel} from 'vs/workbench/common/editor/stringEditorModel';
import URI from 'vs/base/common/uri';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
/**
* A read-only text editor input whos contents are made of the provided value and mime type.
* A read-only text editor input whos contents are made of the provided value and mode ID.
*/
export class StringEditorInput extends EditorInput {
@@ -20,17 +20,18 @@ export class StringEditorInput extends EditorInput {
protected cachedModel: StringEditorModel;
protected value: string;
private name: string;
private description: string;
protected value: string;
protected mime: string;
private modeId: string;
private singleton: boolean;
constructor(
name: string,
description: string,
value: string,
mime: string,
modeId: string,
singleton: boolean,
@IInstantiationService private instantiationService: IInstantiationService
) {
@@ -39,7 +40,7 @@ export class StringEditorInput extends EditorInput {
this.name = name;
this.description = description;
this.value = value;
this.mime = mime || MIME_TEXT;
this.modeId = modeId || PLAINTEXT_MODE_ID;
this.singleton = singleton;
}
@@ -63,10 +64,6 @@ export class StringEditorInput extends EditorInput {
return this.value;
}
public getMime(): string {
return this.mime;
}
/**
* Sets the textual value of this input and will also update the underlying model if this input is resolved.
*/
@@ -123,7 +120,7 @@ export class StringEditorInput extends EditorInput {
}
//Otherwise Create Model and Load
let model = this.instantiationService.createInstance(StringEditorModel, this.value, this.mime, this.getResource());
let model = this.instantiationService.createInstance(StringEditorModel, this.value, this.modeId, this.getResource());
return model.load().then((resolvedModel: StringEditorModel) => {
this.cachedModel = resolvedModel;
@@ -139,8 +136,8 @@ export class StringEditorInput extends EditorInput {
if (otherInput instanceof StringEditorInput) {
let otherStringEditorInput = <StringEditorInput>otherInput;
// If both inputs are singletons, check on the mime for equalness
if (otherStringEditorInput.singleton && this.singleton && otherStringEditorInput.mime === this.mime) {
// If both inputs are singletons, check on the modeId for equalness
if (otherStringEditorInput.singleton && this.singleton && otherStringEditorInput.modeId === this.modeId) {
return true;
}
@@ -153,7 +150,7 @@ export class StringEditorInput extends EditorInput {
// Otherwise compare by properties
return otherStringEditorInput.value === this.value &&
otherStringEditorInput.mime === this.mime &&
otherStringEditorInput.modeId === this.modeId &&
otherStringEditorInput.description === this.description &&
otherStringEditorInput.name === this.name;
}

View File

@@ -19,12 +19,12 @@ import {EditOperation} from 'vs/editor/common/core/editOperation';
*/
export class StringEditorModel extends BaseTextEditorModel {
protected value: string;
protected mime: string;
protected modeId: string;
protected resource: URI;
constructor(
value: string,
mime: string,
modeId: string,
resource: URI,
@IModeService modeService: IModeService,
@IModelService modelService: IModelService
@@ -32,7 +32,7 @@ export class StringEditorModel extends BaseTextEditorModel {
super(modelService, modeService);
this.value = value;
this.mime = mime;
this.modeId = modeId;
this.resource = resource;
}
@@ -99,15 +99,11 @@ export class StringEditorModel extends BaseTextEditorModel {
return null;
}
public getMime(): string {
return this.mime;
}
public load(): TPromise<EditorModel> {
// Create text editor model if not yet done
if (!this.textEditorModel) {
return this.createTextEditorModel(this.value, this.resource, this.mime);
return this.createTextEditorModel(this.value, this.resource, this.modeId);
}
// Otherwise update

View File

@@ -65,11 +65,11 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
}
/**
* Creates the text editor model with the provided value, mime (can be comma separated for multiple values) and optional resource URL.
* Creates the text editor model with the provided value, modeId (can be comma separated for multiple values) and optional resource URL.
*/
protected createTextEditorModel(value: string | IRawText, resource?: URI, mime?: string): TPromise<EditorModel> {
protected createTextEditorModel(value: string | IRawText, resource?: URI, modeId?: string): TPromise<EditorModel> {
const firstLineText = this.getFirstLineText(value);
const mode = this.getOrCreateMode(this.modeService, mime, firstLineText);
const mode = this.getOrCreateMode(this.modeService, modeId, firstLineText);
// To avoid flickering, give the mode at most 50ms to load. If the mode doesn't load in 50ms, proceed creating the model with a mode promise
return TPromise.any<any>([TPromise.timeout(50), mode]).then(() => {
@@ -125,8 +125,8 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
*
* @param firstLineText optional first line of the text buffer to set the mode on. This can be used to guess a mode from content.
*/
protected getOrCreateMode(modeService: IModeService, mime: string, firstLineText?: string): TPromise<IMode> {
return modeService.getOrCreateMode(mime);
protected getOrCreateMode(modeService: IModeService, modeId: string, firstLineText?: string): TPromise<IMode> {
return modeService.getOrCreateMode(modeId);
}
/**
@@ -156,13 +156,13 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
/**
* Updates the text editor model mode based on the settings and configuration.
*/
protected updateTextEditorModelMode(mime?: string): void {
protected updateTextEditorModelMode(modeId?: string): void {
if (!this.textEditorModel) {
return;
}
const firstLineText = this.getFirstLineText(this.textEditorModel.getValue());
const mode = this.getOrCreateMode(this.modeService, mime, firstLineText);
const mode = this.getOrCreateMode(this.modeService, modeId, firstLineText);
this.modelService.setMode(this.textEditorModel, mode);
}

View File

@@ -6,19 +6,18 @@
import {TPromise} from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import {isUnspecific, guessMimeTypes, MIME_TEXT, suggestFilename} from 'vs/base/common/mime';
import {suggestFilename} from 'vs/base/common/mime';
import labels = require('vs/base/common/labels');
import {PLAINTEXT_MODE_ID} from 'vs/editor/common/modes/modesRegistry';
import paths = require('vs/base/common/paths');
import {UntitledEditorInput as AbstractUntitledEditorInput, EncodingMode, ConfirmResult} from 'vs/workbench/common/editor';
import {UntitledEditorModel} from 'vs/workbench/common/editor/untitledEditorModel';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import Event, {Emitter} from 'vs/base/common/event';
import {ITextFileService} from 'vs/workbench/parts/files/common/files'; // TODO@Ben layer breaker
import {ITextFileService} from 'vs/workbench/services/textfile/common/textfiles';
/**
* An editor input to be used for untitled text buffers.
@@ -42,7 +41,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
hasAssociatedFilePath: boolean,
modeId: string,
@IInstantiationService private instantiationService: IInstantiationService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IModeService private modeService: IModeService,
@ITextFileService private textFileService: ITextFileService
@@ -100,23 +98,17 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
public suggestFileName(): string {
if (!this.hasAssociatedFilePath) {
const mime = this.getMime();
if (mime && mime !== MIME_TEXT /* do not suggest when the mime type is simple plain text */) {
return suggestFilename(mime, this.getName());
if (this.cachedModel) {
const modeId = this.cachedModel.getModeId();
if (modeId !== PLAINTEXT_MODE_ID) { // do not suggest when the mode ID is simple plain text
return suggestFilename(modeId, this.getName());
}
}
}
return this.getName();
}
public getMime(): string {
if (this.cachedModel) {
return this.modeService.getMimeForMode(this.cachedModel.getModeId());
}
return null;
}
public getEncoding(): string {
if (this.cachedModel) {
return this.cachedModel.getEncoding();
@@ -149,15 +141,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
private createModel(): UntitledEditorModel {
const content = '';
let mime = this.modeId;
if (!mime && this.hasAssociatedFilePath) {
const mimeFromPath = guessMimeTypes(this.resource.fsPath)[0];
if (!isUnspecific(mimeFromPath)) {
mime = mimeFromPath; // take most specific mime type if file path is associated and mime is specific
}
}
const model = this.instantiationService.createInstance(UntitledEditorModel, content, mime || MIME_TEXT, this.resource, this.hasAssociatedFilePath);
const model = this.instantiationService.createInstance(UntitledEditorModel, content, this.modeId, this.resource, this.hasAssociatedFilePath);
// re-emit some events from the model
this.toUnbind.push(model.onDidChangeDirty(() => this._onDidChangeDirty.fire()));

View File

@@ -9,13 +9,13 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {EditorModel, IEncodingSupport} from 'vs/workbench/common/editor';
import {StringEditorModel} from 'vs/workbench/common/editor/stringEditorModel';
import URI from 'vs/base/common/uri';
import {PLAINTEXT_MODE_ID} from 'vs/editor/common/modes/modesRegistry';
import {EndOfLinePreference} from 'vs/editor/common/editorCommon';
import {IFileService, IFilesConfiguration} from 'vs/platform/files/common/files';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IMode} from 'vs/editor/common/modes';
import {isUnspecific} from 'vs/base/common/mime';
import Event, {Emitter} from 'vs/base/common/event';
export class UntitledEditorModel extends StringEditorModel implements IEncodingSupport {
@@ -35,7 +35,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
constructor(
value: string,
mime: string,
modeId: string,
resource: URI,
hasAssociatedFilePath: boolean,
@IModeService modeService: IModeService,
@@ -43,7 +43,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
@IFileService private fileService: IFileService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(value, mime, resource, modeService, modelService);
super(value, modeId, resource, modeService, modelService);
this.hasAssociatedFilePath = hasAssociatedFilePath;
this.dirty = hasAssociatedFilePath; // untitled associated to file path are dirty right away
@@ -64,12 +64,12 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
return this._onDidChangeEncoding.event;
}
protected getOrCreateMode(modeService: IModeService, mime: string, firstLineText?: string): TPromise<IMode> {
if (isUnspecific(mime)) {
return modeService.getOrCreateModeByFilenameOrFirstLine(this.resource.fsPath, firstLineText); // lookup mode via resource path if the provided mime is unspecific
protected getOrCreateMode(modeService: IModeService, modeId: string, firstLineText?: string): TPromise<IMode> {
if (!modeId || modeId === PLAINTEXT_MODE_ID) {
return modeService.getOrCreateModeByFilenameOrFirstLine(this.resource.fsPath, firstLineText); // lookup mode via resource path if the provided modeId is unspecific
}
return super.getOrCreateMode(modeService, mime, firstLineText);
return super.getOrCreateMode(modeService, modeId, firstLineText);
}
private registerListeners(): void {
@@ -144,16 +144,19 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
}
private onModelContentChanged(): void {
// turn dirty if we were not
if (!this.dirty) {
this.dirty = true;
this._onDidChangeDirty.fire();
}
// mark the untitled editor as non-dirty once its content becomes empty and we do
// not have an associated path set
else if (!this.hasAssociatedFilePath && this.textEditorModel.getLineCount() === 1 && this.textEditorModel.getLineContent(1) === '') {
this.dirty = false;
// not have an associated path set. we never want dirty indicator in that case.
if (!this.hasAssociatedFilePath && this.textEditorModel.getLineCount() === 1 && this.textEditorModel.getLineContent(1) === '') {
if (this.dirty) {
this.dirty = false;
this._onDidChangeDirty.fire();
}
}
// turn dirty if we were not
else if (!this.dirty) {
this.dirty = true;
this._onDidChangeDirty.fire();
}