From 50a0b6e1159f2de744e4f6662b750f98838172a4 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Tue, 27 Aug 2019 20:45:30 -0700 Subject: [PATCH] Stop Using os library in NotebookTextFileModel (#6993) * Stop using os library * small fix --- .../parts/notebook/browser/models/notebookInput.ts | 8 ++++++-- .../parts/notebook/common/models/notebookTextFileModel.ts | 5 ++--- .../notebook/test/common/notebookEditorModel.test.ts | 7 +++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sql/workbench/parts/notebook/browser/models/notebookInput.ts b/src/sql/workbench/parts/notebook/browser/models/notebookInput.ts index 2ce5cc110c..bc6cc648ad 100644 --- a/src/sql/workbench/parts/notebook/browser/models/notebookInput.ts +++ b/src/sql/workbench/parts/notebook/browser/models/notebookInput.ts @@ -27,21 +27,25 @@ import { IDisposable } from 'vs/base/common/lifecycle'; import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts'; import { Deferred } from 'sql/base/common/promise'; import { NotebookTextFileModel } from 'sql/workbench/parts/notebook/common/models/notebookTextFileModel'; +import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration'; export type ModeViewSaveHandler = (handle: number) => Thenable; export class NotebookEditorModel extends EditorModel { private _dirty: boolean; private _changeEventsHookedUp: boolean = false; - private _notebookTextFileModel: NotebookTextFileModel = new NotebookTextFileModel(); + private _notebookTextFileModel: NotebookTextFileModel; private readonly _onDidChangeDirty: Emitter = this._register(new Emitter()); private _lastEditFullReplacement: boolean; constructor(public readonly notebookUri: URI, private textEditorModel: TextFileEditorModel | UntitledEditorModel, @INotebookService private notebookService: INotebookService, - @ITextFileService private textFileService: ITextFileService + @ITextFileService private textFileService: ITextFileService, + @ITextResourcePropertiesService private textResourcePropertiesService: ITextResourcePropertiesService ) { super(); + let _eol = this.textResourcePropertiesService.getEOL(URI.from({ scheme: Schemas.untitled })); + this._notebookTextFileModel = new NotebookTextFileModel(_eol); this._register(this.notebookService.onNotebookEditorAdd(notebook => { if (notebook.id === this.notebookUri.toString()) { // Hook to content change events diff --git a/src/sql/workbench/parts/notebook/common/models/notebookTextFileModel.ts b/src/sql/workbench/parts/notebook/common/models/notebookTextFileModel.ts index cee8305dfc..e443a451ac 100644 --- a/src/sql/workbench/parts/notebook/common/models/notebookTextFileModel.ts +++ b/src/sql/workbench/parts/notebook/common/models/notebookTextFileModel.ts @@ -9,7 +9,6 @@ import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textF import { FindMatch } from 'vs/editor/common/model'; import { NotebookContentChange, INotebookModel } from 'sql/workbench/parts/notebook/common/models/modelInterfaces'; import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts'; -import * as os from 'os'; export class NotebookTextFileModel { // save active cell's line/column in editor model for the beginning of the source property @@ -19,7 +18,7 @@ export class NotebookTextFileModel { // save active cell guid private _activeCellGuid: string; - constructor() { + constructor(private _eol: string) { } public get activeCellGuid(): string { @@ -53,7 +52,7 @@ export class NotebookTextFileModel { // this is another string textEditorModel.textEditorModel.applyEdits([{ range: new Range(convertedRange.startLineNumber, convertedRange.startColumn, convertedRange.endLineNumber, convertedRange.endColumn), - text: change.text.split(os.EOL).join('\\n\",'.concat(os.EOL).concat(startSpaces).concat('\"')) + text: change.text.split(this._eol).join('\\n\",'.concat(this._eol).concat(startSpaces).concat('\"')) }]); }); } else { diff --git a/src/sql/workbench/parts/notebook/test/common/notebookEditorModel.test.ts b/src/sql/workbench/parts/notebook/test/common/notebookEditorModel.test.ts index 2b9b86f047..963220feb1 100644 --- a/src/sql/workbench/parts/notebook/test/common/notebookEditorModel.test.ts +++ b/src/sql/workbench/parts/notebook/test/common/notebookEditorModel.test.ts @@ -28,11 +28,12 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { TestEnvironmentService, TestLifecycleService, TestStorageService, TestTextFileService, workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices'; +import { TestEnvironmentService, TestLifecycleService, TestStorageService, TestTextFileService, workbenchInstantiationService, TestTextResourcePropertiesService } from 'vs/workbench/test/workbenchTestServices'; import { Range } from 'vs/editor/common/core/range'; import { nb } from 'azdata'; import { Emitter } from 'vs/base/common/event'; import { INotebookEditor, INotebookManager } from 'sql/workbench/services/notebook/common/notebookService'; +import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; class ServiceAccessor { @@ -68,6 +69,8 @@ suite('Notebook Editor Model', function (): void { const queryConnectionService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose, memento.object, undefined, new TestStorageService()); queryConnectionService.callBase = true; const capabilitiesService = TypeMoq.Mock.ofType(TestCapabilitiesService); + const configurationService = new TestConfigurationService(); + const testResourcePropertiesService = new TestTextResourcePropertiesService(configurationService); let mockModelFactory = TypeMoq.Mock.ofType(ModelFactory); mockModelFactory.callBase = true; mockModelFactory.setup(f => f.createCell(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { @@ -640,6 +643,6 @@ suite('Notebook Editor Model', function (): void { let textFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(self, defaultUri.toString()), 'utf8', undefined); (accessor.textFileService.models).add(textFileEditorModel.getResource(), textFileEditorModel); await textFileEditorModel.load(); - return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, accessor.textFileService); + return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, accessor.textFileService, testResourcePropertiesService); } });