Merge from vscode 718331d6f3ebd1b571530ab499edb266ddd493d5

This commit is contained in:
ADS Merger
2020-02-08 04:50:58 +00:00
parent 8c61538a27
commit 2af13c18d2
752 changed files with 16458 additions and 10063 deletions

View File

@@ -10,7 +10,7 @@ import { withNullAsUndefined, assertIsDefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IEditor as ICodeEditor, IEditorViewState, ScrollType, IDiffEditor } from 'vs/editor/common/editorCommon';
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, IResourceInput, EditorActivation, EditorOpenContext, ITextEditorSelection } from 'vs/platform/editor/common/editor';
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, IResourceInput, EditorActivation, EditorOpenContext, ITextEditorSelection, TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
import { IInstantiationService, IConstructorSignature0, ServicesAccessor, BrandedService } from 'vs/platform/instantiation/common/instantiation';
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { Registry } from 'vs/platform/registry/common/platform';
@@ -18,14 +18,18 @@ import { ITextModel } from 'vs/editor/common/model';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { ICompositeControl } from 'vs/workbench/common/composite';
import { ActionRunner, IAction } from 'vs/base/common/actions';
import { IFileService } from 'vs/platform/files/common/files';
import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { IPathData } from 'vs/platform/windows/common/windows';
import { coalesce, firstOrDefault } from 'vs/base/common/arrays';
import { ITextFileSaveOptions, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { isEqual } from 'vs/base/common/resources';
import { isEqual, dirname } from 'vs/base/common/resources';
import { IPanel } from 'vs/workbench/common/panel';
import { IRange } from 'vs/editor/common/core/range';
import { createMemoizer } from 'vs/base/common/decorators';
import { ILabelService } from 'vs/platform/label/common/label';
import { Schemas } from 'vs/base/common/network';
import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
export const DirtyWorkingCopiesContext = new RawContextKey<boolean>('dirtyWorkingCopies', false);
export const ActiveEditorContext = new RawContextKey<string | null>('activeEditor', null);
@@ -201,7 +205,7 @@ export interface IEditorInputFactoryRegistry {
export interface IEditorInputFactory {
/**
* Determines wether the given editor input can be serialized by the factory.
* Determines whether the given editor input can be serialized by the factory.
*/
canSerialize(editorInput: IEditorInput): boolean;
@@ -416,18 +420,20 @@ export interface IEditorInput extends IDisposable {
* to e.g. preserve view state of the editor and re-open it
* in the correct group after saving.
*
* @returns the resulting editor input of this operation. Can
* be the same editor input.
* @returns the resulting editor input (typically the same) of
* this operation or `undefined` to indicate that the operation
* failed or was canceled.
*/
save(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined>;
/**
* Saves the editor to a different location. The provided groupId
* Saves the editor to a different location. The provided `group`
* helps implementors to e.g. preserve view state of the editor
* and re-open it in the correct group after saving.
*
* @returns the resulting editor input of this operation. Typically
* a different editor input.
* @returns the resulting editor input (typically a different one)
* of this operation or `undefined` to indicate that the operation
* failed or was canceled.
*/
saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined>;
@@ -563,21 +569,123 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
}
}
export abstract class TextEditorInput extends EditorInput {
export abstract class TextResourceEditorInput extends EditorInput {
private static readonly MEMOIZER = createMemoizer();
constructor(
protected readonly resource: URI,
@IEditorService protected readonly editorService: IEditorService,
@IEditorGroupsService protected readonly editorGroupService: IEditorGroupsService,
@ITextFileService protected readonly textFileService: ITextFileService
@ITextFileService protected readonly textFileService: ITextFileService,
@ILabelService protected readonly labelService: ILabelService,
@IFileService protected readonly fileService: IFileService,
@IFilesConfigurationService protected readonly filesConfigurationService: IFilesConfigurationService
) {
super();
// Clear label memoizer on certain events that have impact
this._register(this.labelService.onDidChangeFormatters(() => TextResourceEditorInput.MEMOIZER.clear()));
this._register(this.fileService.onDidChangeFileSystemProviderRegistrations(() => TextResourceEditorInput.MEMOIZER.clear()));
}
getResource(): URI {
return this.resource;
}
getName(): string {
return this.basename;
}
@TextResourceEditorInput.MEMOIZER
private get basename(): string {
return this.labelService.getUriBasenameLabel(this.resource);
}
getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | undefined {
switch (verbosity) {
case Verbosity.SHORT:
return this.shortDescription;
case Verbosity.LONG:
return this.longDescription;
case Verbosity.MEDIUM:
default:
return this.mediumDescription;
}
}
@TextResourceEditorInput.MEMOIZER
private get shortDescription(): string {
return this.labelService.getUriBasenameLabel(dirname(this.resource));
}
@TextResourceEditorInput.MEMOIZER
private get mediumDescription(): string {
return this.labelService.getUriLabel(dirname(this.resource), { relative: true });
}
@TextResourceEditorInput.MEMOIZER
private get longDescription(): string {
return this.labelService.getUriLabel(dirname(this.resource));
}
@TextResourceEditorInput.MEMOIZER
private get shortTitle(): string {
return this.getName();
}
@TextResourceEditorInput.MEMOIZER
private get mediumTitle(): string {
return this.labelService.getUriLabel(this.resource, { relative: true });
}
@TextResourceEditorInput.MEMOIZER
private get longTitle(): string {
return this.labelService.getUriLabel(this.resource);
}
getTitle(verbosity: Verbosity): string {
switch (verbosity) {
case Verbosity.SHORT:
return this.shortTitle;
case Verbosity.LONG:
return this.longTitle;
default:
case Verbosity.MEDIUM:
return this.mediumTitle;
}
}
isUntitled(): boolean {
return this.resource.scheme === Schemas.untitled;
}
isReadonly(): boolean {
if (this.isUntitled()) {
return false; // untitled is never readonly
}
if (!this.fileService.canHandleResource(this.resource)) {
return true; // resources without file support are always readonly
}
const model = this.textFileService.files.get(this.resource);
return model?.isReadonly() || this.fileService.hasCapability(this.resource, FileSystemProviderCapabilities.Readonly);
}
isSaving(): boolean {
if (this.isUntitled()) {
return false; // untitled is never saving automatically
}
if (this.filesConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
return true; // a short auto save is configured, treat this as being saved
}
return false;
}
async save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
return this.doSave(group, options, false);
}
@@ -1002,9 +1110,9 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
editorViewState: IEditorViewState | undefined;
/**
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
* Option to control the text editor selection reveal type.
*/
revealInCenterIfOutsideViewport: boolean | undefined;
selectionRevealType: TextEditorSelectionRevealType | undefined;
static from(input?: IBaseResourceInput): TextEditorOptions | undefined {
if (!input || !input.options) {
@@ -1043,8 +1151,8 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
this.editorViewState = options.viewState as IEditorViewState;
}
if (typeof options.revealInCenterIfOutsideViewport === 'boolean') {
this.revealInCenterIfOutsideViewport = options.revealInCenterIfOutsideViewport;
if (typeof options.selectionRevealType !== 'undefined') {
this.selectionRevealType = options.selectionRevealType;
}
return this;
@@ -1054,7 +1162,7 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
* Returns if this options object has objects defined for the editor.
*/
hasOptionsDefined(): boolean {
return !!this.editorViewState || !!this.revealInCenterIfOutsideViewport || !!this.selection;
return !!this.editorViewState || !!this.selectionRevealType || !!this.selection;
}
/**
@@ -1094,7 +1202,9 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
editor.setSelection(range);
if (this.revealInCenterIfOutsideViewport) {
if (this.selectionRevealType === TextEditorSelectionRevealType.NearTop) {
editor.revealRangeNearTop(range, scrollType);
} else if (this.selectionRevealType === TextEditorSelectionRevealType.CenterIfOutsideViewport) {
editor.revealRangeInCenterIfOutsideViewport(range, scrollType);
} else {
editor.revealRangeInCenter(range, scrollType);