Skip to content

Commit

Permalink
upgrade Ωedit™ to v0.9.75
Browse files Browse the repository at this point in the history
  • Loading branch information
scholarsmate committed Oct 20, 2023
1 parent 9d43d18 commit f88377c
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 110 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@
"svelte:check": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@omega-edit/client": "0.9.73",
"@omega-edit/client": "0.9.75",
"@viperproject/locate-java-home": "1.1.13",
"@vscode/debugadapter": "1.63.0",
"await-notify": "1.0.1",
"hexy": "0.3.5",
"jsonc-parser": "3.2.0",
"semver": "7.5.4",
"unzip-stream": "0.3.1",
"wait-port": "1.0.4",
"wait-port": "1.1.0",
"xdg-app-paths": "8.3.0"
},
"devDependencies": {
"@tsconfig/svelte": "^5.0.2",
"@types/glob": "^8.0.0",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.1",
"@types/mocha": "^10.0.3",
"@types/node": "^20.8.7",
"@types/vscode": "^1.67.2",
"@types/vscode-webview": "^1.57.2",
"@types/vscode-webview": "^1.57.3",
"@vscode/debugadapter-testsupport": "1.63.0",
"@vscode/test-electron": "2.3.4",
"@vscode/vsce": "2.21.0",
"chai": "^4.3.8",
"concurrently": "^8.2.1",
"@vscode/test-electron": "2.3.5",
"@vscode/vsce": "2.21.1",
"chai": "^4.3.10",
"concurrently": "^8.2.2",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
"css-minimizer-webpack-plugin": "^5.0.1",
Expand All @@ -77,9 +77,9 @@
"prettier": "3.0.3",
"prettier-plugin-svelte": "3.0.3",
"run-func": "^3.0.0",
"sass": "^1.67.0",
"sass": "^1.69.4",
"svelte": "^3.55.0",
"svelte-check": "^3.5.1",
"svelte-check": "^3.5.2",
"svelte-loader": "^3.1.9",
"svelte-preprocess": "^5.0.4",
"ts-loader": "9.4.4",
Expand Down
64 changes: 49 additions & 15 deletions src/dataEditor/dataEditorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getClient,
getClientVersion,
getComputedFileSize,
getContentType,
getCounts,
getLogger,
getServerHeartbeat,
Expand Down Expand Up @@ -248,14 +249,17 @@ export class DataEditorClient implements vscode.Disposable {
assert(this.omegaSessionId.length > 0, 'omegaSessionId is not set')
addActiveSession(this.omegaSessionId)

this.contentType = createSessionResponse.hasContentType()
? (createSessionResponse.getContentType() as string)
: 'unknown'
assert(this.contentType.length > 0, 'contentType is not set')

this.fileSize = createSessionResponse.hasFileSize()
? (createSessionResponse.getFileSize() as number)
: 0

const contentTypeResponse = await getContentType(
this.omegaSessionId,
0,
Math.min(1024, this.fileSize)
)
this.contentType = contentTypeResponse.getContentType()
assert(this.contentType.length > 0, 'contentType is not set')
} catch {
const msg = `Failed to create session for ${this.fileToEdit}`
getLogger().error({
Expand Down Expand Up @@ -669,12 +673,12 @@ async function createDataEditorWebviewPanel(
configureOmegaEditPort()
assert(omegaEditPort > 0, 'omega edit port not configured')

// only start uo the server if one is not already running
// only start up the server if one is not already running
if (!(await checkServerListening(omegaEditPort, OMEGA_EDIT_HOST))) {
await setupLogging()
setAutoFixViewportDataLength(true)
await serverStart()
client = getClient(omegaEditPort, OMEGA_EDIT_HOST)
client = await getClient(omegaEditPort, OMEGA_EDIT_HOST)
assert(
await checkServerListening(omegaEditPort, OMEGA_EDIT_HOST),
'server not listening'
Expand Down Expand Up @@ -1138,9 +1142,9 @@ async function serverStart() {
const animationInterval = 400 // ms per frame
const animationFrames = ['', '.', '..', '...']
const animationIntervalId = setInterval(() => {
const frame = animationFrames[animationFrame % animationFrames.length]
statusBarItem.text = `${serverStartingText} ${frame}`
++animationFrame
statusBarItem.text = `${serverStartingText} ${
animationFrames[++animationFrame % animationFrames.length]
}`
}, animationInterval)
const config = vscode.workspace.getConfiguration('dataEditor')
const logLevel =
Expand All @@ -1152,6 +1156,8 @@ async function serverStart() {
logLevel
)
if (!fs.existsSync(logConfigFile)) {
clearInterval(animationIntervalId)
statusBarItem.dispose()
throw new Error(`Log config file '${logConfigFile}' not found`)
}

Expand All @@ -1173,31 +1179,59 @@ async function serverStart() {
}, SERVER_START_TIMEOUT * 1000)
}),
])) as number | undefined
clearInterval(animationIntervalId)
if (serverPid === undefined || serverPid <= 0) {
statusBarItem.dispose()
throw new Error('Server failed to start or PID is invalid')
}
const clientVersion = getClientVersion()
serverInfo = await getServerInfo()
// this makes sure the server if fully online and ready to take requests
statusBarItem.text = `Initializing Ωedit server on port ${omegaEditPort}`
for (let i = 0; i < 60; ++i) {
try {
await getServerInfo()
break
} catch (err) {
statusBarItem.text = `Initializing Ωedit server on port ${omegaEditPort} (${
i + 1
}/60)`
}
// wait 1 second before trying again
await new Promise((resolve) => {
setTimeout(() => {
resolve(true)
}, 1000)
})
}
try {
serverInfo = await getServerInfo()
} catch (err) {
statusBarItem.dispose()
await serverStop()
throw new Error('Server failed to initialize')
}
statusBarItem.text = `Ωedit server on port ${omegaEditPort} initialized`
const serverVersion = serverInfo.serverVersion
// if the OS is not Windows, check that the server PID matches the one started
// NOTE: serverPid is the PID of the server wrapper script on Windows
if (
!os.platform().toLowerCase().startsWith('win') &&
serverInfo.serverProcessId !== serverPid
) {
statusBarItem.dispose()
throw new Error(
`server PID mismatch ${serverInfo.serverProcessId} != ${serverPid}`
)
}
const clientVersion = getClientVersion()
if (serverVersion !== clientVersion) {
statusBarItem.dispose()
throw new Error(
`Server version ${serverVersion} and client version ${clientVersion} must match`
)
}
// get an initial heartbeat to ensure the server is up and running
// get an initial heartbeat
await getHeartbeat()
clearInterval(animationIntervalId)
statusBarItem.text = `Ωedit server v${serverVersion} started on port ${omegaEditPort} with PID ${serverInfo.serverProcessId}`
statusBarItem.text = `Ωedit server v${serverVersion} ready on port ${omegaEditPort} with PID ${serverInfo.serverProcessId}`
setTimeout(() => {
statusBarItem.dispose()
}, 5000)
Expand Down
Loading

0 comments on commit f88377c

Please sign in to comment.