From d7a5703020eb2fb2f512e35a70e43b649a56d6aa Mon Sep 17 00:00:00 2001 From: Robert Strickland Date: Fri, 3 May 2024 17:43:33 -0500 Subject: [PATCH] Session populates data --- src/dataEditor/dataEditorClient.ts | 2 +- .../include/client/dataEditorClient.ts | 21 ++--------- src/dataEditor/include/server/Server.ts | 35 +++++++++---------- .../include/service/editorService.ts | 6 ++-- src/dataEditor/standalone/standaloneEditor.ts | 3 -- 5 files changed, 23 insertions(+), 44 deletions(-) diff --git a/src/dataEditor/dataEditorClient.ts b/src/dataEditor/dataEditorClient.ts index afebc08e7..aaa30cbbd 100644 --- a/src/dataEditor/dataEditorClient.ts +++ b/src/dataEditor/dataEditorClient.ts @@ -157,7 +157,7 @@ export function activate(ctx: vscode.ExtensionContext): void { await server.start() /* Moving on w/ assumption that server is up and running */ const editor = new StandaloneEditor(ctx, configVars) - await editor.initialize(await server.getService()) + await editor.initialize(server) // await server.register(editor.heatbeat) // return await createDataEditorWebviewPanel(ctx, configVars, fileToEdit) } diff --git a/src/dataEditor/include/client/dataEditorClient.ts b/src/dataEditor/include/client/dataEditorClient.ts index fdb49c1dc..8580360ce 100644 --- a/src/dataEditor/include/client/dataEditorClient.ts +++ b/src/dataEditor/include/client/dataEditorClient.ts @@ -1,28 +1,13 @@ -import { IHeartbeatReceiver } from '@omega-edit/client' -import { - HeartbeatInfo, - HeartbeatProcessor, -} from '../server/heartbeat/HeartBeatInfo' -import { ServiceHeartbeat } from '../server/Server' +import { IEditServiceProvider } from '../server/Server' import { IEditService } from '../service/editorService' -class TestProcessor implements IHeartbeatReceiver { - constructor( - readonly id: string, - public process: (heartbeat: HeartbeatInfo) => void - ) {} -} export abstract class DataEditor { protected abstract fileToEdit: string protected editService: IEditService | undefined = undefined - constructor() {} - async initialize(service: IEditService) { + async initialize(provider: IEditServiceProvider) { await this.getFile() - this.editService = service - service.setup(this.fileToEdit) - // await this.setupService() + this.editService = await provider.getService(this.fileToEdit) } protected abstract getFile(): Promise - // protected abstract setupService(): Promise } export interface DataEditorUI { show(): Promise diff --git a/src/dataEditor/include/server/Server.ts b/src/dataEditor/include/server/Server.ts index 68d59b0e0..7e42b1c54 100644 --- a/src/dataEditor/include/server/Server.ts +++ b/src/dataEditor/include/server/Server.ts @@ -12,11 +12,10 @@ // import net from 'net' import * as fs from 'fs' import { - IHeartbeatReceiver, + // IHeartbeatReceiver, IServerHeartbeat, IServerInfo, getServerHeartbeat, - getServerHeartbeatFor, getServerInfo, pidIsRunning, startServer, @@ -25,8 +24,7 @@ import { import path from 'path' import { APP_DATA_PATH } from '../../config' import assert from 'assert' -import { HeartbeatProcessor, IHeartbeatInfo } from './heartbeat/HeartBeatInfo' -import { OmegaEditService } from '../service/editorService' +import { IEditService, OmegaEditService } from '../service/editorService' type ServerProcess = { pidFile: string @@ -45,13 +43,10 @@ export class ServiceHeartbeat { }, this.interval) } } -export class ServiceClient { - constructor() { - // createSession() - // createViewport() - } +export interface IEditServiceProvider { + getService(targetFile: string): Promise } -export class OmegaEditServer { +export class OmegaEditServer implements IEditServiceProvider { readonly host: string readonly port: number private proc: ServerProcess = { pidFile: '', pid: -1 } @@ -123,17 +118,19 @@ export class OmegaEditServer { resolve(true) }) } - async getService(): Promise { - return new Promise((resolve, reject) => { - resolve(new OmegaEditService()) + async getService(targetFile: string): Promise { + return new Promise(async (resolve, reject) => { + let service = new OmegaEditService() + await service.set(targetFile) + resolve(service) }) } - static createProcessor( - params: Required - ): IHeartbeatReceiver { - // Register Receiver w/ server registry - return params as IHeartbeatReceiver - } + // static createProcessor( + // params: Required + // ): IHeartbeatReceiver { + // // Register Receiver w/ server registry + // return params as IHeartbeatReceiver + // } private async verify(): Promise { return new Promise(async (resolve, reject) => { for (let i = 1; i <= 10; ++i) { diff --git a/src/dataEditor/include/service/editorService.ts b/src/dataEditor/include/service/editorService.ts index f5c958f4f..87359e40a 100644 --- a/src/dataEditor/include/service/editorService.ts +++ b/src/dataEditor/include/service/editorService.ts @@ -5,12 +5,12 @@ import { getLanguage, CreateSessionResponse, } from '@omega-edit/client' -import assert from 'assert' export interface IEditService { - setup(editingFile: string): any + set(editingFile: string): any } +/* OmegaEditService Implementation */ const SessionMetadata = { byteOrderMark: '', changeCount: 0, @@ -35,7 +35,7 @@ export class Session { export class OmegaEditService implements IEditService { private session: Session | undefined = undefined constructor() {} - async setup(editingFile: string) { + async set(editingFile: string) { try { this.session = new Session(await createSession(editingFile)) } catch { diff --git a/src/dataEditor/standalone/standaloneEditor.ts b/src/dataEditor/standalone/standaloneEditor.ts index 3dda850b7..4daf40f7c 100644 --- a/src/dataEditor/standalone/standaloneEditor.ts +++ b/src/dataEditor/standalone/standaloneEditor.ts @@ -1,7 +1,6 @@ import * as vscode from 'vscode' import * as editor_config from '../config' import { DataEditor } from '../include/client/dataEditorClient' -import { IEditService } from '../include/service/editorService' export class StandaloneEditor extends DataEditor { protected fileToEdit: string = '' @@ -21,6 +20,4 @@ export class StandaloneEditor extends DataEditor { // await this.setupDataEditor() } } - - async setupService(): Promise {} }