From 0b9f3c15d2091d2722b5687a7c242c08e045972b Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Wed, 22 Feb 2023 17:43:23 +0800 Subject: [PATCH] Fix 'Hover Provider Example' incorrect Promise syntax --- .../hover-provider-example/sample.js | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/website/src/website/data/playground-samples/extending-language-services/hover-provider-example/sample.js b/website/src/website/data/playground-samples/extending-language-services/hover-provider-example/sample.js index 1359688a59..ebe3920783 100644 --- a/website/src/website/data/playground-samples/extending-language-services/hover-provider-example/sample.js +++ b/website/src/website/data/playground-samples/extending-language-services/hover-provider-example/sample.js @@ -31,35 +31,32 @@ monaco.editor.create(document.getElementById("container"), { function xhr(url) { var req = null; - return new Promise( - function (c, e) { - req = new XMLHttpRequest(); - req.onreadystatechange = function () { - if (req._canceled) { - return; - } + return new Promise(function (c, e) { + req = new XMLHttpRequest(); + req.onreadystatechange = function () { + if (req._canceled) { + return; + } - if (req.readyState === 4) { - if ( - (req.status >= 200 && req.status < 300) || - req.status === 1223 - ) { - c(req); - } else { - e(req); - } - req.onreadystatechange = function () {}; + if (req.readyState === 4) { + if ( + (req.status >= 200 && req.status < 300) || + req.status === 1223 + ) { + c(req); + } else { + e(req); } - }; + req.onreadystatechange = function () {}; + } + }; - req.open("GET", url, true); - req.responseType = ""; + req.open("GET", url, true); + req.responseType = ""; - req.send(null); - }, - function () { - req._canceled = true; - req.abort(); - } - ); + req.send(null); + }).catch(function () { + req._canceled = true; + req.abort(); + }); }