From d34abb4dcb46f54d5bf93cd477ebd15cc5196562 Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Tue, 2 Jul 2019 05:01:54 +0500 Subject: [PATCH 1/6] [website] Add coverage to Try Flow --- website/_assets/css/_try.scss | 108 +++++++++++++++++++++-- website/_assets/js/tryFlow.js.es6.liquid | 55 ++++++++++-- website/_assets/js/tryFlowWorker.js | 17 +++- website/_layouts/default.html | 1 - 4 files changed, 167 insertions(+), 14 deletions(-) diff --git a/website/_assets/css/_try.scss b/website/_assets/css/_try.scss index 9362042ee7e..89b4f7a6d1a 100644 --- a/website/_assets/css/_try.scss +++ b/website/_assets/css/_try.scss @@ -163,17 +163,26 @@ html.site-fullscreen .content { } @-webkit-keyframes sk-bouncedelay { - 0%, 80%, 100% { -webkit-transform: scale(0) } - 40% { -webkit-transform: scale(1.0) } + 0%, + 80%, + 100% { + -webkit-transform: scale(0); + } + 40% { + -webkit-transform: scale(1); + } } @keyframes sk-bouncedelay { - 0%, 80%, 100% { + 0%, + 80%, + 100% { -webkit-transform: scale(0); transform: scale(0); - } 40% { - -webkit-transform: scale(1.0); - transform: scale(1.0); + } + 40% { + -webkit-transform: scale(1); + transform: scale(1); } } @@ -205,3 +214,90 @@ html.site-fullscreen .content { width: 100%; } } + +/* New images */ + +.CodeMirror-lint-mark-error { + background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%206%203'%20enable-background%3D'new%200%200%206%203'%20height%3D'3'%20width%3D'6'%3E%3Cg%20fill%3D'%23d60a0a'%3E%3Cpolygon%20points%3D'5.5%2C0%202.5%2C3%201.1%2C3%204.1%2C0'%2F%3E%3Cpolygon%20points%3D'4%2C0%206%2C2%206%2C0.6%205.4%2C0'%2F%3E%3Cpolygon%20points%3D'0%2C2%201%2C3%202.4%2C3%200%2C0.6'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E"); +} + +.CodeMirror-lint-mark-warning { + background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%206%203'%20enable-background%3D'new%200%200%206%203'%20height%3D'3'%20width%3D'6'%3E%3Cg%20fill%3D'%23117711'%3E%3Cpolygon%20points%3D'5.5%2C0%202.5%2C3%201.1%2C3%204.1%2C0'%2F%3E%3Cpolygon%20points%3D'4%2C0%206%2C2%206%2C0.6%205.4%2C0'%2F%3E%3Cpolygon%20points%3D'0%2C2%201%2C3%202.4%2C3%200%2C0.6'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E"); +} + +.CodeMirror-lint-mark-info { + background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%206%203'%20enable-background%3D'new%200%200%206%203'%20height%3D'3'%20width%3D'6'%3E%3Cg%20fill%3D'%23008000'%3E%3Cpolygon%20points%3D'5.5%2C0%202.5%2C3%201.1%2C3%204.1%2C0'%2F%3E%3Cpolygon%20points%3D'4%2C0%206%2C2%206%2C0.6%205.4%2C0'%2F%3E%3Cpolygon%20points%3D'0%2C2%201%2C3%202.4%2C3%200%2C0.6'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E"); +} + +/* The lint marker gutter */ + +.CodeMirror-lint-markers { + width: 16px; +} + +.CodeMirror-lint-tooltip { + background-color: #ffd; + border: 1px solid black; + border-radius: 4px 4px 4px 4px; + color: black; + font-family: monospace; + font-size: 10pt; + overflow: hidden; + padding: 2px 5px; + position: fixed; + white-space: pre; + white-space: pre-wrap; + z-index: 100; + max-width: 600px; + opacity: 0; + transition: opacity 0.4s; + -moz-transition: opacity 0.4s; + -webkit-transition: opacity 0.4s; + -o-transition: opacity 0.4s; + -ms-transition: opacity 0.4s; +} + +.CodeMirror-lint-mark-error, +.CodeMirror-lint-mark-warning, +.CodeMirror-lint-mark-info { + display: inline-block; + background-position: left bottom; + background-repeat: repeat-x; +} + +.CodeMirror-lint-marker-error, +.CodeMirror-lint-marker-warning { + background-position: center center; + background-repeat: no-repeat; + cursor: pointer; + display: inline-block; + height: 16px; + width: 16px; + vertical-align: middle; + position: relative; +} + +.CodeMirror-lint-message-error, +.CodeMirror-lint-message-warning { + padding-left: 18px; + background-position: top left; + background-repeat: no-repeat; +} + +.CodeMirror-lint-marker-error, +.CodeMirror-lint-message-error { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII="); +} + +.CodeMirror-lint-marker-warning, +.CodeMirror-lint-message-warning { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII="); +} + +.CodeMirror-lint-marker-multiple { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC"); + background-repeat: no-repeat; + background-position: right bottom; + width: 100%; + height: 100%; +} diff --git a/website/_assets/js/tryFlow.js.es6.liquid b/website/_assets/js/tryFlow.js.es6.liquid index 8b57fd90786..021727ef6af 100644 --- a/website/_assets/js/tryFlow.js.es6.liquid +++ b/website/_assets/js/tryFlow.js.es6.liquid @@ -106,12 +106,25 @@ function removeChildren(node) { } function getAnnotations(text, callback, options, editor) { - Promise.resolve(editor.getOption('flow')) - .then(flowProxy => flowProxy.checkContent('-', text)) - .then(errors => { - CodeMirror.signal(editor, 'flowErrors', errors); + const flow = Promise.resolve(editor.getOption('flow')); + const sources = Promise.all([ + flow + .then(flowProxy => flowProxy.coverage('-', text)) + .then(coverage => { + CodeMirror.signal(editor, 'flowCoverage', coverage); + return coverage.expressions.uncovered_locs + }) + .catch(() => []), + flow + .then(flowProxy => flowProxy.checkContent('-', text)) + .then(errors => { + CodeMirror.signal(editor, 'flowErrors', errors); + return errors + }) + ]); - var lint = errors.map(function(err) { + sources.then(([coverage, errors]) => { + const errorsLint = errors.map(function(err) { var messages = err.message; var firstLoc = messages[0].loc; var message = messages.map(function(msg) { @@ -127,7 +140,21 @@ function getAnnotations(text, callback, options, editor) { message: message }; }); - callback(lint); + const coverageLint = coverage.map(function (loc) { + return { + from: CodeMirror.Pos( + loc.start.line - 1, + loc.start.column - 1, + ), + to: CodeMirror.Pos(loc.end.line - 1, loc.end.column), + severity: 'info', + message: 'Not covered by flow' + } + }); + callback([ + ...errorsLint, + ...coverageLint, + ]); }); } getAnnotations.async = true; @@ -217,6 +244,14 @@ class AsyncLocalFlow { return Promise.resolve(this._flow.checkContent(filename, body)); } + coverage(filename, body) { + return Promise.resolve(this._flow.coverage(filename, body)) + } + + dumpTypes(filename, body) { + return Promise.resolve(this._flow.dumpTypes(filename, body)) + } + typeAtPos(filename, body, line, col) { return Promise.resolve(this._flow.typeAtPos(filename, body, line, col)); } @@ -239,6 +274,14 @@ class AsyncWorkerFlow { return this._worker.send({ type: 'checkContent', filename, body }); } + coverage(filename, body) { + return this._worker.send({ type: 'coverage', filename, body }) + } + + dumpTypes(filename, body) { + return this._worker.send({ type: 'dumpTypes', filename, body }) + } + typeAtPos(filename, body, line, col) { return this._worker.send({ type: 'typeAtPos', filename, body, line, col }); } diff --git a/website/_assets/js/tryFlowWorker.js b/website/_assets/js/tryFlowWorker.js index 7ceb59be461..80da7e7f171 100644 --- a/website/_assets/js/tryFlowWorker.js +++ b/website/_assets/js/tryFlowWorker.js @@ -19,11 +19,26 @@ this.onmessage = function(e) { case "checkContent": getFlow(data.version).then(function(flow) { var result = flow.checkContent(data.filename, data.body); - postMessage({id: data.id, type: "checkContent", result: result }); + postMessage({id: data.id, type: "checkContent", result: result}); })["catch"](function (e) { postMessage({id: data.id, type: "checkContent", err: e}); }); return; + case "dumpTypes": + getFlow(data.version).then(function(flow) { + var result = flow.dumpTypes(data.filename, data.body); + postMessage({id: data.id, type: "dumpTypes", result: result}); + })["catch"](function (e) { + postMessage({id: data.id, type: "dumpTypes", err: e}); + }); + return; + case "coverage": + getFlow(data.version).then(function(flow) { + var result = flow.coverage(data.filename, data.body); + postMessage({id: data.id, type: "coverage", result: result}); + })["catch"](function (e) { + postMessage({id: data.id, type: "coverage", err: e}); + }) case "typeAtPos": getFlow(data.version).then(function(flow) { var result = flow.typeAtPos( diff --git a/website/_layouts/default.html b/website/_layouts/default.html index d371f4535f3..fdcc7750ca7 100644 --- a/website/_layouts/default.html +++ b/website/_layouts/default.html @@ -26,7 +26,6 @@ {% endif %} {% if page.codemirror or layout.codemirror %} - {% endif %}