|
@@ -23,6 +23,13 @@ class MonacoCreator {
|
|
this.deprecatedCandidates = [];
|
|
this.deprecatedCandidates = [];
|
|
|
|
|
|
this.compilerTriggerTimeoutID = null;
|
|
this.compilerTriggerTimeoutID = null;
|
|
|
|
+
|
|
|
|
+ this.addOnMoncaoLoadedCallback(
|
|
|
|
+ function () {
|
|
|
|
+ this.parent.main.run();
|
|
|
|
+ },
|
|
|
|
+ this
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
// ACCESSORS
|
|
// ACCESSORS
|
|
@@ -43,8 +50,8 @@ class MonacoCreator {
|
|
return this.monacoMode;
|
|
return this.monacoMode;
|
|
};
|
|
};
|
|
set MonacoMode(mode) {
|
|
set MonacoMode(mode) {
|
|
- if (this.monacoMode != "javascript"
|
|
|
|
- && this.monacoMode != "typescript")
|
|
|
|
|
|
+ if (this.monacoMode != "javascript" &&
|
|
|
|
+ this.monacoMode != "typescript")
|
|
console.warn("Error while defining Monaco Mode");
|
|
console.warn("Error while defining Monaco Mode");
|
|
this.monacoMode = mode;
|
|
this.monacoMode = mode;
|
|
};
|
|
};
|
|
@@ -81,12 +88,16 @@ class MonacoCreator {
|
|
this.setupDefinitionWorker(libContent);
|
|
this.setupDefinitionWorker(libContent);
|
|
|
|
|
|
// WARNING !!! We need the 'dev' version of Monaco, as we use monkey-patching to hook into the suggestion adapter
|
|
// WARNING !!! We need the 'dev' version of Monaco, as we use monkey-patching to hook into the suggestion adapter
|
|
- require.config({ paths: { 'vs': '/node_modules/monaco-editor/dev/vs' } });
|
|
|
|
|
|
+ require.config({
|
|
|
|
+ paths: {
|
|
|
|
+ 'vs': '/node_modules/monaco-editor/dev/vs'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
require(['vs/editor/editor.main'], () => {
|
|
require(['vs/editor/editor.main'], () => {
|
|
// Setup the Monaco compilation pipeline, so we can reuse it directly for our scrpting needs
|
|
// Setup the Monaco compilation pipeline, so we can reuse it directly for our scrpting needs
|
|
this.setupMonacoCompilationPipeline(libContent);
|
|
this.setupMonacoCompilationPipeline(libContent);
|
|
-
|
|
|
|
|
|
+
|
|
// This is used for a vscode-like color preview for ColorX types
|
|
// This is used for a vscode-like color preview for ColorX types
|
|
this.setupMonacoColorProvider();
|
|
this.setupMonacoColorProvider();
|
|
|
|
|
|
@@ -95,10 +106,38 @@ class MonacoCreator {
|
|
this.hookMonacoCompletionProvider(module.SuggestAdapter);
|
|
this.hookMonacoCompletionProvider(module.SuggestAdapter);
|
|
});
|
|
});
|
|
|
|
|
|
- this.parent.main.run();
|
|
|
|
|
|
+ this.onMonacoLoaded();
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ onMonacoLoaded() {
|
|
|
|
+ if (this.monacoLoaded) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.onMonacoLoadedCallbacks.forEach((callbackDef) => {
|
|
|
|
+ callbackDef.func.call(callbackDef.context, this);
|
|
|
|
+ });
|
|
|
|
+ this.monacoLoaded = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * This will register a new callback that will be triggered when the monaco loader is done.
|
|
|
|
+ * If the loader is already done, the function will be executed right away.
|
|
|
|
+ * @param {Function} func the function to call when monaco is available
|
|
|
|
+ * @param {*} context The context of this function
|
|
|
|
+ */
|
|
|
|
+ addOnMoncaoLoadedCallback(func, context) {
|
|
|
|
+ this.onMonacoLoadedCallbacks = this.onMonacoLoadedCallbacks || [];
|
|
|
|
+ if (this.monacoLoaded) {
|
|
|
|
+ func.call(context, this);
|
|
|
|
+ } else {
|
|
|
|
+ this.onMonacoLoadedCallbacks.push({
|
|
|
|
+ func: func,
|
|
|
|
+ context: context
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// > This worker will analyze the syntaxtree and return an array of deprecated functions (but the goal is to do more in the future!)
|
|
// > This worker will analyze the syntaxtree and return an array of deprecated functions (but the goal is to do more in the future!)
|
|
// We need to do this because:
|
|
// We need to do this because:
|
|
// - checking extended properties during completion is time consuming, so we need to prefilter potential candidates
|
|
// - checking extended properties during completion is time consuming, so we need to prefilter potential candidates
|
|
@@ -109,22 +148,26 @@ class MonacoCreator {
|
|
// We will also need this worker in the future to compute Intellicode scores for completion using dedicated attributes.
|
|
// We will also need this worker in the future to compute Intellicode scores for completion using dedicated attributes.
|
|
setupDefinitionWorker(libContent) {
|
|
setupDefinitionWorker(libContent) {
|
|
this.definitionWorker = new Worker('/js/definitionWorker.js');
|
|
this.definitionWorker = new Worker('/js/definitionWorker.js');
|
|
- this.definitionWorker.addEventListener('message', ({ data }) => {
|
|
|
|
|
|
+ this.definitionWorker.addEventListener('message', ({
|
|
|
|
+ data
|
|
|
|
+ }) => {
|
|
this.deprecatedCandidates = data.result;
|
|
this.deprecatedCandidates = data.result;
|
|
this.analyzeCode();
|
|
this.analyzeCode();
|
|
});
|
|
});
|
|
- this.definitionWorker.postMessage({ code: libContent });
|
|
|
|
|
|
+ this.definitionWorker.postMessage({
|
|
|
|
+ code: libContent
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
isDeprecatedEntry(details) {
|
|
isDeprecatedEntry(details) {
|
|
- return details
|
|
|
|
- && details.tags
|
|
|
|
- && details.tags.find(this.isDeprecatedTag);
|
|
|
|
|
|
+ return details &&
|
|
|
|
+ details.tags &&
|
|
|
|
+ details.tags.find(this.isDeprecatedTag);
|
|
}
|
|
}
|
|
|
|
|
|
isDeprecatedTag(tag) {
|
|
isDeprecatedTag(tag) {
|
|
- return tag
|
|
|
|
- && tag.name == "deprecated";
|
|
|
|
|
|
+ return tag &&
|
|
|
|
+ tag.name == "deprecated";
|
|
}
|
|
}
|
|
|
|
|
|
// This will make sure that all members marked with a deprecated jsdoc attribute will be marked as such in Monaco UI
|
|
// This will make sure that all members marked with a deprecated jsdoc attribute will be marked as such in Monaco UI
|
|
@@ -156,7 +199,10 @@ class MonacoCreator {
|
|
for (const candidate of this.deprecatedCandidates) {
|
|
for (const candidate of this.deprecatedCandidates) {
|
|
const matches = model.findMatches(candidate, null, false, true, null, false);
|
|
const matches = model.findMatches(candidate, null, false, true, null, false);
|
|
for (const match of matches) {
|
|
for (const match of matches) {
|
|
- const position = { lineNumber: match.range.startLineNumber, column: match.range.startColumn };
|
|
|
|
|
|
+ const position = {
|
|
|
|
+ lineNumber: match.range.startLineNumber,
|
|
|
|
+ column: match.range.startColumn
|
|
|
|
+ };
|
|
const wordInfo = model.getWordAtPosition(position);
|
|
const wordInfo = model.getWordAtPosition(position);
|
|
const offset = model.getOffsetAt(position);
|
|
const offset = model.getOffsetAt(position);
|
|
|
|
|
|
@@ -184,7 +230,7 @@ class MonacoCreator {
|
|
|
|
|
|
monaco.editor.setModelMarkers(model, source, markers);
|
|
monaco.editor.setModelMarkers(model, source, markers);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// This is our hook in the Monaco suggest adapter, we are called everytime a completion UI is displayed
|
|
// This is our hook in the Monaco suggest adapter, we are called everytime a completion UI is displayed
|
|
// So we need to be super fast.
|
|
// So we need to be super fast.
|
|
// We need the 'dev' version of Monaco, as we use monkey-patching to hook into this suggestion adapter
|
|
// We need the 'dev' version of Monaco, as we use monkey-patching to hook into this suggestion adapter
|
|
@@ -273,7 +319,9 @@ class MonacoCreator {
|
|
label = `(${converter(color.red)}, ${converter(color.green)}, ${converter(color.blue)}, ${converter(color.alpha)})`;
|
|
label = `(${converter(color.red)}, ${converter(color.green)}, ${converter(color.blue)}, ${converter(color.alpha)})`;
|
|
}
|
|
}
|
|
|
|
|
|
- return [{ label: label }];
|
|
|
|
|
|
+ return [{
|
|
|
|
+ label: label
|
|
|
|
+ }];
|
|
},
|
|
},
|
|
|
|
|
|
provideDocumentColors: (model) => {
|
|
provideDocumentColors: (model) => {
|
|
@@ -378,10 +426,16 @@ class MonacoCreator {
|
|
const main = this.parent.main;
|
|
const main = this.parent.main;
|
|
const monacoCreator = this;
|
|
const monacoCreator = this;
|
|
|
|
|
|
- this.diffEditor.addCommand(monaco.KeyCode.Escape, function () { main.toggleDiffEditor(monacoCreator, menuPG); });
|
|
|
|
|
|
+ this.diffEditor.addCommand(monaco.KeyCode.Escape, function () {
|
|
|
|
+ main.toggleDiffEditor(monacoCreator, menuPG);
|
|
|
|
+ });
|
|
// Adding default VSCode bindinds for previous/next difference
|
|
// Adding default VSCode bindinds for previous/next difference
|
|
- this.diffEditor.addCommand(monaco.KeyMod.Alt | monaco.KeyCode.F5, function () { main.navigateToNext(); });
|
|
|
|
- this.diffEditor.addCommand(monaco.KeyMod.Shift | monaco.KeyMod.Alt | monaco.KeyCode.F5, function () { main.navigateToPrevious(); });
|
|
|
|
|
|
+ this.diffEditor.addCommand(monaco.KeyMod.Alt | monaco.KeyCode.F5, function () {
|
|
|
|
+ main.navigateToNext();
|
|
|
|
+ });
|
|
|
|
+ this.diffEditor.addCommand(monaco.KeyMod.Shift | monaco.KeyMod.Alt | monaco.KeyCode.F5, function () {
|
|
|
|
+ main.navigateToPrevious();
|
|
|
|
+ });
|
|
|
|
|
|
this.diffEditor.focus();
|
|
this.diffEditor.focus();
|
|
}
|
|
}
|
|
@@ -418,10 +472,18 @@ class MonacoCreator {
|
|
toggleMinimap() {
|
|
toggleMinimap() {
|
|
var minimapToggle = document.getElementById("minimapToggle1280");
|
|
var minimapToggle = document.getElementById("minimapToggle1280");
|
|
if (minimapToggle.classList.contains('checked')) {
|
|
if (minimapToggle.classList.contains('checked')) {
|
|
- this.jsEditor.updateOptions({ minimap: { enabled: false } });
|
|
|
|
|
|
+ this.jsEditor.updateOptions({
|
|
|
|
+ minimap: {
|
|
|
|
+ enabled: false
|
|
|
|
+ }
|
|
|
|
+ });
|
|
this.parent.utils.setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-square" aria-hidden="true"></i>');
|
|
this.parent.utils.setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-square" aria-hidden="true"></i>');
|
|
} else {
|
|
} else {
|
|
- this.jsEditor.updateOptions({ minimap: { enabled: true } });
|
|
|
|
|
|
+ this.jsEditor.updateOptions({
|
|
|
|
+ minimap: {
|
|
|
|
+ enabled: true
|
|
|
|
+ }
|
|
|
|
+ });
|
|
this.parent.utils.setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
this.parent.utils.setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
}
|
|
}
|
|
minimapToggle.classList.toggle('checked');
|
|
minimapToggle.classList.toggle('checked');
|
|
@@ -465,4 +527,4 @@ class MonacoCreator {
|
|
return output + stub;
|
|
return output + stub;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-};
|
|
|
|
|
|
+};
|