From 9f0a0fd42133b922cb573bde065de9d31fc319e1 Mon Sep 17 00:00:00 2001 From: Tejas Tiwari Date: Fri, 19 Dec 2025 17:54:06 +0530 Subject: [PATCH 1/2] Data editor: add profile source target selection Signed-off-by: Tejas Tiwari --- src/dataEditor/dataEditorClient.ts | 125 +++++++++++------- .../components/DataMetrics/DataMetrics.svelte | 51 ++++--- 2 files changed, 113 insertions(+), 63 deletions(-) diff --git a/src/dataEditor/dataEditorClient.ts b/src/dataEditor/dataEditorClient.ts index 0765a0004..d33219ab4 100644 --- a/src/dataEditor/dataEditorClient.ts +++ b/src/dataEditor/dataEditorClient.ts @@ -473,7 +473,42 @@ export class DataEditorClient implements vscode.Disposable { data: data, }) } + + private async runProfile( + sessionId: string, + startOffset: number, + length: number + ) { + const byteProfile = await profileSession(sessionId, startOffset, length) + const characterCount = await countCharacters( + sessionId, + startOffset, + length + ) + const contentType = await getContentType(sessionId, startOffset, length) + const language = await getLanguage( + sessionId, + startOffset, + length, + characterCount.getByteOrderMark() + ) + return { + byteProfile, + numAscii: numAscii(byteProfile), + language: language.getLanguage(), + contentType: contentType.getContentType(), + characterCount: { + byteOrderMark: characterCount.getByteOrderMark(), + byteOrderMarkBytes: characterCount.getByteOrderMarkBytes(), + singleByteCount: characterCount.getSingleByteChars(), + doubleByteCount: characterCount.getDoubleByteChars(), + tripleByteCount: characterCount.getTripleByteChars(), + quadByteCount: characterCount.getQuadByteChars(), + invalidBytes: characterCount.getInvalidBytes(), + }, + } + } // handle messages from the webview private async messageReceiver(message: EditorMessage) { switch (message.command) { @@ -549,53 +584,49 @@ export class DataEditorClient implements vscode.Disposable { }) break - case MessageCommand.profile: - { - const startOffset: number = message.data.startOffset - const length: number = message.data.length - const byteProfile: number[] = await profileSession( - this.omegaSessionId, - startOffset, - length - ) - const characterCount = await countCharacters( - this.omegaSessionId, - startOffset, - length - ) - const contentTypeResponse = await getContentType( - this.omegaSessionId, - startOffset, - length - ) - const languageResponse = await getLanguage( - this.omegaSessionId, - startOffset, - length, - characterCount.getByteOrderMark() - ) - await this.panel.webview.postMessage({ - command: MessageCommand.profile, - data: { - startOffset: startOffset, - length: length, - byteProfile: byteProfile, - numAscii: numAscii(byteProfile), - language: languageResponse.getLanguage(), - contentType: contentTypeResponse.getContentType(), - characterCount: { - byteOrderMark: characterCount.getByteOrderMark(), - byteOrderMarkBytes: characterCount.getByteOrderMarkBytes(), - singleByteCount: characterCount.getSingleByteChars(), - doubleByteCount: characterCount.getDoubleByteChars(), - tripleByteCount: characterCount.getTripleByteChars(), - quadByteCount: characterCount.getQuadByteChars(), - invalidBytes: characterCount.getInvalidBytes(), - }, - }, - }) - } - break + case MessageCommand.profile: { + const startOffset: number = message.data.startOffset + const length: number = message.data.length + const target: string | undefined = message.data.target + + let sessionId = this.omegaSessionId + let isDiskProfile = false + + try { + if (target === 'disk') { + const tempSession = await createSession( + this.fileToEdit, + undefined, + checkpointPath + ) + sessionId = tempSession.getSessionId() + addActiveSession(sessionId) + isDiskProfile = true + } + + const profileData = await this.runProfile( + sessionId, + startOffset, + length + ) + + await this.panel.webview.postMessage({ + command: MessageCommand.profile, + data: { + startOffset, + length, + ...profileData, + }, + }) + } finally { + if (isDiskProfile) { + await removeActiveSession(sessionId) + } + } + + break +} + case MessageCommand.clearChanges: if ( diff --git a/src/svelte/src/components/DataMetrics/DataMetrics.svelte b/src/svelte/src/components/DataMetrics/DataMetrics.svelte index f54148d47..e28ba0f71 100644 --- a/src/svelte/src/components/DataMetrics/DataMetrics.svelte +++ b/src/svelte/src/components/DataMetrics/DataMetrics.svelte @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -->
+
+ +
{#if title.length > 0}

{title}

From b88ef203238a9903464577da76ff135f801b8027 Mon Sep 17 00:00:00 2001 From: Tejas Tiwari Date: Sun, 11 Jan 2026 16:25:18 +0530 Subject: [PATCH 2/2] fix: apply Prettier formatting to Data Editor profiling Signed-off-by: Tejas Tiwari --- src/dataEditor/dataEditorClient.ts | 83 +++++++++---------- .../components/DataMetrics/DataMetrics.svelte | 56 ++++++------- 2 files changed, 67 insertions(+), 72 deletions(-) diff --git a/src/dataEditor/dataEditorClient.ts b/src/dataEditor/dataEditorClient.ts index d33219ab4..e5cee31be 100644 --- a/src/dataEditor/dataEditorClient.ts +++ b/src/dataEditor/dataEditorClient.ts @@ -473,18 +473,14 @@ export class DataEditorClient implements vscode.Disposable { data: data, }) } - + private async runProfile( sessionId: string, startOffset: number, length: number ) { const byteProfile = await profileSession(sessionId, startOffset, length) - const characterCount = await countCharacters( - sessionId, - startOffset, - length - ) + const characterCount = await countCharacters(sessionId, startOffset, length) const contentType = await getContentType(sessionId, startOffset, length) const language = await getLanguage( sessionId, @@ -584,49 +580,48 @@ export class DataEditorClient implements vscode.Disposable { }) break - case MessageCommand.profile: { - const startOffset: number = message.data.startOffset - const length: number = message.data.length - const target: string | undefined = message.data.target + case MessageCommand.profile: { + const startOffset: number = message.data.startOffset + const length: number = message.data.length + const target: string | undefined = message.data.target - let sessionId = this.omegaSessionId - let isDiskProfile = false - - try { - if (target === 'disk') { - const tempSession = await createSession( - this.fileToEdit, - undefined, - checkpointPath - ) - sessionId = tempSession.getSessionId() - addActiveSession(sessionId) - isDiskProfile = true - } + let sessionId = this.omegaSessionId + let isDiskProfile = false - const profileData = await this.runProfile( - sessionId, - startOffset, - length - ) + try { + if (target === 'disk') { + const tempSession = await createSession( + this.fileToEdit, + undefined, + checkpointPath + ) + sessionId = tempSession.getSessionId() + addActiveSession(sessionId) + isDiskProfile = true + } - await this.panel.webview.postMessage({ - command: MessageCommand.profile, - data: { - startOffset, - length, - ...profileData, - }, - }) - } finally { - if (isDiskProfile) { - await removeActiveSession(sessionId) - } - } + const profileData = await this.runProfile( + sessionId, + startOffset, + length + ) - break -} + await this.panel.webview.postMessage({ + command: MessageCommand.profile, + data: { + startOffset, + length, + ...profileData, + }, + }) + } finally { + if (isDiskProfile) { + await removeActiveSession(sessionId) + } + } + break + } case MessageCommand.clearChanges: if ( diff --git a/src/svelte/src/components/DataMetrics/DataMetrics.svelte b/src/svelte/src/components/DataMetrics/DataMetrics.svelte index e28ba0f71..9b597a610 100644 --- a/src/svelte/src/components/DataMetrics/DataMetrics.svelte +++ b/src/svelte/src/components/DataMetrics/DataMetrics.svelte @@ -156,28 +156,28 @@ limitations under the License. }, }) } - + let lastProfileTarget: 'editor' | 'disk' | null = null let lastRequestedTarget: 'editor' | 'disk' = 'editor' function requestSessionProfile(startOffset: number, length: number) { - lastRequestedTarget = profileTarget - setStatusMessage( - `Profiling bytes from ${startOffset} to ${startOffset + length}...`, - 0 - ) - vscode.postMessage({ - command: MessageCommand.profile, - data: { - startOffset, - length, - target: profileTarget === 'disk' ? 'disk' : undefined, - }, - }) -} -$: if (profileTarget !== lastProfileTarget) { - lastProfileTarget = profileTarget - requestSessionProfile(startOffset, length) -} + lastRequestedTarget = profileTarget + setStatusMessage( + `Profiling bytes from ${startOffset} to ${startOffset + length}...`, + 0 + ) + vscode.postMessage({ + command: MessageCommand.profile, + data: { + startOffset, + length, + target: profileTarget === 'disk' ? 'disk' : undefined, + }, + }) + } + $: if (profileTarget !== lastProfileTarget) { + lastProfileTarget = profileTarget + requestSessionProfile(startOffset, length) + } function handleInputEnter(e: CustomEvent) { switch (e.detail.id) { case 'start-offset-input': @@ -290,7 +290,7 @@ $: if (profileTarget !== lastProfileTarget) { window.addEventListener('message', (msg) => { switch (msg.data.command) { case MessageCommand.profile: - if(msg.data.data?.target && msg.data.data.target !== profileTarget) { + if (msg.data.data?.target && msg.data.data.target !== profileTarget) { // ignore messages not for the current profile target break } @@ -329,14 +329,14 @@ $: if (profileTarget !== lastProfileTarget) {
- -
+ +
{#if title.length > 0}

{title}