Copilot commented on code in PR #1647:
URL: https://github.com/apache/daffodil-vscode/pull/1647#discussion_r3177357862


##########
build/package/LICENSE:
##########
@@ -2202,6 +2202,22 @@ conditions of the following licenses.
     under the terms of the GNU Lesser General Public License version 2.1
     as published by the Free Software Foundation.
 
+- 'lightningcss' in extension/dist/ext/extension.js
+- 'lightningcss' in node_modules/vite
+  This product bundles 'lightningcss' from the above files.
+  These files are available under the MPL 2.0 license:
+
+    Most of the open source code in the Saxon product is governed by the 
Mozilla Public
+    License version 2.0, which is reproduced below.
+
+- 'sax' in extension/dist/ext/extension.js
+- 'sax' in node_modules/vite
+  This product bundles 'sax' from the above files.
+  These files are available under the BlueOak-1.0.0 license:
+
+    Most of the open source code in the Saxon product is governed by the Blue 
Oak Model License

Review Comment:
   The bundled-license preamble you added for both `lightningcss` and `sax` 
says these files are part of 'the Saxon product', which is factually unrelated 
to either dependency. Shipping the generated LICENSE with incorrect package 
descriptions makes the bundled-license report inaccurate.
   



##########
src/svelte/src/components/DataMetrics/DataMetrics.svelte:
##########
@@ -279,39 +273,39 @@ limitations under the License.
   }
 
   onMount(() => {
-    // Handle messages sent from the extension to the webview
-    window.addEventListener('message', (msg) => {
-      switch (msg.data.command) {
-        case MessageCommand.profile:
-          numAscii = msg.data.data.numAscii as number
-          byteProfile = msg.data.data.byteProfile as number[]
-          language = msg.data.data.language as string
-          contentType = msg.data.data.contentType as string
-
-          // character count data
-          characterCountData.byteOrderMark = msg.data.data.characterCount
-            .byteOrderMark as string
-          characterCountData.byteOrderMarkBytes = msg.data.data.characterCount
-            .byteOrderMarkBytes as number
-          characterCountData.singleByteCount = msg.data.data.characterCount
-            .singleByteCount as number
-          characterCountData.doubleByteCount = msg.data.data.characterCount
-            .doubleByteCount as number
-          characterCountData.tripleByteCount = msg.data.data.characterCount
-            .tripleByteCount as number
-          characterCountData.quadByteCount = msg.data.data.characterCount
-            .quadByteCount as number
-          characterCountData.invalidBytes = msg.data.data.characterCount
-            .invalidBytes as number
-
-          setStatusMessage(
-            `Profiled bytes from ${startOffset} to ${startOffset + length}`
-          )
-          break
-        default:
-          break // do nothing
-      }
+    addListener('profile', (data) => {
+      const {
+        numAscii,
+        byteProfile,
+        characterCount,
+        contentType,
+        language,
+        length,
+        startOffset,
+      } = data
+      asciiCount = numAscii
+      profileBytes = byteProfile
+      content = contentType
+      lang = language
+      // character count data
+      characterCountData.byteOrderMark = characterCount.byteOrderMark as string
+      characterCountData.byteOrderMarkBytes =
+        characterCount.byteOrderMarkBytes as number
+      characterCountData.singleByteCount =
+        characterCount.singleByteCount as number
+      characterCountData.doubleByteCount =
+        characterCount.doubleByteCount as number
+      characterCountData.tripleByteCount =
+        characterCount.tripleByteCount as number
+      characterCountData.quadByteCount = characterCount.quadByteCount as number
+      characterCountData.invalidBytes = characterCount.invalidBytes as number
+
+      setStatusMessage(
+        `Profiled bytes from ${startOffset} to ${startOffset + length}`
+      )
     })
+    length = length < 0 ? DATA_PROFILE_MAX_LENGTH : length

Review Comment:
   `length` is now only defaulted when it is negative, but the parent still 
initializes the profiler with `length = 0`. On first open this sends `profile { 
startOffset: 0, length: 0 }`, so the profiler requests an empty range instead 
of profiling the file's initial segment.
   



##########
src/svelte/src/components/Header/fieldsets/Settings.svelte:
##########
@@ -28,30 +28,45 @@ limitations under the License.
   import FlexContainer from '../../layouts/FlexContainer.svelte'
   import { UIThemeCSSClass } from '../../../utilities/colorScheme'
   import ViewportVisibilityIcon from 
'../../Icons/ViewportVisibilityIcon.svelte'
-  import { MessageCommand } from '../../../utilities/message'
 
+  import {
+    fileMetricsState,
+    isRegularSizedFile,
+    saveable,
+  } from './FileMetrics.svelte.ts'
+
+  const { addListener } = getUIMessegnerCtx()
   /* DEBUG_ONLY_START */
   import { getDebugVarContext } from '../../Debug/'
+  import { getUIMessegnerCtx } from 'utilities/messageContext.svelte.ts'

Review Comment:
   `getUIMessegnerCtx()` is called outside the `DEBUG_ONLY` block, but its 
import sits inside that block. The production build strips lines 39-64, so the 
import disappears while line 38 remains, which leaves `getUIMessegnerCtx` 
undefined and breaks the non-debug Svelte build.



##########
src/svelte/src/components/DataDisplays/CustomByteDisplay/DataLineFeed.svelte:
##########
@@ -562,36 +554,36 @@ limitations under the License.
   }
 
   window.addEventListener('keydown', navigation_keydown_event)
-  window.addEventListener('message', (msg) => {
-    switch (msg.data.command) {
-      case MessageCommand.viewportRefresh:
-        if (awaitViewportSeek) {
-          awaitViewportSeek = false
-          $dataFeedLineTop = Math.max(
-            0,
-            Math.min(lineTopMaxViewport, $dataFeedLineTop)
-          )
-          if ($selectionDataStore.active)
-            selectedByteElement = document.getElementById(
-              $selectedByte.offset.toString()
-            ) as HTMLDivElement
-        }
-        break
-      case 'daffodil.data':
-        const { bytePos1b } = msg.data.data
-        if (!bytePosIsDisplayable(bytePos1b - 1)) {
-          $seekOffsetInput = bytePos1b.toString(addressRadix)
-          eventDispatcher('seek')
-        }
-        $dfdlBytePos = bytePos1b - 1
-        break
+
+  addListener('viewportRefresh', (data) => {
+    if (awaitViewportSeek) {
+      awaitViewportSeek = false
+      $dataFeedLineTop = Math.max(
+        0,
+        Math.min(lineTopMaxViewport, $dataFeedLineTop)
+      )
+      if ($selectionDataStore.active)
+        selectedByteElement = document.getElementById(
+          $selectedByte.offset.toString()
+        ) as HTMLDivElement
     }
   })
+  if (isUIDebugAttached(getUIMsgId())) {
+    addListener('bytePos1b', (data) => {
+      const { bytePos1b } = data
+      if (!bytePosIsDisplayable(bytePos1b - 1)) {
+        $seekOffsetInput = bytePos1b.toString(addressRadix)
+        eventDispatcher('seek')
+      }
+      $dfdlBytePos = bytePos1b - 1
+    })
+  }

Review Comment:
   This listener is only attached when the initial UI id already contains the 
`dfdl-` prefix. That means an editor opened before a DFDL session starts will 
never subscribe to `bytePos1b`, even after the matching debug session becomes 
active later, so live byte-position tracking regresses unless the editor is 
opened after debugging has already begun.
   



##########
src/dataEditor/dataEditorClient.ts:
##########
@@ -846,16 +870,18 @@ export class DataEditorClient implements 
vscode.Disposable {
     }
 
     if (saved) {
-      this.fileToEdit = fileToSave
       const fileSize = await getComputedFileSize(this.omegaSessionId)
-      await this.panel.webview.postMessage({
-        command: MessageCommand.fileInfo,
-        data: {
+      if (this.fileToEdit !== fileToSave) {
+        this.fileToEdit = fileToSave
+        this.panel.postMessage('saveAs', {
           computedFileSize: fileSize,
-          diskFileSize: fileSize,
-          fileName: fileToSave,
-        },
-      })
+          newFilePath: this.fileToEdit,
+        })

Review Comment:
   When `Save As` changes `this.fileToEdit`, the `OPEN_EDITORS` index is not 
updated from the old path to the new one. After this, `isActive()` starts 
returning `false`, disposing the editor deletes the wrong key, and reopening 
the original file is incorrectly treated as a duplicate because the stale map 
entry is left behind.



##########
src/svelte/src/App.svelte:
##########
@@ -64,21 +56,34 @@ limitations under the License.
   } from './components/DataDisplays/CustomByteDisplay/BinaryData'
   import { byte_count_divisible_offset } from './utilities/display'
   import Help from './components/layouts/Help.svelte'
-  import { viewportByteIndicators } from 'utilities/highlights'
+  import { EditByteModes, type BytesPerRow } from 'ext_types'
+  import { VIEWPORT_SCROLL_INCREMENT } from './stores/configuration'
+  import { vscode } from './utilities/vscode'
+  import { isRegularSizedFile } from 
'./components/Header/fieldsets/FileMetrics.svelte.ts'
+  import { viewportByteIndicators } from 'utilities/highlights.ts'
+  import {
+    getUIMessegnerCtx,
+    setUIMessegnerCtx,
+  } from 'utilities/messageContext.svelte.ts'
+
+  let { mountTarget }: { mountTarget: HTMLElement } = $props<{
+    mountTarget: HTMLElement
+  }>()
+
+  const uiMsgId = mountTarget.attributes['extension_msg_id'].value
+  setUIMessegnerCtx(vscode.getMessenger(uiMsgId))
+  const { addListener, postMessage } = getUIMessegnerCtx()

Review Comment:
   `App.svelte` now assumes a `mountTarget` prop is always present and 
immediately dereferences `mountTarget.attributes[...]`, but the debug 
entrypoint still renders `<App />` with no props 
(`src/svelte/src/App.debug.svelte:22-24`). Running the data editor in 
`DEBUG_DATAEDITOR=on` will therefore crash before the UI finishes mounting.
   



##########
src/svelte/src/App.svelte:
##########
@@ -64,21 +56,34 @@ limitations under the License.
   } from './components/DataDisplays/CustomByteDisplay/BinaryData'
   import { byte_count_divisible_offset } from './utilities/display'
   import Help from './components/layouts/Help.svelte'
-  import { viewportByteIndicators } from 'utilities/highlights'
+  import { EditByteModes, type BytesPerRow } from 'ext_types'
+  import { VIEWPORT_SCROLL_INCREMENT } from './stores/configuration'
+  import { vscode } from './utilities/vscode'
+  import { isRegularSizedFile } from 
'./components/Header/fieldsets/FileMetrics.svelte.ts'
+  import { viewportByteIndicators } from 'utilities/highlights.ts'
+  import {
+    getUIMessegnerCtx,
+    setUIMessegnerCtx,
+  } from 'utilities/messageContext.svelte.ts'
+
+  let { mountTarget }: { mountTarget: HTMLElement } = $props<{
+    mountTarget: HTMLElement
+  }>()
+
+  const uiMsgId = mountTarget.attributes['extension_msg_id'].value
+  setUIMessegnerCtx(vscode.getMessenger(uiMsgId))
+  const { addListener, postMessage } = getUIMessegnerCtx()

Review Comment:
   `getUIMsgId()` is used later to decide whether the UI should subscribe to 
`bytePos1b`, but the new app initialization never writes the extracted 
`uiMsgId` into this state. As a result `getUIMsgId()` stays `''` and the DFDL 
byte-position listener is never registered, so debug byte-position highlighting 
stops working.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to