You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "scholarsmate (via GitHub)" <gi...@apache.org> on 2023/04/05 04:57:09 UTC

[GitHub] [daffodil-vscode] scholarsmate opened a new pull request, #566: upgrade to omega-edit 0.9.59

scholarsmate opened a new pull request, #566:
URL: https://github.com/apache/daffodil-vscode/pull/566

   Upgrades Ωedit to 0.9.59, and now includes server-side logging, and log rotation.


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on a diff in pull request #566: upgrade to omega-edit 0.9.59

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on code in PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#discussion_r1161997263


##########
package.json:
##########
@@ -42,10 +42,10 @@
     "sbt": "sbt universal:packageBin"
   },
   "dependencies": {
+    "@omega-edit/client": "^0.9.59",

Review Comment:
   Make sure to update this to be `0.9.59` instead of `^0.9.59`. It is preferred to pin packages at a specific version. Having `^` basically allows the install to the version listed or anything newer.



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on a diff in pull request #566: upgrade to omega-edit 0.9.59

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on code in PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#discussion_r1162099679


##########
package.json:
##########
@@ -42,10 +42,10 @@
     "sbt": "sbt universal:packageBin"
   },
   "dependencies": {
+    "@omega-edit/client": "^0.9.59",

Review Comment:
   @scholarsmate This will still apply just with `0.9.60`



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] scholarsmate commented on pull request #566: upgrade to omega-edit 0.9.63

Posted by "scholarsmate (via GitHub)" <gi...@apache.org>.
scholarsmate commented on PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#issuecomment-1507444669

   @arosien, please review.  Thanks!


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on pull request #566: upgrade to omega-edit 0.9.63

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#issuecomment-1507367766

   @scholarsmate You may need to rebase.


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on pull request #566: upgrade to omega-edit 0.9.60

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#issuecomment-1506221726

   @scholarsmate 0.9.62 was released and finally all `omega-edit-native` jars have their library files. So fingers crossed once you bump to that this CI will pass without much of an issue.


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] scholarsmate commented on a diff in pull request #566: upgrade to omega-edit 0.9.60

Posted by "scholarsmate (via GitHub)" <gi...@apache.org>.
scholarsmate commented on code in PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#discussion_r1162116553


##########
package.json:
##########
@@ -42,10 +42,10 @@
     "sbt": "sbt universal:packageBin"
   },
   "dependencies": {
+    "@omega-edit/client": "^0.9.59",

Review Comment:
   I pinned 3 remaining dependencies.  I didn't touch the devDependencies though.  I figured we can tackle those in another PR.  We should probably do that before the 1.3.0 release.



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on pull request #566: upgrade to omega-edit 0.9.59

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#issuecomment-1497598656

   @scholarsmate I think you need to update how the tests try to run the server


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] scholarsmate merged pull request #566: upgrade to omega-edit 0.9.63

Posted by "scholarsmate (via GitHub)" <gi...@apache.org>.
scholarsmate merged PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on pull request #566: upgrade to omega-edit 0.9.60

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#issuecomment-1504055840

   @scholarsmate Also update `src/tests/runTest.ts` to catch the output of `runTests` and use that value in `process.exit` something like this
   
   ```ts
   const runTestsResult = await runTests({
     vscodeExecutablePath,
     extensionDevelopmentPath,
     extensionTestsPath,
   })
   process.exit(runTestsResult)
   ```
   
   This is needed because it seems `yarn test` will sometimes hang without it.


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] scholarsmate commented on a diff in pull request #566: upgrade to omega-edit 0.9.60

Posted by "scholarsmate (via GitHub)" <gi...@apache.org>.
scholarsmate commented on code in PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#discussion_r1162112548


