Open trevorade opened 5 years ago
From my experience, the reason for the delay is not the processing delay, but rather inefficient handling of extraLibs in monaco-typescript. As it is right now, in the official monaco-typescript release, whenever addExtraLib is called the existing worker is destroyed, the extra lib is added, then a new one is initialized with all the libs. The same process happens when a extra lib is disposed of. So, whenever you call addExtraLib you are destroying all parsing, and creating it again for all the inmemory editors and extra libs. In my fork, I've fixed this issue by passing making the main thread pass the new extra libs over to the WebWorker on demand, without destroying it. The bulk of the work is here: https://github.com/stefan-lacatus/monaco-typescript/commit/9d9675a28ffc039ec471c4bb240758f81720f84b . The linked commit also deals with bulk updates of the extraLibs.
@stefan-lacatus Cool. Unfortunately, I'm directly using the Monaco releases and wouldn't be able to benefit from your patch. Any chance of making a PR in monaco-typescript of your commit?
Is there an existing monaco-typescript issue about this inefficient handling and lack of a means to bulk-update extra libs?
I'll try to create a PR with this features this week. As far as I know, there's no existing issue for this.
I just updated the issue description to also encapsulate the idea of permitting adding / removing libraries in bulk in order to speed up the operation.
In my case, I have an editor which supports editing server-side NodeJS style JS as well as client-side JS. The server-side JS has no DOM and the libraries available to each are different so I need to be able to quickly swap between one set of compiler options and another. Doing this in a single bulk operation would be ideal here based on https://github.com/Microsoft/monaco-editor/issues/1300#issuecomment-460389135
I have created the PR for this.
@trevorade : My usecase is very similar. To improve performance even more, I've created separate workers for the client/server-side editors. This way, when switching between the two editors, I don't have to care about adding/removing extra libs. They are simply kept separate. This is done via the setupNamedLanguage
call, included in the PR. Using it, you can create your own language, with separate processing.
monaco-editor version: 0.15.6
Adding a lot of DTS files for use in JavaScript/TypeScript frequently takes several seconds for the TypeScript compiler to process. As best I can tell, there is no way to programmatically determine when the compiler has processed the extra files and is "stable" again.
The idea is that, when calling
monaco.languages.typescript.LanguageServiceDefaults.addExtraLib
with large DTS files, it would be helpful to show the user an indeterminate progress bar to make it clear that autocompletions are not available presently. Notifying the program that processing is complete could be accomplished via an event, a promise returned fromaddExtraLib
, or an optional callback toaddExtraLib
.Note, if
addExtraLib
is called multiple times in quick succession, we would want to know when the TypeScript compiler has finished processing all of the DTS files, not only/just a single DTS file.