@@ -4,8 +4,52 @@ import { localize, loadI18n } from '../utils/i18n';
44import * as lan from '../language/main' ;
55import * as asm from './ASM' ;
66
7+ import { XhrOptions } from "emulators/dist/out/impl/http" ;
8+ import { platform } from 'emulators/dist/out/emulators' ;
9+
10+ self . window = self
11+
712export function activate ( context : vscode . ExtensionContext ) : void {
813
14+ let jsdos = ""
15+ if ( context . extensionMode == vscode . ExtensionMode . Development ) {
16+ jsdos = "node_modules/emulators/dist/"
17+ }
18+
19+ const request = platform . current . httpRequest
20+ platform . current . httpRequest = async function ( url :string , options :XhrOptions ) {
21+ if ( url . endsWith ( "wasm" ) ) {
22+ const uri = vscode . Uri . file ( url )
23+ const filename = uri . path . substring ( uri . path . lastIndexOf ( '/' ) ) ;
24+ const uri2 = vscode . Uri . joinPath ( context . extensionUri , jsdos , filename )
25+ return await vscode . workspace . fs . readFile ( uri2 )
26+ }
27+ if ( url . endsWith ( "js" ) ) {
28+ const uri = vscode . Uri . file ( url )
29+ const filename = uri . path . substring ( uri . path . lastIndexOf ( '/' ) ) ;
30+ const uri2 = vscode . Uri . joinPath ( context . extensionUri , jsdos , filename )
31+ const data = await vscode . workspace . fs . readFile ( uri2 )
32+ const text = new TextDecoder ( "utf-8" ) . decode ( data )
33+ return text
34+ }
35+ return request ( url , options )
36+ }
37+
38+ platform . current . createWorker = async function ( url : string , onerror :( e :ErrorEvent ) => void , onmessage :( e :MessageEvent ) => void ) : Promise < Worker > {
39+ const uri = vscode . Uri . file ( url )
40+ const filename = uri . path . substring ( uri . path . lastIndexOf ( '/' ) ) ;
41+ const uri2 = vscode . Uri . joinPath ( context . extensionUri , jsdos , filename )
42+ const data = await vscode . workspace . fs . readFile ( uri2 )
43+
44+ const b = new Blob ( [ data ] )
45+
46+ const localUrl = URL . createObjectURL ( b ) ;
47+ const worker = new Worker ( localUrl ) ;
48+ worker . onerror = onerror ;
49+ worker . onmessage = onmessage
50+ return worker
51+ } as any ;
52+
953 loadI18n ( context ) ;
1054
1155 //provide programmaic language features like hover,references,outline(symbol)
0 commit comments