Built-ins with Web Workers #1322
-
What is the recommended way to access a code file for loading a set of built-ins using a custom WorkspaceManager when you are using WebWorkers? My guess is that the NodeFileSystemProvider won't work for me if I am bundling everything for execution in the browser instead of running my language server as a NodeJS app. Here is how I have done it in that past with a standard NodeJS implementation: protected override async loadAdditionalDocuments(_folders: WorkspaceFolder[], _collector: (document: LangiumDocument) => void): Promise<void> {
//read in the global behaviors file
const fileSystemProvider = new NodeFileSystemProvider();
const uri: URI = URI.file(__dirname + '/resources/global.behaviors') ; // swiped from https://github.com/microsoft/vscode-uri
const text = await fileSystemProvider.readFile(uri);
//parse the doc contents
const doc : LangiumDocument = this.factory.fromString(text,uri);
_collector(doc);
// add doc to the cache, as suggested in https://github.com/langium/langium/issues/464
this.langiumDocuments.addDocument(doc);
return Promise.resolve();
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@ballcoach12 Often times we usually just put the builtin library into the TypeScript code: export const stdlib = `
// stdlib here
`; If you don't want to embed it into the bundle itself, you will likely need to download it from some service endpoint. If you have both a node and web version of your language, it makes sense to have something like a |
Beta Was this translation helpful? Give feedback.
@ballcoach12 Often times we usually just put the builtin library into the TypeScript code:
If you don't want to embed it into the bundle itself, you will likely need to download it from some service endpoint. If you have both a node and web version of your language, it makes sense to have something like a
BuiltInLoadStrategy
as part of your injection context that you pass to yourcreate<language>Module
function. One would just load from disk usingfs
while the other one usesfetch
to download the builtin library instead.