##########
package.json:
##########
@@ -42,10 +42,10 @@
     "sbt": "sbt universal:packageBin"
   },
   "dependencies": {
+    "@omega-edit/client": "^0.9.59",

Review Comment:
   Ah, good point!  Fixing...



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [daffodil-vscode] Shanedell commented on a diff in pull request #566: upgrade to omega-edit 0.9.60

Posted by "Shanedell (via GitHub)" <gi...@apache.org>.
Shanedell commented on code in PR #566:
URL: https://github.com/apache/daffodil-vscode/pull/566#discussion_r1163275984


##########
src/dataEdit/client.ts:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as fs from 'fs'
+import {
+  createSimpleFileLogger,
+  getClientVersion,
+  getServerVersion,
+  setAutoFixViewportDataLength,
+  setLogger,
+  startServer,
+  stopServerUsingPID,
+} from '@omega-edit/client'
+import path from 'path'
+import * as vscode from 'vscode'
+import XDGAppPaths from 'xdg-app-paths'
+import { DataEditWebView } from './dataEditWebView'
+import { initOmegaEditClient } from './utils'
+
+export let omegaEditPort: number = 0
+
+const DEFAULT_OMEGA_EDIT_PORT: number = 9000
+const OMEGA_EDIT_MIN_PORT: number = 1024
+const OMEGA_EDIT_MAX_PORT: number = 65535
+const MAX_LOG_FILES = 5 // Maximum number of log files to keep TODO: make this configurable
+const appDataPath = XDGAppPaths({ name: 'omega_edit' }).data()
+
+function rotateLogFiles(logFile: string) {
+  interface LogFile {
+    path: string
+    ctime: Date
+  }
+
+  if (MAX_LOG_FILES <= 0) {
+    throw new Error('Maximum number of log files must be greater than 0')
+  }
+  if (fs.existsSync(logFile)) {
+    const logDir = path.dirname(logFile)
+    const logFileName = path.basename(logFile)
+
+    // Get list of existing log files
+    const logFiles: LogFile[] = fs
+      .readdirSync(logDir)
+      .filter((file) => file.startsWith(logFileName) && file !== logFileName)
+      .map((file) => ({
+        path: path.join(logDir, file),
+        ctime: fs.statSync(path.join(logDir, file)).ctime,
+      }))
+      .sort((a, b) => b.ctime.getTime() - a.ctime.getTime())
+
+    // Delete oldest log files if maximum number of log files is exceeded
+    while (logFiles.length >= MAX_LOG_FILES) {
+      const fileToDelete = logFiles.pop() as LogFile
+      fs.unlinkSync(fileToDelete.path)
+    }
+
+    // Rename current log file with timestamp and create a new empty file
+    const timestamp = new Date().toISOString().replace(/:/g, '-')
+    fs.renameSync(logFile, path.join(logDir, `${logFileName}.${timestamp}`))
+  }
+}
+
+function getPidFile(serverPort: number) {
+  return path.join(appDataPath, `serv-${serverPort}.pid`)
+}
+
+async function getOmegaEditPort() {
+  if (omegaEditPort === 0) {
+    omegaEditPort = vscode.workspace
+      .getConfiguration('dataEditor')
+      .get<number>('omegaEditServerPort', DEFAULT_OMEGA_EDIT_PORT)
+    if (
+      omegaEditPort <= OMEGA_EDIT_MIN_PORT ||
+      omegaEditPort > OMEGA_EDIT_MAX_PORT
+    ) {
+      omegaEditPort = 0
+      throw new Error('Invalid port')
+    }
+  } else
+    throw new Error('Data Editor currently only supports a single instance')
+}
+
+function setupLogging() {
+  const config = vscode.workspace.getConfiguration('dataEditor')
+  const logFile = config
+    .get<string>(
+      'logFile',
+      '${workspaceFolder}/dataEditor-${omegaEditPort}.log'
+    )
+    ?.replace('${workspaceFolder}', appDataPath)
+    .replace('${omegaEditPort}', omegaEditPort.toString())
+  const logLevel =
+    process.env.OMEGA_EDIT_CLIENT_LOG_LEVEL ||
+    config.get<string>('logLevel', 'info')
+  rotateLogFiles(logFile)
+  setLogger(createSimpleFileLogger(logFile, logLevel))
+  vscode.window.showInformationMessage(
+    `Logging to '${logFile}', at level '${logLevel}'`
+  )
+}
+
+async function serverStop(serverPort: number) {
+  const serverPidFile = getPidFile(serverPort)
+  if (fs.existsSync(serverPidFile)) {
+    const pid = parseInt(fs.readFileSync(serverPidFile).toString())
+    if (await stopServerUsingPID(pid)) {
+      vscode.window.setStatusBarMessage(
+        `Ωedit server stopped on port ${omegaEditPort} with PID ${pid}`,
+        new Promise((resolve) => {
+          setTimeout(() => {
+            resolve(true)
+          }, 2000)
+        })
+      )
+    } else {
+      vscode.window.showErrorMessage(
+        `Ωedit server on port ${omegaEditPort} with PID ${pid} failed to stop`
+      )
+    }
+  }
+}
+
+function generateLogbackConfigFile(
+  logFile: string,
+  logLevel: string = 'INFO'
+): string {
+  const logbackConfig = `<?xml version="1.0" encoding="UTF-8"?>\n
+<configuration>
+    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+        <file>${logFile}</file>
+        <encoder>
+            <pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg MDC: {%mdc}%n</pattern>
+        </encoder>
+    </appender>
+    <root level="${logLevel}">
+        <appender-ref ref="FILE" />
+    </root>
+</configuration>
+`
+  const logbackConfigFile = path.join(
+    appDataPath,
+    `serv-${omegaEditPort}.logconf.xml`
+  )
+  rotateLogFiles(logFile)
+  fs.writeFileSync(logbackConfigFile, logbackConfig)
+  return logbackConfigFile // Return the path to the logback config file
+}
+
+async function serverStart(serverPort: number) {
+  await serverStop(serverPort)
+  const serverStartingText = `Ωedit server starting on port ${omegaEditPort}`
+  const statusBarItem = vscode.window.createStatusBarItem(
+    vscode.StatusBarAlignment.Left
+  )
+  statusBarItem.text = serverStartingText
+  statusBarItem.show()
+
+  let animationFrame = 0
+  const animationInterval = 400 // ms per frame
+  const animationFrames = ['', '.', '..', '...']
+  const animationIntervalId = setInterval(() => {
+    const frame = animationFrames[animationFrame % animationFrames.length]
+    statusBarItem.text = `${serverStartingText} ${frame}`
+    ++animationFrame
+  }, animationInterval)
+
+  const logConfigFile = generateLogbackConfigFile(
+    path.join(appDataPath, `serv-${omegaEditPort}.log`),
+    'INFO' // TODO: Make this configurable
+  )
+  if (!fs.existsSync(logConfigFile)) {
+    throw new Error(`Log config file '${logConfigFile}' not found`)
+  }
+
+  // Start the server and wait up to 10 seconds for it to start
+  const start = performance.now()

Review Comment:
   @scholarsmate This and line 205 where you make `duration` are what causes the tests to break. `performance.now` must not be available during the CLI tests. When I removed them locally my tests ran fine. I think just removing the stuff related to that is fine as the user may not really need to know how fast it came up



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org