Stop Using os library in NotebookTextFileModel (#6993)

* Stop using os library

* small fix
This commit is contained in:
Chris LaFreniere
2019-08-27 20:45:30 -07:00
committed by GitHub
parent e96b1796b3
commit 50a0b6e115
3 changed files with 13 additions and 7 deletions

View File

@@ -27,21 +27,25 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts'; import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts';
import { Deferred } from 'sql/base/common/promise'; import { Deferred } from 'sql/base/common/promise';
import { NotebookTextFileModel } from 'sql/workbench/parts/notebook/common/models/notebookTextFileModel'; import { NotebookTextFileModel } from 'sql/workbench/parts/notebook/common/models/notebookTextFileModel';
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>; export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>;
export class NotebookEditorModel extends EditorModel { export class NotebookEditorModel extends EditorModel {
private _dirty: boolean; private _dirty: boolean;
private _changeEventsHookedUp: boolean = false; private _changeEventsHookedUp: boolean = false;
private _notebookTextFileModel: NotebookTextFileModel = new NotebookTextFileModel(); private _notebookTextFileModel: NotebookTextFileModel;
private readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>()); private readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>());
private _lastEditFullReplacement: boolean; private _lastEditFullReplacement: boolean;
constructor(public readonly notebookUri: URI, constructor(public readonly notebookUri: URI,
private textEditorModel: TextFileEditorModel | UntitledEditorModel, private textEditorModel: TextFileEditorModel | UntitledEditorModel,
@INotebookService private notebookService: INotebookService, @INotebookService private notebookService: INotebookService,
@ITextFileService private textFileService: ITextFileService @ITextFileService private textFileService: ITextFileService,
@ITextResourcePropertiesService private textResourcePropertiesService: ITextResourcePropertiesService
) { ) {
super(); super();
let _eol = this.textResourcePropertiesService.getEOL(URI.from({ scheme: Schemas.untitled }));
this._notebookTextFileModel = new NotebookTextFileModel(_eol);
this._register(this.notebookService.onNotebookEditorAdd(notebook => { this._register(this.notebookService.onNotebookEditorAdd(notebook => {
if (notebook.id === this.notebookUri.toString()) { if (notebook.id === this.notebookUri.toString()) {
// Hook to content change events // Hook to content change events

View File

@@ -9,7 +9,6 @@ import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textF
import { FindMatch } from 'vs/editor/common/model'; import { FindMatch } from 'vs/editor/common/model';
import { NotebookContentChange, INotebookModel } from 'sql/workbench/parts/notebook/common/models/modelInterfaces'; import { NotebookContentChange, INotebookModel } from 'sql/workbench/parts/notebook/common/models/modelInterfaces';
import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts'; import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts';
import * as os from 'os';
export class NotebookTextFileModel { export class NotebookTextFileModel {
// save active cell's line/column in editor model for the beginning of the source property // 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 // save active cell guid
private _activeCellGuid: string; private _activeCellGuid: string;
constructor() { constructor(private _eol: string) {
} }
public get activeCellGuid(): string { public get activeCellGuid(): string {
@@ -53,7 +52,7 @@ export class NotebookTextFileModel {
// this is another string // this is another string
textEditorModel.textEditorModel.applyEdits([{ textEditorModel.textEditorModel.applyEdits([{
range: new Range(convertedRange.startLineNumber, convertedRange.startColumn, convertedRange.endLineNumber, convertedRange.endColumn), 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 { } else {

View File

@@ -28,11 +28,12 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager'; import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; 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 { Range } from 'vs/editor/common/core/range';
import { nb } from 'azdata'; import { nb } from 'azdata';
import { Emitter } from 'vs/base/common/event'; import { Emitter } from 'vs/base/common/event';
import { INotebookEditor, INotebookManager } from 'sql/workbench/services/notebook/common/notebookService'; import { INotebookEditor, INotebookManager } from 'sql/workbench/services/notebook/common/notebookService';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
class ServiceAccessor { 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()); const queryConnectionService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose, memento.object, undefined, new TestStorageService());
queryConnectionService.callBase = true; queryConnectionService.callBase = true;
const capabilitiesService = TypeMoq.Mock.ofType(TestCapabilitiesService); const capabilitiesService = TypeMoq.Mock.ofType(TestCapabilitiesService);
const configurationService = new TestConfigurationService();
const testResourcePropertiesService = new TestTextResourcePropertiesService(configurationService);
let mockModelFactory = TypeMoq.Mock.ofType(ModelFactory); let mockModelFactory = TypeMoq.Mock.ofType(ModelFactory);
mockModelFactory.callBase = true; mockModelFactory.callBase = true;
mockModelFactory.setup(f => f.createCell(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { 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); let textFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(self, defaultUri.toString()), 'utf8', undefined);
(<TextFileEditorModelManager>accessor.textFileService.models).add(textFileEditorModel.getResource(), textFileEditorModel); (<TextFileEditorModelManager>accessor.textFileService.models).add(textFileEditorModel.getResource(), textFileEditorModel);
await textFileEditorModel.load(); await textFileEditorModel.load();
return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, accessor.textFileService); return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, accessor.textFileService, testResourcePropertiesService);
} }
}); });