Skip to content

Commit b8a2793

Browse files
committed
gRPC demo client
1 parent ee71cf1 commit b8a2793

File tree

7 files changed

+677
-4
lines changed

7 files changed

+677
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ src/version.ts
4545
# either /tmp or XDG or ...
4646
datafile-hex
4747
npm-debug.log
48+
49+
src/omegaEdit/client

package.json

+25-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "apache-daffodil-vscode",
33
"displayName": "Apache Daffodil VS Code Extension",
44
"description": "VS Code extension for Apache Daffodil DFDL schema debugging",
5-
"version": "1.0.0",
5+
"version": "1.2.0",
66
"daffodilVersion": "3.2.1",
7+
"omegaVersion": "0.8.1",
78
"publisher": "asf",
89
"author": "Apache Daffodil",
910
"license": "Apache-2.0",
@@ -40,9 +41,13 @@
4041
"post-build": "rm -rf NOTICE LICENSE && mv tmp.LICENSE LICENSE && mv tmp.NOTICE NOTICE"
4142
},
4243
"dependencies": {
44+
"@grpc/grpc-js": "^1.5.4",
4345
"await-notify": "1.0.1",
4446
"child_process": "^1.0.2",
47+
"google-protobuf": "^3.19.4",
4548
"hexy": "^0.3.1",
49+
"minimist": "^1.2.5",
50+
"omega-edit": "0.8.1",
4651
"unzip-stream": "^0.3.1",
4752
"vscode-debugadapter": "^1.46.0",
4853
"xdg-app-paths": "^7.3.0"
@@ -63,15 +68,16 @@
6368
"webpack-cli": "^3.3.12"
6469
},
6570
"main": "./dist/ext/extension.js",
66-
"browser": "./dist/web/extension.js",
6771
"activationEvents": [
6872
"onDebugResolve:dfdl",
6973
"onDebugDynamicConfigurations:dfdl",
7074
"onCommand:extension.dfdl-debug.getProgramName",
7175
"onCommand:extension.dfdl-debug.getDataName",
7276
"onCommand:extension.dfdl-debug.runEditorContents",
7377
"onCommand:extension.dfdl-debug.debugEditorContents",
74-
"onCommand:launch.config"
78+
"onCommand:launch.config",
79+
"onCommand:omega.grpc",
80+
"onCommand:omega.version"
7581
],
7682
"workspaceTrust": {
7783
"request": "never"
@@ -123,6 +129,12 @@
123129
{
124130
"command": "extension.dfdl-debug.runEditorContents",
125131
"when": "resourceLangId == xml"
132+
},
133+
{
134+
"command": "omega.grpc"
135+
},
136+
{
137+
"command": "omega.version"
126138
}
127139
],
128140
"debug/variables/context": [
@@ -186,6 +198,16 @@
186198
"category": "Daffodil Debug",
187199
"enablement": "!inDebugMode",
188200
"icon": "$(debug-configure)"
201+
},
202+
{
203+
"command": "omega.version",
204+
"title": "Omega Edit Ω Version Info",
205+
"category": "Omega"
206+
},
207+
{
208+
"command": "omega.grpc",
209+
"title": "Omega Edit Ω gRPC Demo",
210+
"category": "Omega"
189211
}
190212
],
191213
"breakpoints": [

src/adapter/activateDaffodilDebug.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as fs from 'fs'
2121
import * as infoset from '../infoset'
2222
import { getConfig, setCurrentConfig } from '../utils'
2323
import * as launchWizard from '../launchWizard/launchWizard'
24+
import * as omegaClient from '../omegaEdit/demoClient'
2425

2526
// Function for setting up the commands for Run and Debug file
2627
function createDebugRunFileConfigs(resource: vscode.Uri, runOrDebug: String) {
@@ -264,6 +265,7 @@ export function activateDaffodilDebug(
264265

265266
infoset.activate(context)
266267
launchWizard.activate(context)
268+
omegaClient.activate(context)
267269
}
268270

269271
class DaffodilConfigurationProvider

src/omegaEdit/demoClient.ts

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as vscode from 'vscode'
19+
import {
20+
ChangeKind,
21+
ChangeRequest,
22+
ViewportDataRequest,
23+
} from 'omega-edit/omega_edit_pb'
24+
import {
25+
client,
26+
getVersion,
27+
newSession,
28+
newViewport,
29+
deleteSession,
30+
// deleteViewport,
31+
randomId,
32+
// uri,
33+
viewportSubscribe,
34+
} from './omegaUtils'
35+
import { startServer, stopServer } from './server'
36+
37+
let serverRunning = false
38+
39+
async function cleanupViewportSession(
40+
sessionId: string,
41+
viewportIds: Array<string>
42+
) {
43+
// viewportIds.forEach(async (vId) => {
44+
// await deleteViewport(vId)
45+
// })
46+
47+
await deleteSession(sessionId)
48+
}
49+
50+
export function activate(ctx: vscode.ExtensionContext) {
51+
ctx.subscriptions.push(
52+
vscode.commands.registerCommand('omega.version', async () => {
53+
if (!serverRunning) {
54+
await startServer(ctx)
55+
serverRunning = true
56+
}
57+
let v = await getVersion()
58+
vscode.window.showInformationMessage(v)
59+
})
60+
)
61+
62+
ctx.subscriptions.push(
63+
vscode.commands.registerCommand('omega.grpc', async () => {
64+
if (!serverRunning) {
65+
await startServer(ctx)
66+
serverRunning = true
67+
}
68+
69+
let panel = vscode.window.createWebviewPanel(
70+
'viewport',
71+
'Ω Edit gRPC',
72+
vscode.ViewColumn.One,
73+
{
74+
enableScripts: true,
75+
}
76+
)
77+
78+
// panel.webview.html = getWebviewContent(uri)
79+
panel.webview.html = getWebviewContent()
80+
81+
let fileToEdit = await vscode.window
82+
.showOpenDialog({
83+
canSelectMany: false,
84+
openLabel: 'Select',
85+
canSelectFiles: true,
86+
canSelectFolders: false,
87+
})
88+
.then((fileUri) => {
89+
if (fileUri && fileUri[0]) {
90+
return fileUri[0].fsPath
91+
}
92+
})
93+
94+
let s = await newSession(fileToEdit)
95+
// panel.webview.postMessage({ command: 'session', text: s })
96+
97+
let vpin = await newViewport(randomId().toString(), s, 0, 1000)
98+
let vp1 = await newViewport(randomId().toString(), s, 0, 64)
99+
let vp2 = await newViewport(randomId().toString(), s, 64, 64)
100+
let vp3 = await newViewport(randomId().toString(), s, 128, 64)
101+
102+
let vpdrin = new ViewportDataRequest()
103+
vpdrin.setViewportId(vpin)
104+
client.getViewportData(vpdrin, (err, r) => {
105+
let data = r?.getData_asB64()
106+
if (data) {
107+
let txt = Buffer.from(data, 'base64').toString('binary')
108+
panel.webview.postMessage({ command: 'input', text: txt })
109+
}
110+
})
111+
112+
await viewportSubscribe(panel, vp1, vp1, 'viewport1', 'hex1')
113+
await viewportSubscribe(panel, vp1, vp2, 'viewport2', null)
114+
await viewportSubscribe(panel, vp1, vp3, 'viewport3', 'hex2')
115+
116+
panel.webview.onDidReceiveMessage(
117+
(message) => {
118+
switch (message.command) {
119+
case 'send':
120+
let b64 = Buffer.from(message.text, 'binary').toString('base64')
121+
let change = new ChangeRequest()
122+
change.setSessionId(s)
123+
change.setKind(ChangeKind.CHANGE_OVERWRITE)
124+
change.setData(b64)
125+
change.setOffset(0)
126+
change.setLength(1000)
127+
client.submitChange(change, (err, r) => {
128+
if (err) console.log(err)
129+
else console.log(r)
130+
})
131+
}
132+
},
133+
undefined,
134+
ctx.subscriptions
135+
)
136+
137+
panel.onDidDispose(
138+
async () => {
139+
await cleanupViewportSession(s, [vpin, vp1, vp2, vp3])
140+
panel.dispose()
141+
await stopServer()
142+
},
143+
undefined,
144+
ctx.subscriptions
145+
)
146+
})
147+
)
148+
}
149+
150+
function getWebviewContent() {
151+
return `<!DOCTYPE html>
152+
<html lang="en">
153+
<head>
154+
<meta charset="UTF-8">
155+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
156+
<title>Omega gRPC</title>
157+
<style>
158+
.grid-container {
159+
display: grid;
160+
grid-gap: 2px 2px;
161+
grid-template-columns: auto auto auto;
162+
background-color: #2196F3;
163+
padding: 5px;
164+
}
165+
166+
.grid-item {
167+
background-color: rgba(255, 255, 255, 0.8);
168+
border: 1px solid rgba(0, 0, 0, 0.8);
169+
padding: 2px;
170+
font-size: 12px;
171+
text-align: left;
172+
color: black;
173+
white-space: pre;
174+
font-family: monospace;
175+
}
176+
</style>
177+
</head>
178+
<body>
179+
<!-- <div id="server">uri</div> -->
180+
<!-- <div id="session">?</div> -->
181+
<div class="grid-container">
182+
<div class="grid-item" id="viewport1">empty</div>
183+
<div class="grid-item" id="viewport2">empty</div>
184+
<div class="grid-item" id="viewport3">empty</div>
185+
<div class="grid-item" id="hex1"></div>
186+
<div class="grid-item"><textarea id="input" rows="10" cols="50" oninput="sendit(this.value)"></textarea></div>
187+
<div class="grid-item" id="hex2"></div>
188+
</div>
189+
<script>
190+
const vscode = acquireVsCodeApi();
191+
function sendit(value) {
192+
vscode.postMessage({
193+
command: 'send',
194+
text: value
195+
})
196+
}
197+
window.addEventListener('message', event => {
198+
const message = event.data;
199+
document.getElementById(message.command).innerHTML = message.text
200+
});
201+
</script>
202+
</body>
203+
</html>`
204+
}

0 commit comments

Comments
 (0)