From 245ce3ae21dec4c6a577e06b28216cccbf36e439 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 21 Mar 2019 16:00:00 +0100 Subject: [PATCH] files - proper size for content --- src/vs/platform/files/common/files.ts | 17 +++++++++-------- .../browser/nodeless.simpleservices.ts | 7 +++++-- .../services/files/node/fileService.ts | 2 ++ .../services/files/node/remoteFileService.ts | 4 +++- .../textfile/common/textFileEditorModel.ts | 5 +++-- .../services/textfile/common/textFileService.ts | 6 +++--- src/vs/workbench/test/workbenchTestServices.ts | 7 +++++-- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index 340cc1d6423..e26c5f2913b 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -499,6 +499,14 @@ interface IBaseStat { */ name: string; + /** + * The size of the file. + * + * The value may or may not be resolved as + * it is optional. + */ + size?: number; + /** * The last modifictaion date represented * as millis from unix epoch. @@ -526,6 +534,7 @@ interface IBaseStat { export interface IBaseStatWithMetadata extends IBaseStat { mtime: number; etag: string; + size: number; } /** @@ -548,14 +557,6 @@ export interface IFileStat extends IBaseStat { * The children of the file stat or undefined if none. */ children?: IFileStat[]; - - /** - * The size of the file. - * - * The value may or may not be resolved as - * it is optional. - */ - size?: number; } export interface IFileStatWithMetadata extends IFileStat, IBaseStatWithMetadata { diff --git a/src/vs/workbench/browser/nodeless.simpleservices.ts b/src/vs/workbench/browser/nodeless.simpleservices.ts index 6bf801a6b67..e08fe1645db 100644 --- a/src/vs/workbench/browser/nodeless.simpleservices.ts +++ b/src/vs/workbench/browser/nodeless.simpleservices.ts @@ -736,7 +736,9 @@ export class SimpleRemoteFileService implements IFileService { // @ts-ignore mtime: content.mtime, // @ts-ignore - name: content.name + name: content.name, + // @ts-ignore + size: content.size }; }); } @@ -860,7 +862,8 @@ function initFakeFileSystem(): void { mtime: Date.now(), isDirectory: true, name: basename(workspaceResource.fsPath), - children: [] + children: [], + size: 0 }; fileMap.set(root.resource, root); diff --git a/src/vs/workbench/services/files/node/fileService.ts b/src/vs/workbench/services/files/node/fileService.ts index d99791bea33..7dbeac6cfc3 100644 --- a/src/vs/workbench/services/files/node/fileService.ts +++ b/src/vs/workbench/services/files/node/fileService.ts @@ -228,6 +228,7 @@ export class FileService extends Disposable implements ILegacyFileService, IFile etag: streamContent.etag, encoding: streamContent.encoding, isReadonly: streamContent.isReadonly, + size: streamContent.size, value: '' }; @@ -279,6 +280,7 @@ export class FileService extends Disposable implements ILegacyFileService, IFile result.name = stat.name; result.mtime = stat.mtime; result.etag = stat.etag; + result.size = stat.size; // Return early if resource is a directory if (stat.isDirectory) { diff --git a/src/vs/workbench/services/files/node/remoteFileService.ts b/src/vs/workbench/services/files/node/remoteFileService.ts index 05582b32e3d..4b7334c5522 100644 --- a/src/vs/workbench/services/files/node/remoteFileService.ts +++ b/src/vs/workbench/services/files/node/remoteFileService.ts @@ -324,7 +324,8 @@ export class RemoteFileService extends FileService { name: fileStat.name, etag: fileStat.etag, mtime: fileStat.mtime, - isReadonly: fileStat.isReadonly + isReadonly: fileStat.isReadonly, + size: fileStat.size }; }); }); @@ -418,6 +419,7 @@ export class RemoteFileService extends FileService { value: '', encoding: content.encoding, etag: content.etag, + size: content.size, mtime: content.mtime, name: content.name, resource: content.resource, diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 5da9672adfe..1b7f86ba5f3 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -270,6 +270,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil resource: this.resource, name: basename(this.resource), mtime: Date.now(), + size: 0, etag: etag(Date.now(), 0), value: createTextBufferFactory(''), /* will be filled later from backup */ encoding: this.fileService.encoding.getWriteEncoding(this.resource, this.preferredEncoding).encoding, @@ -349,6 +350,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil private loadWithContent(content: IRawTextContent, options?: ILoadOptions, backup?: URI): Promise { return this.doLoadWithContent(content, backup).then(model => { + // Telemetry: We log the fileGet telemetry event after the model has been loaded to ensure a good mimetype const settingsType = this.getTypeIfSettings(); if (settingsType) { @@ -381,11 +383,10 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil resource: this.resource, name: content.name, mtime: content.mtime, - size: -1, + size: content.size, etag: content.etag, isDirectory: false, isSymbolicLink: false, - children: undefined, isReadonly: content.isReadonly }); diff --git a/src/vs/workbench/services/textfile/common/textFileService.ts b/src/vs/workbench/services/textfile/common/textFileService.ts index e90549429ac..c8de89c0abe 100644 --- a/src/vs/workbench/services/textfile/common/textFileService.ts +++ b/src/vs/workbench/services/textfile/common/textFileService.ts @@ -109,16 +109,16 @@ export class TextFileService extends Disposable implements ITextFileService { resolveTextContent(resource: URI, options?: IResolveContentOptions): Promise { return this.fileService.resolveStreamContent(resource, options).then(streamContent => { return createTextBufferFactoryFromStream(streamContent.value).then(res => { - const r: IRawTextContent = { + return { resource: streamContent.resource, name: streamContent.name, mtime: streamContent.mtime, etag: streamContent.etag, encoding: streamContent.encoding, isReadonly: streamContent.isReadonly, + size: streamContent.size, value: res - }; - return r; + } as IRawTextContent; }); }); } diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 2e24dfe49f1..52d33a4591f 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -251,7 +251,8 @@ export class TestTextFileService extends TextFileService { mtime: content.mtime, etag: content.etag, encoding: content.encoding, - value: createTextBufferFactory(content.value) + value: createTextBufferFactory(content.value), + size: content.value.length }; }); } @@ -961,7 +962,8 @@ export class TestFileService implements IFileService { etag: 'index.txt', encoding: 'utf8', mtime: Date.now(), - name: resources.basename(resource) + name: resources.basename(resource), + size: 1 }); } @@ -981,6 +983,7 @@ export class TestFileService implements IFileService { etag: 'index.txt', encoding: 'utf8', mtime: Date.now(), + size: 1, name: resources.basename(resource) }); } -- GitLab