This is an automated email from the ASF dual-hosted git repository.
shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git
The following commit(s) were added to refs/heads/main by this push:
new f2e3b7a omega-edit updates:
f2e3b7a is described below
commit f2e3b7a9d0216ea578c7c435a1ab4bc6ed1963e8
Author: Shane Dell <[email protected]>
AuthorDate: Mon Dec 5 17:38:01 2022 -0500
omega-edit updates:
- Moved omega-edit server related code to the omega-edit node module.
- Moved omega-edit scala server zip to omega-edit node package.
- Delete build/scripts/omega_edit_download since the scala server is now
bundled in the node package.
- Remove omegaEditServerHash from package.json.
- Display information messages when starting and stopping the omega-edit
server.
- This is to give the developer a notice that it is starting/started or
stopped.
- This replace the terminal being opened displaying the omega-edit server
binding.
- Remove code that kills a java process on windows and any daffodil
debugger on linux/mac as it could be harmful to do that.
Closes #334
---
.gitignore | 2 +-
build/package/.vscodeignore | 2 +-
build/scripts/omega_edit_download.ts | 122 -----------------------------------
package.json | 8 +--
src/daffodilDebugger.ts | 15 +----
src/omega_edit/client.ts | 38 +++++++----
src/omega_edit/server.ts | 85 ------------------------
src/omega_edit/utils.ts | 17 +++++
src/tests/suite/omegaEdit.test.ts | 33 ++++++----
src/utils.ts | 22 +++----
yarn.lock | 8 +--
11 files changed, 82 insertions(+), 270 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0f8424b..c399385 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,4 +53,4 @@ npm-debug.log
tmp.*
# ignore omega-edit scala server package file
-src/omega_edit/omega-edit-scala-server*
+omega-edit-scala-server*
diff --git a/build/package/.vscodeignore b/build/package/.vscodeignore
index 64bafdb..b07d292 100644
--- a/build/package/.vscodeignore
+++ b/build/package/.vscodeignore
@@ -28,5 +28,5 @@
!src/styles/styles.css
!src/omega_edit/omega_edit.js
!src/omega_edit/interface.html
-!src/omega_edit/omega-edit-scala-server*.zip
+!node_modules/omega-edit/omega-edit-scala-server*.zip
!src/language/providers/intellisense/DFDLGeneralFormat.dfdl.xsd
diff --git a/build/scripts/omega_edit_download.ts
b/build/scripts/omega_edit_download.ts
deleted file mode 100644
index faa25f9..0000000
--- a/build/scripts/omega_edit_download.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.
- */
-
-// @ts-nocheck <-- This is needed as this file is basically a JavaScript script
-// but with some TypeScript niceness baked in
-const fs = require('fs')
-const os = require('os')
-const path = require('path')
-const HttpClient = require('typed-rest-client/HttpClient').HttpClient
-const crypto = require('crypto')
-const hashSum = crypto.createHash('sha512')
-
-/**
- * The below classes (Backend, Artifact) are defined similarly in
src/classes/artifact.ts.
- * However for this script to work properly they needed to be redefined in a
more JS style.
- */
-
-class Backend {
- constructor(owner, repo) {
- this.owner = owner
- this.repo = repo
- }
-}
-
-class Artifact {
- constructor(omegaEditVersion) {
- this.omegaEditVersion = omegaEditVersion
- this.name = `omega-edit-scala-server-${this.omegaEditVersion}`
- this.archive = `${this.name}.zip`
- this.archiveUrl = (backend) =>
-
`https://github.com/${backend.owner}/${backend.repo}/releases/download/v${this.omegaEditVersion}/${this.archive}`
- this.scriptName = os.platform().toLowerCase().startsWith('win32')
- ? 'omega-edit-grpc-server.bat'
- : './omega-edit-grpc-server'
- }
-}
-
-// Method to get omega-edit version from a JSON file
-function getOmegaEditPackageVersion(filePath) {
- return JSON.parse(fs.readFileSync(filePath).toString())['dependencies'][
- 'omega-edit'
- ]
-}
-
-// Method to get omegaEditServerHash from a JSON file
-function getOmegaEditServerHash(filePath) {
- return
JSON.parse(fs.readFileSync(filePath).toString())['omegaEditServerHash']
-}
-
-async function downloadServer() {
- // Get omegaEditVersion
- const omegaEditVersion = getOmegaEditPackageVersion('./package.json')
- const artifact = new Artifact(omegaEditVersion)
- const backend = new Backend('ctc-oss', 'omega-edit')
-
- let filePath = path.join('src/omega_edit', artifact.archive).toString()
-
- // Download and setup omega-edit server files
- if (!fs.existsSync(filePath)) {
- // Get omega-edit server of version entered using http client
- const client = new HttpClient('client')
- const artifactUrl = artifact.archiveUrl(backend)
- const response = await client.get(artifactUrl)
-
- if (response.message.statusCode !== 200) {
- const err = new Error(
- `Couldn't download the Ωedit sever backend from ${artifactUrl}.`
- )
- err['httpStatusCode'] = response.message.statusCode
- throw err
- }
-
- // Create zip from rest call
- const file = fs.createWriteStream(filePath)
-
- await new Promise((resolve, reject) => {
- file.on(
- 'error',
- (err) =>
- function () {
- throw err
- }
- )
- const stream = response.message.pipe(file)
-
- stream.on('close', () => {
- try {
- resolve(filePath)
- } catch (err) {
- reject(err)
- }
- })
- })
-
- hashSum.update(fs.readFileSync(filePath))
- if (
- hashSum.digest('hex').toString() !==
- getOmegaEditServerHash('./package.json')
- ) {
- fs.unlinkSync(filePath)
- throw new Error("[ERROR] omega-edit Scala server hashes didn't match")
- }
- }
-}
-
-module.exports = {
- downloadServer: downloadServer,
-}
diff --git a/package.json b/package.json
index ed19b62..891ecef 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,6 @@
"description": "VS Code extension for Apache Daffodil DFDL schema
debugging",
"version": "1.3.0-SNAPSHOT",
"daffodilVersion": "3.4.0",
- "omegaEditServerHash":
"1c11c5711b6cd477023be71d04b070e1289312aaaef5f81fb9ded4e3884b7135ca13e2b2cf7b547e374142167c19789555eeb5d83dbed38ff6dde71c25db5fb7",
"publisher": "asf",
"author": "Apache Daffodil",
"license": "Apache-2.0",
@@ -24,12 +23,11 @@
"url": "https://github.com/apache/daffodil-vscode/issues"
},
"scripts": {
- "omega-edit-download": "node -e
\"require('./build/scripts/omega_edit_download.ts').downloadServer()\"",
"gen-version-ts": "node -p \"'export const LIB_VERSION = ' +
JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
"precompile": "yarn run gen-version-ts",
- "compile": "tsc -p ./ && yarn omega-edit-download",
+ "compile": "tsc -p ./",
"lint": "yarn run prettier src -c",
- "prewatch": "yarn omega-edit-download && yarn run
gen-version-ts",
+ "prewatch": "yarn run gen-version-ts",
"watch": "webpack --watch --devtool nosources-source-map
--config ./build/extension.webpack.config.js",
"webpack": "webpack --mode production --config
./build/extension.webpack.config.js",
"prepackage": "yarn sbt && yarn install && yarn compile && yarn
webpack",
@@ -46,7 +44,7 @@
"child_process": "1.0.2",
"google-protobuf": "3.20.1",
"hexy": "0.3.4",
- "omega-edit": "0.9.24",
+ "omega-edit": "0.9.32",
"unzip-stream": "0.3.1",
"uuid": "^8.3.2",
"vscode-debugadapter": "1.51.0",
diff --git a/src/daffodilDebugger.ts b/src/daffodilDebugger.ts
index a60bfb3..ddd1580 100644
--- a/src/daffodilDebugger.ts
+++ b/src/daffodilDebugger.ts
@@ -120,19 +120,6 @@ export async function getDebugger(
await unzipFile(filePath, rootPath)
}
- // Stop debugger if running
- if (os.platform() === 'win32') {
- // Windows stop debugger if already running
- child_process.execSync(
- 'tskill java 2>nul 1>nul || echo "Java not running"'
- )
- } else {
- // Linux/Mac stop debugger if already running and make sure script is
executable
- child_process.exec(
- "kill -9 $(ps -ef | grep 'daffodil' | grep 'jar' | awk '{ print $2
}') || return 0"
- ) // ensure debugger server not running and
- }
-
// Get program file before debugger starts to avoid timeout
if (config.program.includes('${command:AskForProgramName}')) {
config.program = await vscode.commands.executeCommand(
@@ -193,7 +180,7 @@ export async function getDebugger(
await runScript(
`${rootPath}/daffodil-debugger-${daffodilVersion}-${LIB_VERSION}`,
- artifact,
+ artifact.scriptName,
shellPath,
shellArgs,
{
diff --git a/src/omega_edit/client.ts b/src/omega_edit/client.ts
index 42725e5..935314b 100644
--- a/src/omega_edit/client.ts
+++ b/src/omega_edit/client.ts
@@ -20,12 +20,15 @@ import * as fs from 'fs'
import * as omegaEditSession from 'omega-edit/session'
import * as omegaEditViewport from 'omega-edit/viewport'
import * as omegaEditVersion from 'omega-edit/version'
-import { getServer, stopServer } from './server'
-import { viewportSubscribe } from './utils'
+import { startOmegaEditServer, viewportSubscribe } from './utils'
import { OmegaEdit } from './omega_edit'
import { v4 as uuidv4 } from 'uuid'
-
+import XDGAppPaths from 'xdg-app-paths'
+import { killProcess } from '../utils'
let serverRunning = false
+let serverTerminal: vscode.Terminal | undefined
+const xdgAppPaths = XDGAppPaths({ name: 'omega_edit' })
+let rootPath = xdgAppPaths.data()
// Method to get omega-edit version from a JSON file
export function getOmegaEditPackageVersion(filePath: fs.PathLike) {
@@ -44,6 +47,20 @@ async function cleanupViewportSession(
await omegaEditSession.destroySession(sessionId)
}
+async function commonOmegaEdit(
+ ctx: vscode.ExtensionContext,
+ startServer: boolean,
+ omegaEditPackageVersion: string
+) {
+ if (!serverRunning && startServer) {
+ ;[serverTerminal, serverRunning] = await startOmegaEditServer(
+ ctx,
+ rootPath,
+ omegaEditPackageVersion
+ )
+ }
+}
+
export function activate(ctx: vscode.ExtensionContext) {
const omegaEditPackageVersion = getOmegaEditPackageVersion(
ctx.asAbsolutePath('./package.json')
@@ -53,11 +70,7 @@ export function activate(ctx: vscode.ExtensionContext) {
vscode.commands.registerCommand(
'omega_edit.version',
async (startServer: boolean = true) => {
- if (!serverRunning && startServer) {
- await getServer(ctx, omegaEditPackageVersion)
- serverRunning = true
- }
-
+ await commonOmegaEdit(ctx, startServer, omegaEditPackageVersion)
return await omegaEditVersion.getVersion()
}
)
@@ -71,10 +84,7 @@ export function activate(ctx: vscode.ExtensionContext) {
startServer: boolean = true,
subscribeToViewports: boolean = true
) => {
- if (!serverRunning && startServer) {
- await getServer(ctx, omegaEditPackageVersion)
- serverRunning = true
- }
+ await commonOmegaEdit(ctx, startServer, omegaEditPackageVersion)
return await createOmegaEditWebviewPanel(
ctx,
@@ -182,7 +192,9 @@ async function createOmegaEditWebviewPanel(
async () => {
await cleanupViewportSession(s, [vpAll, vp1, vp2, vp3])
panel.dispose()
- serverRunning = !(await stopServer())
+ await serverTerminal?.processId.then(async (id) => await killProcess(id))
+ serverRunning = false
+ vscode.window.showInformationMessage('omega-edit server stopped!')
},
undefined,
ctx.subscriptions
diff --git a/src/omega_edit/server.ts b/src/omega_edit/server.ts
deleted file mode 100644
index a2ea73e..0000000
--- a/src/omega_edit/server.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 vscode from 'vscode'
-import * as fs from 'fs'
-import * as path from 'path'
-import { Artifact } from '../classes/artifact'
-import XDGAppPaths from 'xdg-app-paths'
-import { runScript, unzipFile, killProcess } from '../utils'
-
-const xdgAppPaths = XDGAppPaths({ name: 'omega_edit' })
-
-export async function getServer(
- ctx: vscode.ExtensionContext,
- omegaEditVersion: string
-) {
- // Get omegaEditVersion
- const artifact = new Artifact(
- 'omega-edit-scala-server',
- omegaEditVersion,
- 'omega-edit-grpc-server'
- )
-
- if (vscode.workspace.workspaceFolders) {
- let rootPath = xdgAppPaths.data()
-
- // If data and app directories for holding omega server script do not
exist create them
- if (!fs.existsSync(rootPath)) {
- fs.mkdirSync(rootPath, { recursive: true })
- }
-
- // Download and setup omega-edit server files
- if (!fs.existsSync(`${rootPath}/${artifact.name}`)) {
- const filePath = path.join(
- ctx.asAbsolutePath('./src/omega_edit/'),
- artifact.archive
- )
-
- // Unzip file and remove zip
- await unzipFile(filePath, rootPath)
- }
-
- await runScript(
- `${rootPath}/omega-edit-scala-server-${omegaEditVersion}`,
- artifact
- )
- }
-}
-
-// Function for stopping debugging
-export async function stopServer(terminal: vscode.Terminal | null = null) {
- if (terminal !== null) {
- terminal.processId.then(async (id) => await killProcess(id))
- return true
- } else {
- const action = await vscode.window.showInformationMessage(
- 'Stop Ωedit server?',
- 'Yes',
- 'No'
- )
-
- if (action === 'Yes') {
- vscode.window.activeTerminal?.processId.then(
- async (id) => await killProcess(id)
- )
- return true
- }
-
- return false
- }
-}
diff --git a/src/omega_edit/utils.ts b/src/omega_edit/utils.ts
index 7925024..3b2455f 100644
--- a/src/omega_edit/utils.ts
+++ b/src/omega_edit/utils.ts
@@ -23,6 +23,8 @@ import {
ViewportDataRequest,
} from 'omega-edit/omega_edit_pb'
import { getClient, ALL_EVENTS } from 'omega-edit/settings'
+import * as omegaEditServer from 'omega-edit/server'
+import { runScript } from '../utils'
const client = getClient()
@@ -132,3 +134,18 @@ export async function viewportSubscribe(
// data request not ran right away, so this ensures the views are populated
await setViewportDataForPanel(panel, vp2, commandViewport, commandHex)
}
+
+export async function startOmegaEditServer(
+ ctx: vscode.ExtensionContext,
+ rootPath: string,
+ omegaEditPackageVersion: string
+): Promise<[vscode.Terminal, boolean]> {
+ const [scriptName, scriptPath] = await omegaEditServer.setupServer(
+ rootPath,
+ omegaEditPackageVersion,
+ ctx.asAbsolutePath('./node_modules/omega-edit')
+ )
+
+ let terminal = await runScript(scriptPath, scriptName)
+ return [terminal, true]
+}
diff --git a/src/tests/suite/omegaEdit.test.ts
b/src/tests/suite/omegaEdit.test.ts
index 5e3c335..21efb89 100644
--- a/src/tests/suite/omegaEdit.test.ts
+++ b/src/tests/suite/omegaEdit.test.ts
@@ -23,30 +23,30 @@ import { Artifact, Backend } from '../../classes/artifact'
import * as omegaEditClient from '../../omega_edit/client'
import { unzipFile, runScript, killProcess } from '../../utils'
import { before, after } from 'mocha'
+import * as fs from 'fs'
+const PROJECT_ROOT = path.join(__dirname, '../../../')
const wait_port = require('wait-port')
-const omegaEditPackagePath = path.join(__dirname, '../../../src/omega_edit')
+
+const omegaEditPackagePath = path.join(PROJECT_ROOT, 'node_modules/omega-edit')
+const omegaEditVersion = omegaEditClient.getOmegaEditPackageVersion(
+ path.join(PROJECT_ROOT, 'package.json')
+)
const localArtifact = new Artifact(
'omega-edit-scala-server',
- omegaEditClient.getOmegaEditPackageVersion(
- path.join(__dirname, '../../../package.json')
- ),
+ omegaEditVersion,
'omega-edit-grpc-server'
)
-const testDfdlFile = path.join(
- __dirname,
- '../../../src/tests/data/test.dfdl.xsd'
-)
+const extractedFolder = path.join(PROJECT_ROOT, localArtifact.name)
+const testDfdlFile = path.join(PROJECT_ROOT, 'src/tests/data/test.dfdl.xsd')
export async function runServerForTests() {
- const extractedFolder = `${omegaEditPackagePath}/${localArtifact.name}`
-
- await unzipFile(
+ fs.copyFileSync(
`${omegaEditPackagePath}/${localArtifact.name}.zip`,
- omegaEditPackagePath
+ `${extractedFolder}.zip`
)
-
- return await runScript(`${extractedFolder}`, localArtifact)
+ await unzipFile(`${extractedFolder}.zip`, PROJECT_ROOT)
+ return await runScript(`${extractedFolder}`, localArtifact.scriptName)
}
suite('omega-edit Test Suite', () => {
@@ -58,6 +58,11 @@ suite('omega-edit Test Suite', () => {
after(async () => {
await terminal.processId.then(async (id) => await killProcess(id))
+ fs.rmSync(`${PROJECT_ROOT}/${localArtifact.name}.zip`)
+ fs.rmSync(`${PROJECT_ROOT}/${localArtifact.name}`, {
+ recursive: true,
+ force: true,
+ })
})
test('Test toggle.experimental', async () => {
diff --git a/src/utils.ts b/src/utils.ts
index 36440de..d116930 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -18,9 +18,9 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as unzip from 'unzip-stream'
-import { Artifact } from './classes/artifact'
import * as os from 'os'
import * as child_process from 'child_process'
+import path from 'path'
const wait_port = require('wait-port')
const defaultConf = vscode.workspace.getConfiguration()
@@ -183,9 +183,11 @@ export async function killProcess(id: number | undefined) {
}
}
+export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))
+
export async function runScript(
scriptPath: string,
- artifact: Artifact,
+ scriptName: string,
shellPath: string | null = null,
shellArgs: string[] = [],
env:
@@ -196,23 +198,21 @@ export async function runScript(
type: string = '',
hideTerminal: boolean = false
) {
- const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))
-
if (!os.platform().toLowerCase().startsWith('win')) {
child_process.execSync(
- `chmod +x ${scriptPath.replace(
- ' ',
- '\\ '
- )}/bin/${artifact.scriptName.replace('./', '')}`
+ `chmod +x ${scriptPath.replace(' ', '\\ ')}/bin/${scriptName.replace(
+ './',
+ ''
+ )}`
)
}
// Start server in terminal based on scriptName
let terminal = vscode.window.createTerminal({
- name: artifact.scriptName,
- cwd: `${scriptPath}/bin`,
+ name: scriptName,
+ cwd: path.join(scriptPath, 'bin'),
hideFromUser: false,
- shellPath: shellPath !== null ? shellPath : artifact.scriptName,
+ shellPath: shellPath !== null ? shellPath : scriptName,
shellArgs: shellArgs,
env: env,
})
diff --git a/yarn.lock b/yarn.lock
index dba147c..5ec0c53 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1658,10 +1658,10 @@ object-inspect@^1.9.0:
resolved
"https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.2.tgz#c0641f26394532f28ab8d796ab954e43c009a8ea"
integrity
sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==
[email protected]:
- version "0.9.24"
- resolved
"https://registry.yarnpkg.com/omega-edit/-/omega-edit-0.9.24.tgz#b7c40e320ec06416d02afc1134a51095b39ecedd"
- integrity
sha512-myPLWkc1TVSOXIiqhIn3WdvCUdvSb9LDmYFM63E6naK6dphbGKM3ClFBx0mQsQ6XKSBkrJ9Gxcw09dnS+CUViA==
[email protected]:
+ version "0.9.32"
+ resolved
"https://registry.yarnpkg.com/omega-edit/-/omega-edit-0.9.32.tgz#29006dcb23843f644f15e9b1919a2c756e231a7b"
+ integrity
sha512-zRwvq/+t6hKJafKjA9WUk76cc0SZP/CLjcLmFCi8Kx7orPxA3jRtCYWwYbgrhri3sQ3Xz0kxPFBDd+dCz47tHw==
dependencies:
"@grpc/grpc-js" "^1.7.1"
"@types/google-protobuf" "^3.15.5"