Skip to content

Commit

Permalink
Switched to newer method, put placeholders for all message commands, …
Browse files Browse the repository at this point in the history
…still need to figure out eventlistener
  • Loading branch information
nlewis05 committed Oct 17, 2023
1 parent a2c8866 commit 5d64472
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 312 deletions.
220 changes: 112 additions & 108 deletions src/dataEditor/dataEditorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import XDGAppPaths from 'xdg-app-paths'
import assert from 'assert'
import { SvelteWebviewInitializer } from './svelteWebviewInitializer'
import {
MessageCommands,
RobertMessageCommand,
MessageCommand,
MessageLevel,
} from '../svelte/src/utilities/message'
import {
EditByteModes,
Expand Down Expand Up @@ -305,26 +305,26 @@ export class DataEditorClient implements vscode.Disposable {
}

private async sendHeartbeat() {

let heartBeatMsg: MessageCommand['HeartBeat'] = {
latency: heartbeatInfo.latency,
omegaEditPort: heartbeatInfo.omegaEditPort,
serverCpuLoadAverage: heartbeatInfo.serverCpuLoadAverage,
serverUptime: heartbeatInfo.serverUptime,
serverUsedMemory: heartbeatInfo.serverUsedMemory,
sessionCount: heartbeatInfo.sessionCount,
omegaEditPort: heartbeatInfo.omegaEditPort,
serverVersion: heartbeatInfo.serverInfo.serverVersion,
serverHostname: heartbeatInfo.serverInfo.serverHostname,
serverProcessId: heartbeatInfo.serverInfo.serverProcessId,
jvmVersion: heartbeatInfo.serverInfo.jvmVersion,
jvmVendor: heartbeatInfo.serverInfo.jvmVendor,
jvmPath: heartbeatInfo.serverInfo.jvmPath,
availableProcessors: heartbeatInfo.serverInfo.availableProcessors,
}
await this.panel.webview.postMessage({
command: MessageCommand.heartbeat,
data: {
latency: heartbeatInfo.latency,
omegaEditPort: heartbeatInfo.omegaEditPort,
serverCpuLoadAverage: heartbeatInfo.serverCpuLoadAverage,
serverUptime: heartbeatInfo.serverUptime,
serverUsedMemory: heartbeatInfo.serverUsedMemory,
sessionCount: heartbeatInfo.sessionCount,
serverInfo: {
omegaEditPort: heartbeatInfo.omegaEditPort,
serverVersion: heartbeatInfo.serverInfo.serverVersion,
serverHostname: heartbeatInfo.serverInfo.serverHostname,
serverProcessId: heartbeatInfo.serverInfo.serverProcessId,
jvmVersion: heartbeatInfo.serverInfo.jvmVersion,
jvmVendor: heartbeatInfo.serverInfo.jvmVendor,
jvmPath: heartbeatInfo.serverInfo.jvmPath,
availableProcessors: heartbeatInfo.serverInfo.availableProcessors,
},
},
command: 'Heartbeat',
data: heartBeatMsg,
})
}

Expand Down Expand Up @@ -357,18 +357,29 @@ export class DataEditorClient implements vscode.Disposable {
}
})

let fileInfoMsg: MessageCommand['FileInfo'] = {
computedFileSize: data.computedFileSize,
fileName: data.fileName,
changeCount: data.changeCount,
undoCount: data.undoCount
}

// send the accumulated counts to the webview
await this.panel.webview.postMessage({
command: MessageCommand.fileInfo,
data: data,
command: 'FileInfo',
data: fileInfoMsg,
})
}

