22import * as React from 'react' ;
33import styled from 'styled-components' ;
44import { debounce } from 'lodash' ;
5- import type { Preferences , ModuleError , Module , Directory } from 'common/types' ;
5+ import type {
6+ Preferences ,
7+ ModuleError ,
8+ ModuleCorrection ,
9+ Module ,
10+ Directory ,
11+ } from 'common/types' ;
612import { getModulePath } from 'app/store/entities/sandboxes/modules/selectors' ;
713
814import theme from 'common/theme' ;
@@ -28,6 +34,7 @@ type State = {
2834type Props = {
2935 code : ?string ,
3036 errors : ?Array < ModuleError > ,
37+ corrections : Array < ModuleCorrection > ,
3138 id : string ,
3239 sandboxId : string ,
3340 title : string ,
@@ -134,12 +141,12 @@ const requireAMDModule = paths =>
134141const handleError = (
135142 monaco ,
136143 editor ,
137- currentErrors : ?Array < ModuleError > ,
138- nextErrors: ? Array< ModuleError >
144+ nextErrors : ?Array < ModuleError > ,
145+ nextCorrections: Array< ModuleCorrection >
139146) => {
140147 if ( ! monaco ) return ;
141148 if ( nextErrors && nextErrors . length > 0 ) {
142- const markers = nextErrors
149+ const errorMarkers = nextErrors
143150 . map ( error => {
144151 if ( error ) {
145152 return {
@@ -156,10 +163,41 @@ const handleError = (
156163 } )
157164 . filter ( x => x ) ;
158165
159- monaco . editor . setModelMarkers ( editor . getModel ( ) , 'error' , markers ) ;
166+ monaco . editor . setModelMarkers ( editor . getModel ( ) , 'error' , errorMarkers ) ;
160167 } else {
161168 monaco . editor . setModelMarkers ( editor . getModel ( ) , 'error' , [ ] ) ;
162169 }
170+
171+ if (nextCorrections.length > 0 ) {
172+ const correctionMarkers = nextCorrections
173+ . map ( correction => {
174+ if ( correction ) {
175+ return {
176+ severity :
177+ correction . severity === 'warning'
178+ ? monaco . Severity . Warning
179+ : monaco . Severity . Notice ,
180+ startColumn : correction . column ,
181+ startLineNumber : correction . line ,
182+ endColumn : 1 ,
183+ endLineNumber : correction . line + 1 ,
184+ message : correction . message ,
185+ source : correction . source ,
186+ } ;
187+ }
188+
189+ return null ;
190+ } )
191+ . filter ( x => x ) ;
192+
193+ monaco . editor . setModelMarkers (
194+ editor . getModel ( ) ,
195+ 'correction' ,
196+ correctionMarkers
197+ ) ;
198+ } else {
199+ monaco . editor . setModelMarkers ( editor . getModel ( ) , 'correction' , [ ] ) ;
200+ }
163201} ;
164202
165203export default class CodeEditor extends React . PureComponent < Props , State > {
@@ -343,6 +381,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
343381 nextProps.sandboxId !== this.props.sandboxId ||
344382 nextProps.id !== this.props.id ||
345383 nextProps.errors !== this.props.errors ||
384+ nextProps.corrections !== this.props.corrections ||
346385 this.props.canSave !== nextProps.canSave ||
347386 this.props.preferences !== nextProps.preferences
348387 );
@@ -369,16 +408,13 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
369408 } ;
370409
371410 componentWillUpdate ( nextProps : Props ) {
372- const {
373- id : currentId ,
374- sandboxId : currentSandboxId ,
375- errors : currentErrors ,
376- } = this . props ;
411+ const { id : currentId , sandboxId : currentSandboxId } = this . props ;
377412
378413 const {
379414 id : nextId ,
380415 code : nextCode ,
381416 errors : nextErrors ,
417+ corrections : nextCorrections ,
382418 title : nextTitle ,
383419 sandboxId : nextSandboxId ,
384420 } = nextProps ;
@@ -401,15 +437,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
401437 nextCode,
402438 nextTitle,
403439 } ) . then ( ( ) => {
404- handleError (
405- this . monaco ,
406- this . editor ,
407- currentErrors ,
408- nextErrors ,
409- nextCode ,
410- currentId ,
411- nextId
412- ) ;
440+ handleError ( this . monaco , this . editor , nextErrors , nextCorrections ) ;
413441 } ) ;
414442 }
415443 }
0 commit comments