|
@@ -50,27 +50,46 @@ class MonacoCreator {
|
|
|
/**
|
|
|
* Load the Monaco Node module.
|
|
|
*/
|
|
|
- loadMonaco(typings) {
|
|
|
- var xhr = new XMLHttpRequest();
|
|
|
+ async loadMonaco(typings) {
|
|
|
+ let response = await fetch(typings || "babylon.d.txt");
|
|
|
+ if (!response.ok)
|
|
|
+ return;
|
|
|
|
|
|
- xhr.open('GET', typings || "babylon.d.txt", true);
|
|
|
+ const libContent = await response.text();
|
|
|
+ require.config({ paths: { 'vs': 'node_modules/monaco-editor/dev/vs' } });
|
|
|
|
|
|
- xhr.onreadystatechange = function () {
|
|
|
- if (xhr.readyState === 4) {
|
|
|
- if (xhr.status === 200) {
|
|
|
- require.config({ paths: { 'vs': 'node_modules/monaco-editor/min/vs' } });
|
|
|
- require(['vs/editor/editor.main'], function () {
|
|
|
- this.setupMonacoCompilationPipeline(xhr.responseText);
|
|
|
- this.setupMonacoColorProvider();
|
|
|
+ require(['vs/editor/editor.main'], () => {
|
|
|
+ this.setupMonacoCompilationPipeline(libContent);
|
|
|
+ this.setupMonacoColorProvider();
|
|
|
|
|
|
- this.parent.main.run();
|
|
|
- }.bind(this));
|
|
|
- }
|
|
|
- }
|
|
|
- }.bind(this);
|
|
|
- xhr.send(null);
|
|
|
+ require(['vs/language/typescript/languageFeatures'], module => {
|
|
|
+ this.hookMonacoCompletionProvider(module.SuggestAdapter);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.parent.main.run();
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
+ hookMonacoCompletionProvider(provider) {
|
|
|
+ const hooked = provider.prototype.provideCompletionItems;
|
|
|
+
|
|
|
+ const suggestionFilter = function(suggestion) {
|
|
|
+ return !suggestion.label.startsWith("_");
|
|
|
+ }
|
|
|
+
|
|
|
+ provider.prototype.provideCompletionItems = function(model, position, context, token) {
|
|
|
+ // reuse 'this' to preserve context through call (using apply)
|
|
|
+ return hooked
|
|
|
+ .apply(this, [model, position, context, token])
|
|
|
+ .then(result => {
|
|
|
+ if (!result.suggestions)
|
|
|
+ return result;
|
|
|
+
|
|
|
+ return { suggestions: result.suggestions.filter(suggestionFilter)};
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
setupMonacoCompilationPipeline(libContent) {
|
|
|
const typescript = monaco.languages.typescript;
|
|
|
|