From 70e48eeb5257628b141a1f3a8d0d2d42f17942f2 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 8 Feb 2019 15:19:17 +0100 Subject: [PATCH] debt - more promise cleanup --- ...guage-services-hover-provider-example.html | 6 +- test/samples.js | 40 +- test/tokenization.html | 4 +- .../hover-provider-example/sample.js | 10 +- website/playground/playground.js | 718 +++++++++--------- 5 files changed, 386 insertions(+), 392 deletions(-) diff --git a/test/playground.generated/extending-language-services-hover-provider-example.html b/test/playground.generated/extending-language-services-hover-provider-example.html index 2b499d66..cf0efc19 100644 --- a/test/playground.generated/extending-language-services-hover-provider-example.html +++ b/test/playground.generated/extending-language-services-hover-provider-example.html @@ -60,7 +60,7 @@ monaco.editor.create(document.getElementById("container"), { function xhr(url) { var req = null; - return new monaco.Promise(function(c,e,p) { + return new Promise(function(c,e) { req = new XMLHttpRequest(); req.onreadystatechange = function () { if (req._canceled) { return; } @@ -72,8 +72,6 @@ function xhr(url) { e(req); } req.onreadystatechange = function () { }; - } else { - p(req); } }; @@ -92,4 +90,4 @@ function xhr(url) { }); - \ No newline at end of file + diff --git a/test/samples.js b/test/samples.js index 98885f79..28f59418 100644 --- a/test/samples.js +++ b/test/samples.js @@ -1,40 +1,40 @@ /// -define(['./samples-all.generated'], function(ALL_SAMPLES) { +define(['./samples-all.generated'], function (ALL_SAMPLES) { var XHR_SAMPLES = {}; - ALL_SAMPLES.forEach(function(sample) { + ALL_SAMPLES.forEach(function (sample) { XHR_SAMPLES[sample.name] = sample.content; }); var samples = []; - var modesIds = monaco.languages.getLanguages().map(function(language) { return language.id; }); + var modesIds = monaco.languages.getLanguages().map(function (language) { return language.id; }); modesIds.sort(); - modesIds.forEach(function(modeId) { + modesIds.forEach(function (modeId) { samples.push({ name: 'sample - ' + modeId, mimeType: modeId, - loadText: function() { - return monaco.Promise.as(XHR_SAMPLES['sample.' + modeId + '.txt']); + loadText: function () { + return Promise.resolve(XHR_SAMPLES['sample.' + modeId + '.txt']); } }); }); function addXHRSample(name, modelUrl, mimeType, textModifier) { - textModifier = textModifier || function(text) { return text; }; + textModifier = textModifier || function (text) { return text; }; samples.push({ name: name, mimeType: mimeType, - loadText: function() { - return monaco.Promise.as(XHR_SAMPLES[modelUrl]).then(textModifier); + loadText: function () { + return Promise.resolve(XHR_SAMPLES[modelUrl]).then(textModifier); } }); } function addStringPowerXHRSample(name, modelUrl, mimeType, power) { - addXHRSample(name, modelUrl, mimeType, function(text) { + addXHRSample(name, modelUrl, mimeType, function (text) { var result = text; for (var i = 0; i < power; ++i) { result += "\n" + result; @@ -47,8 +47,8 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { samples.push({ name: name, mimeType: mimeType, - loadText: function() { - return monaco.Promise.as(modelText); + loadText: function () { + return Promise.resolve(modelText); } }); } @@ -65,7 +65,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { addXHRSample('Z___jquery-min.js', 'run-editor-jquery-min-js.txt', 'text/javascript'); - addXHRSample('Z___scrolling-strategy.js', 'run-editor-sample-js.txt', 'text/plain', function(text) { + addXHRSample('Z___scrolling-strategy.js', 'run-editor-sample-js.txt', 'text/plain', function (text) { console.log('here I am'); var lines = text.split('\n'); var newLines = lines.slice(0); @@ -98,7 +98,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { '\uDBFF\uDFFF' ].join('\n')); - addSample('Z___easy-debug.js', 'text/plain', (function() { + addSample('Z___easy-debug.js', 'text/plain', (function () { var myValue = "Line1"; for (var i = 2; i < 50; i++) { myValue += "\nLine" + i; @@ -106,7 +106,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { return myValue; })()); - addSample('Z___copy-paste.txt', 'text/plain', (function() { + addSample('Z___copy-paste.txt', 'text/plain', (function () { var i = 0, sampleCopyPasteLine = ''; while (sampleCopyPasteLine.length < 1000) { i++; @@ -119,7 +119,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { return sampleCopyPaste; })()); - addSample('Z___xss', 'text/html', (function() { + addSample('Z___xss', 'text/html', (function () { var xssRepresentations = [ '<', 'BAD\u2028CHARACTER', @@ -196,7 +196,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { return xssRepresentations.length + ':\n' + xssRepresentations.join('\n'); })()); - addSample('Z___many-links.js', 'text/javascript', (function() { + addSample('Z___many-links.js', 'text/javascript', (function () { var result = "bla bla a url: https://microsoft.com some more bla bla"; for (var i = 0; i < 13; ++i) { result += "\n" + result; @@ -204,7 +204,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { return "/*" + result + "\n*/"; })()); - addSample('Z___line-separators.js', 'text/javascript', (function() { + addSample('Z___line-separators.js', 'text/javascript', (function () { return [ "var x = '1'; // And\u2028 here I have a nice comment.", "", @@ -216,7 +216,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) { addXHRSample('Z___intellisense.js', 'run-editor-intellisense-js.txt', 'text/javascript'); - addSample('Z___recursion attack', 'text/html', (function() { + addSample('Z___recursion attack', 'text/html', (function () { var arr = []; for (var i = 0; i < 10000; i++) { arr.push('\n