// handle messages from the webview
private async messageReceiver(message: IMessage) {
switch (message.command) {
case MessageCommand.showMessage:
switch (message.data.messageLevel as MessageLevel) {
private async messageReceiver() {
switch (MessageCommand[]) {
case 'Show':
let showMessage: MessageCommand['Show'] = {
messageLevel: ,
message: ,
}
switch (showMessage.messageLevel as MessageLevel) {
case MessageLevel.Error:
vscode.window.showErrorMessage(message.data.message)
break
Expand All @@ -381,7 +392,7 @@ export class DataEditorClient implements vscode.Disposable {
}
break

case MessageCommand.scrollViewport:
case 'ScrollViewport':
await this.scrollViewport(
this.panel,
this.currentViewportId,
Expand All @@ -390,22 +401,27 @@ export class DataEditorClient implements vscode.Disposable {
)
break

case MessageCommand.editorOnChange:
case 'Edit':
{
this.displayState.editorEncoding = message.data.encoding
let editMsg: MessageCommand['Edit'] = {
encoding: ,
editMode: ,
selectionData: ,
}
this.displayState.editorEncoding = editMsg.encoding
const encodeDataAs =
message.data.editMode === EditByteModes.Single
editMsg.editMode === EditByteModes.Single
? 'hex'
: this.displayState.editorEncoding

if (
message.data.selectionData &&
message.data.selectionData.length > 0
editMsg.selectionData &&
editMsg.selectionData.length > 0
) {
await this.panel.webview.postMessage({
command: MessageCommand.editorOnChange,
display: dataToEncodedStr(
Buffer.from(message.data.selectionData),
Buffer.from(editMsg.selectionData),
encodeDataAs
),
})
Expand All @@ -415,52 +431,46 @@ export class DataEditorClient implements vscode.Disposable {

// case MessageCommand.applyChanges:
case 'apply':
let incomingMsg: RobertMessageCommand['Apply'] = message.data
let incomingMsg: MessageCommand['Apply'] = message.data
incomingMsg.editedSegmentData
incomingMsg.offset
incomingMsg.originalSegmentData

await edit(
this.omegaSessionId,
message.data.offset,
message.data.originalSegment,
message.data.editedSegment
incomingMsg.offset,
incomingMsg.originalSegmentData,
incomingMsg.editedSegmentData
)
await this.sendChangesInfo()
break

case MessageCommand.undoChange:
case 'Undo'
let undoMsg: MessageCommand[]
await undo(this.omegaSessionId)
await this.sendChangesInfo()
break

case MessageCommand.redoChange:
case 'Redo'
await redo(this.omegaSessionId)
await this.sendChangesInfo()
break

case MessageCommand.profile:
case 'Profile':
{
const startOffset: number = message.data.startOffset
const length: number = message.data.length
const byteProfile: number[] = await profileSession(
this.omegaSessionId,
startOffset,
length
)
let profileMsg: MessageCommand['Profile'] = message.data
profileMsg.startOffset
profileMsg.length
profileMsg.byteProfile

await this.panel.webview.postMessage({
command: MessageCommand.profile,
data: {
startOffset: startOffset,
length: length,
byteProfile: byteProfile,
numAscii: numAscii(byteProfile),
},
command: 'Profile',
data: profileMsg,
})
}
break

case MessageCommand.clearChanges:
case 'Clear':
if (
(await vscode.window.showInformationMessage(
'Are you sure you want to revert all changes?',
Expand All @@ -474,11 +484,11 @@ export class DataEditorClient implements vscode.Disposable {
}
break

case MessageCommand.save:
case 'Save':
await this.saveFile(this.fileToEdit)
break

case MessageCommand.saveAs:
case 'SaveAs':
{
const uri = await vscode.window.showSaveDialog({
title: 'Save Session',
Expand All @@ -490,29 +500,27 @@ export class DataEditorClient implements vscode.Disposable {
}
break

case MessageCommand.requestEditedData:
case 'RequestEditedData':
{
let requestEditedDataMsg: MessageCommand['RequestEditedData'] = message.data
const [selectionData, selectionDisplay] = fillRequestData(message)

await this.panel.webview.postMessage({
command: MessageCommand.requestEditedData,
data: {
data: Uint8Array.from(selectionData),
dataDisplay: selectionDisplay,
},
command: 'RequestEditedData',
data: requestEditedDataMsg,
})
}
break

case MessageCommand.replace:
case 'ReplaceResults':
{
let replaceResultsMsg: MessageCommand['ReplaceResults'] = message.data
const searchDataBytes = encodedStrToData(
message.data.searchData,
message.data.encoding
)
const replaceDataBytes = encodedStrToData(
message.data.replaceData,
message.data.encoding
message.data.encoding,
)
const nextOffset = await replaceOneSession(
this.omegaSessionId,
Expand All @@ -530,49 +538,44 @@ export class DataEditorClient implements vscode.Disposable {
await this.sendChangesInfo()
}
await this.panel.webview.postMessage({
command: MessageCommand.replaceResults,
data: {
replacementsCount: nextOffset === -1 ? 0 : 1,
nextOffset: nextOffset,
searchDataBytesLength: searchDataBytes.length,
replaceDataBytesLength: replaceDataBytes.length,
},
command: 'ReplaceResults',
data: replaceResultsMsg
})
}
break

case MessageCommand.search:
case 'Search':
{
let searchMsg: MessageCommand['Search'] = message.data

const searchDataBytes = encodedStrToData(
message.data.searchData,
message.data.encoding
searchMsg.searchData,
searchMsg.encoding
)

let searchResultsMsg: MessageCommand['SearchResults'] = message.data
const searchResults = await searchSession(
this.omegaSessionId,
searchDataBytes,
message.data.caseInsensitive,
message.data.isReverse,
message.data.searchOffset,
message.data.searchLength,
message.data.limit + 1
searchResultsMsg.caseInsensitive,
searchResultsMsg.isReverse,
searchResultsMsg.searchOffset,
searchResultsMsg.searchLength,
searchResultsMsg.limit + 1
)
if (searchResults.length === 0) {
vscode.window.showInformationMessage(
`No more matches found for '${message.data.searchData}'`
`No more matches found for '${searchMsg.searchData}'`
)
}
let overflow = false
if (searchResults.length > message.data.limit) {
if (searchResults.length > searchResultsMsg.limit) {
overflow = true
searchResults.pop()
}
await this.panel.webview.postMessage({
command: MessageCommand.searchResults,
data: {
searchResults: searchResults,
searchDataBytesLength: searchDataBytes.length,
overflow: overflow,
},
command: 'SearchResults',
data: searchResultsMsg
})
}
break
Expand Down Expand Up @@ -615,14 +618,11 @@ export class DataEditorClient implements vscode.Disposable {

if (saved) {
this.fileToEdit = fileToSave
this.fileSize = await getComputedFileSize(this.omegaSessionId)
this.fileSize = await getComputedFileSize(this.omegaSessionId)
let fileInfoMsg: MessageCommand['FileInfo'] = message.data
await this.panel.webview.postMessage({
command: MessageCommand.fileInfo,
data: {
computedFileSize: this.fileSize,
diskFileSize: this.fileSize,
fileName: this.fileToEdit,
},
command: 'FileInfo',
data: fileInfoMsg,
})
vscode.window.showInformationMessage(`Saved: ${this.fileToEdit}`)
} else if (cancelled) {
Expand Down Expand Up @@ -827,16 +827,17 @@ async function sendViewportRefresh(
panel: vscode.WebviewPanel,
viewportDataResponse: ViewportDataResponse
): Promise<void> {
let viewportRefreshMsg: MessageCommand['ViewPortRefresh'] = {
viewportId: viewportDataResponse.getViewportId(),
viewportOffset: viewportDataResponse.getOffset(),
viewportLength: viewportDataResponse.getLength(),
viewportFollowingByteCount: viewportDataResponse.getFollowingByteCount(),
viewportData: viewportDataResponse.getData_asU8(),
viewportCapacity: VIEWPORT_CAPACITY_MAX,
}
await panel.webview.postMessage({
command: MessageCommand.viewportRefresh,
data: {
viewportId: viewportDataResponse.getViewportId(),
viewportOffset: viewportDataResponse.getOffset(),
viewportLength: viewportDataResponse.getLength(),
viewportFollowingByteCount: viewportDataResponse.getFollowingByteCount(),
viewportData: viewportDataResponse.getData_asU8(),
viewportCapacity: VIEWPORT_CAPACITY_MAX,
},
command: 'ViewportRefresh',
data: viewportRefreshMsg,
})
}

Expand Down Expand Up @@ -891,9 +892,12 @@ class DisplayState {
}

private sendUIThemeUpdate() {
return this.panel.webview.postMessage({
command: MessageCommand.setUITheme,
let setUIThemeMsg: MessageCommand['SetUITheme'] = {
theme: this.colorThemeKind,
}
return this.panel.webview.postMessage({
command: 'SetUITheme',
theme: setUIThemeMsg,
})
}
}
Expand Down
Loading

0 comments on commit 5d64472

Please sign in to comment.