|
|
|
@ -4,14 +4,17 @@ interface RendererProps { |
|
|
|
|
message: any; |
|
|
|
|
opt?: any, |
|
|
|
|
plugin: any, |
|
|
|
|
config: any |
|
|
|
|
editor: any, |
|
|
|
|
config: any, |
|
|
|
|
fileManager: any |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const Renderer = ({ message, opt = {}, plugin, config }: RendererProps) => { |
|
|
|
|
export const Renderer = ({ message, opt = {}, editor, config, fileManager, plugin }: RendererProps) => { |
|
|
|
|
const [messageText, setMessageText] = useState(null) |
|
|
|
|
const [editorOptions, setEditorOptions] = useState({ |
|
|
|
|
useSpan: false, |
|
|
|
|
type: '' |
|
|
|
|
type: '', |
|
|
|
|
errFile: '' |
|
|
|
|
}) |
|
|
|
|
const [classList] = useState(opt.type === 'error' ? 'alert alert-danger' : 'alert alert-warning') |
|
|
|
|
const [close, setClose] = useState(false) |
|
|
|
@ -79,20 +82,40 @@ export const Renderer = ({ message, opt = {}, plugin, config }: RendererProps) = |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handlePointToErrorOnClick = (location, fileName) => { |
|
|
|
|
plugin.call('editor', 'discardHighlight') |
|
|
|
|
plugin.call('editor', 'highlight', location, fileName) |
|
|
|
|
const handleErrorClick = (opt) => { |
|
|
|
|
if (opt.click) { |
|
|
|
|
opt.click(message) |
|
|
|
|
} else if (opt.errFile !== undefined && opt.errLine !== undefined && opt.errCol !== undefined) { |
|
|
|
|
_errorClick(opt.errFile, opt.errLine, opt.errCol) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleClose = () => { |
|
|
|
|
setClose(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const _errorClick = (errFile, errLine, errCol) => { |
|
|
|
|
if (errFile !== config.get('currentFile')) { |
|
|
|
|
// TODO: refactor with this._components.contextView.jumpTo
|
|
|
|
|
const provider = fileManager.fileProviderOf(errFile) |
|
|
|
|
if (provider) { |
|
|
|
|
provider.exists(errFile).then(() => { |
|
|
|
|
fileManager.open(errFile) |
|
|
|
|
editor.gotoLine(errLine, errCol) |
|
|
|
|
}).catch(error => { |
|
|
|
|
if (error) return console.log(error) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
editor.gotoLine(errLine, errCol) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{ |
|
|
|
|
messageText && !close && ( |
|
|
|
|
<div className={`sol ${editorOptions.type} ${classList}`} data-id={opt.errFile} onClick={() => handlePointToErrorOnClick(opt.location, opt.fileName)}> |
|
|
|
|
<div className={`sol ${editorOptions.type} ${classList}`} data-id={editorOptions.errFile} onClick={() => handleErrorClick(editorOptions)}> |
|
|
|
|
{ editorOptions.useSpan ? <span> { messageText } </span> : <pre><span>{ messageText }</span></pre> } |
|
|
|
|
<div className="close" data-id="renderer" onClick={handleClose}> |
|
|
|
|
<i className="fas fa-times"></i> |
|
|
|
|