How to read from filesystem in worker in web extension? #1535
-
How can I supply a listing of file paths and file contents into a worker that is running in a web extension? I used the lsp-web-extension-sample to search for an implementation. import * as vscode from 'vscode'
console.log('vscode.workspace.fs.readFile: ' + vscode.workspace.fs.readFile); The log showed that the reference to vscode.workspace.fs.readFile: async readFile(i){try{const n=l.b.get(i.scheme);return n?(await l.a.$ensureActivation(i.scheme),(await n.impl.readFile(i)).slice()):(await l.a.$readFile(i)).buffer}catch(n){return S.e(n)}} However, when I placed this code in the worker, in the file ErrorEvent {isTrusted: true, message: 'Uncaught ReferenceError: require is not defined', filename: 'vscode-file://vscode-app/k:/Source/Repos/vsc…ion-sample/server/dist/browserServerMain.js', lineno: 8539, colno: 1, …} As far as I understand this error, the Can we somehow access |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
No. const serverMain = Uri.joinPath(context.extensionUri, 'server/dist/browserServerMain.js');
const worker = new Worker(serverMain.toString(true)); However, even in the context of Web Worker, you can execute |
Beta Was this translation helpful? Give feedback.
No.
browserServerMain.js
is executed in the context of Web Worker. Thevscode
module is not provided in the context.https://github.com/microsoft/vscode-extension-samples/blob/a11599ca990d239073f4b9978723800d8565d9fb/lsp-web-extension-sample/client/src/browserClientMain.ts#L44-L45
However, even in the context of Web Worker, you can execute
fetch('file:///localworkspacedir/local/file')
if you want.