@@ -9,7 +9,6 @@ import { SyncRequestDispatch } from '../../shared/sync-request';
9
9
import { polyfillStreams , jsonFromChunks , stringFromChunks } from './streaming' ;
10
10
import { loadWasm , WasmEngine , WasmState , WasmStateChangeEvent } from './wasm/engine' ;
11
11
import * as wasiWasm from '@vscode/wasm-wasi' ;
12
- import { assertNever } from '../../shared/assert-never' ;
13
12
14
13
interface WasmToCodeMessage {
15
14
type : string ;
@@ -65,7 +64,7 @@ type CodeToWasmCommand =
65
64
export class MSBuildLogDocument implements vscode . CustomDocument {
66
65
disposables : DisposableLike [ ] ;
67
66
readonly _requestDispatch : SyncRequestDispatch < WasmToCodeReply > ;
68
- constructor ( readonly uri : Uri , readonly _engine : WasmEngine , readonly out : vscode . LogOutputChannel ) {
67
+ constructor ( readonly _pipeIn : wasiWasm . Writable , readonly uri : Uri , readonly _engine : WasmEngine , readonly out : vscode . LogOutputChannel ) {
69
68
this . disposables = [ ] ;
70
69
this . disposables . push ( this . _engine ) ;
71
70
this . disposables . push ( this . _requestDispatch = new SyncRequestDispatch < WasmToCodeReply > ( ) ) ;
@@ -83,7 +82,7 @@ export class MSBuildLogDocument implements vscode.CustomDocument {
83
82
isLive ( ) : boolean { return this . _engine . isLive ( ) ; }
84
83
85
84
gotStdOut ( value : unknown ) {
86
- this . out . info ( `received from wasm process: ${ value } ` ) ;
85
+ this . out . info ( `received from wasm process: ${ JSON . stringify ( value ) } ` ) ;
87
86
if ( isWasmToCodeMessage ( value ) ) {
88
87
switch ( value . type ) {
89
88
case 'ready' :
@@ -113,26 +112,24 @@ export class MSBuildLogDocument implements vscode.CustomDocument {
113
112
get onStateChange ( ) : vscode . Event < WasmStateChangeEvent > { return this . _engine . onStateChange ; }
114
113
115
114
async postCommand ( c : CodeToWasmCommand ) : Promise < void > {
116
- let requestId = c . requestId ;
117
- let command = c . command ;
118
- let extra : string = '' ;
119
- switch ( c . command ) {
120
- case 'root' :
121
- break ;
122
- case 'node' :
123
- extra = `${ c . nodeId } \n` ;
124
- break ;
125
- case 'manyNodes' :
126
- extra = `${ c . nodeId } \n${ c . count } \n` ;
127
- break ;
128
- default :
129
- assertNever ( c ) ;
130
- break ;
131
- }
132
- await this . _engine . process . stdin ?. write ( `${ requestId } \n${ command } \n${ extra } ` , 'utf-8' ) ;
115
+ const json = JSON . stringify ( c ) ;
116
+ const encoder = new TextEncoder ( ) ;
117
+ const jsonBytes = encoder . encode ( json ) ;
118
+ const len = jsonBytes . byteLength ;
119
+ this . out ?. info ( `sending ${ len } followed by <<${ json } >>` ) ;
120
+ const lenBuf = new ArrayBuffer ( 4 ) ;
121
+ const int32View = new Int32Array ( lenBuf ) ;
122
+ int32View [ 0 ] = len ;
123
+ const int8View = new Uint8Array ( lenBuf ) ;
124
+ int8View [ 0 ] ++ ;
125
+ int8View [ 1 ] ++ ;
126
+ int8View [ 2 ] ++ ;
127
+ int8View [ 3 ] ++ ;
128
+ await this . _pipeIn . write ( int8View ) ;
129
+ await this . _pipeIn . write ( jsonBytes ) ;
130
+ await this . _pipeIn . write ( '\n' , 'utf-8' ) ;
133
131
}
134
132
135
-
136
133
async requestRoot ( ) : Promise < WasmToCodeNodeReply > {
137
134
const [ requestId , replyPromise ] = this . _requestDispatch . promiseReply < WasmToCodeNodeReply > ( ) ;
138
135
this . out . info ( `requested root id=${ requestId } ` ) ;
@@ -172,9 +169,16 @@ export async function openMSBuildLogDocument(context: vscode.ExtensionContext, u
172
169
out . info ( `opening msbuild log ${ uri } ` ) ;
173
170
const wasm = await loadWasm ( ) ;
174
171
await polyfillStreams ( ) ;
172
+ //const memFS = await wasm.createMemoryFileSystem();
175
173
const rootFileSystem = await wasm . createRootFileSystem ( [
176
- { kind : 'workspaceFolder' }
174
+ { kind : 'workspaceFolder' } ,
175
+ //{
176
+ // kind: 'memoryFileSystem',
177
+ // mountPoint: '/pipe',
178
+ // fileSystem: memFS
179
+ //},
177
180
] ) ;
181
+ //const pipeIn = memFS.createWritable('./input', 'utf-8');
178
182
const pipeIn = wasm . createWritable ( ) ;
179
183
const pipeOut = wasm . createReadable ( ) ;
180
184
const pipeErr = wasm . createReadable ( ) ;
@@ -185,7 +189,7 @@ export async function openMSBuildLogDocument(context: vscode.ExtensionContext, u
185
189
out : { 'kind' : 'pipeOut' , pipe : pipeOut } ,
186
190
err : { 'kind' : 'pipeOut' , pipe : pipeErr } ,
187
191
} ,
188
- rootFileSystem
192
+ rootFileSystem,
189
193
} ;
190
194
const path = Uri . joinPath ( context . extensionUri , 'dist' , 'StructuredLogViewer.Wasi.Engine.wasm' ) ;
191
195
const moduleBytes = await vscode . workspace . fs . readFile ( path ) ;
@@ -194,6 +198,6 @@ export async function openMSBuildLogDocument(context: vscode.ExtensionContext, u
194
198
const process = await wasm . createProcess ( 'StructuredLogViewer.Wasi.Engine' , module , options ) ;
195
199
const engine = new WasmEngine ( process , out ) ;
196
200
out . info ( 'process created' )
197
- return new MSBuildLogDocument ( uri , engine , out ) ;
201
+ return new MSBuildLogDocument ( pipeIn , uri , engine , out ) ;
198
202
}
199
203
0 commit comments