parent
f46484b754
commit
de9c5d7222
@ -1,71 +1,97 @@ |
|||||||
import { CustomTooltip } from '@remix-ui/helper'; |
import { CustomTooltip } from "@remix-ui/helper"; |
||||||
import React from 'react' //eslint-disable-line
|
import React from "react"; //eslint-disable-line
|
||||||
|
import { RemixUiStaticAnalyserState } from "../staticanalyser"; |
||||||
|
|
||||||
interface ErrorRendererProps { |
interface ErrorRendererProps { |
||||||
message: any; |
message: any; |
||||||
opt: any, |
opt: any; |
||||||
warningErrors: any |
warningErrors: any; |
||||||
editor: any, |
editor: any; |
||||||
name: string, |
name: string; |
||||||
|
ssaState: RemixUiStaticAnalyserState |
||||||
} |
} |
||||||
|
|
||||||
const ErrorRenderer = ({ message, opt, editor, name }: ErrorRendererProps) => { |
const ErrorRenderer = ({ message, opt, editor, name, ssaState }: ErrorRendererProps) => { |
||||||
const getPositionDetails = (msg: any) => { |
const getPositionDetails = (msg: any) => { |
||||||
const result = { } as Record<string, number | string> |
const result = {} as Record<string, number | string>; |
||||||
|
|
||||||
// To handle some compiler warning without location like SPDX license warning etc
|
// To handle some compiler warning without location like SPDX license warning etc
|
||||||
if (!msg.includes(':')) return { errLine: -1, errCol: -1, errFile: msg } |
if (!msg.includes(":")) return { errLine: -1, errCol: -1, errFile: msg }; |
||||||
|
|
||||||
// extract line / column
|
// extract line / column
|
||||||
let position = msg.match(/^(.*?):([0-9]*?):([0-9]*?)?/) |
let position = msg.match(/^(.*?):([0-9]*?):([0-9]*?)?/); |
||||||
result.errLine = position ? parseInt(position[2]) - 1 : -1 |
result.errLine = position ? parseInt(position[2]) - 1 : -1; |
||||||
result.errCol = position ? parseInt(position[3]) : -1 |
result.errCol = position ? parseInt(position[3]) : -1; |
||||||
|
|
||||||
// extract file
|
// extract file
|
||||||
position = msg.match(/^(https:.*?|http:.*?|.*?):/) |
position = msg.match(/^(https:.*?|http:.*?|.*?):/); |
||||||
result.errFile = position ? position[1] : '' |
result.errFile = position ? position[1] : ""; |
||||||
return result |
return result; |
||||||
} |
}; |
||||||
|
|
||||||
const handlePointToErrorOnClick = async (location, fileName) => { |
const handlePointToErrorOnClick = async (location, fileName) => { |
||||||
await editor.call('editor', 'discardHighlight') |
await editor.call("editor", "discardHighlight"); |
||||||
await editor.call('editor', 'highlight', location, fileName, '', { focus: true }) |
await editor.call("editor", "highlight", location, fileName, "", { |
||||||
} |
focus: true, |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
if (!message) return |
if (!message) return; |
||||||
let position = getPositionDetails(message) |
let position = getPositionDetails(message); |
||||||
if (!position.errFile || (opt.errorType && opt.errorType === position.errFile)) { |
if ( |
||||||
|
!position.errFile || |
||||||
|
(opt.errorType && opt.errorType === position.errFile) |
||||||
|
) { |
||||||
// Updated error reported includes '-->' before file details
|
// Updated error reported includes '-->' before file details
|
||||||
const errorDetails = message.split('-->') |
const errorDetails = message.split("-->"); |
||||||
// errorDetails[1] will have file details
|
// errorDetails[1] will have file details
|
||||||
if (errorDetails.length > 1) position = getPositionDetails(errorDetails[1]) |
if (errorDetails.length > 1) position = getPositionDetails(errorDetails[1]); |
||||||
} |
} |
||||||
opt.errLine = position.errLine |
opt.errLine = position.errLine; |
||||||
opt.errCol = position.errCol |
opt.errCol = position.errCol; |
||||||
opt.errFile = position.errFile.trim() |
opt.errFile = position.errFile.trim(); |
||||||
const classList = opt.type === 'error' ? 'alert alert-danger' : 'alert alert-warning' |
const classList = |
||||||
|
opt.type === "error" ? "alert alert-danger" : "alert alert-warning"; |
||||||
return ( |
return ( |
||||||
<div> |
<div> |
||||||
<div className={`sol ${opt.type} ${classList}`}> |
<div className={`sol ${opt.type} ${classList}`}> |
||||||
<span className='d-flex flex-column' data-id={`${name}Button`} onClick={async () => await handlePointToErrorOnClick(opt.location, opt.fileName)} style={{ cursor: "pointer", overflow: 'hidden', textOverflow: 'ellipsis' }}> |
<div |
||||||
<span className='h6 font-weight-bold'>{opt.name}</span> |
className="d-flex flex-column" |
||||||
<span>{ opt.item.warning }</span> |
data-id={`${name}Button`} |
||||||
{opt.item.more |
onClick={async () => |
||||||
? <span><a href={opt.item.more} target='_blank'>more</a></span> |
await handlePointToErrorOnClick(opt.location, opt.fileName) |
||||||
: <span> </span> |
|
||||||
} |
} |
||||||
<CustomTooltip |
style={{ |
||||||
placement="right" |
cursor: "pointer", |
||||||
tooltipId="errorTooltip" |
overflow: "hidden", |
||||||
tooltipText={`Position in ${opt.errFile}`} |
textOverflow: "ellipsis", |
||||||
tooltipClasses="text-nowrap" |
}} |
||||||
> |
> |
||||||
<span>Pos: {opt.locationString}</span> |
<span className="h6 font-weight-bold">{opt.name}</span> |
||||||
</CustomTooltip> |
<span>{opt.item.warning}</span> |
||||||
</span> |
{opt.item.more ? ( |
||||||
|
<span> |
||||||
|
<a href={opt.item.more} target="_blank"> |
||||||
|
more |
||||||
|
</a> |
||||||
|
</span> |
||||||
|
) : ( |
||||||
|
<span> </span> |
||||||
|
)} |
||||||
|
<div> |
||||||
|
<CustomTooltip |
||||||
|
placement="right" |
||||||
|
tooltipId="errorTooltip" |
||||||
|
tooltipText={`Position in ${ssaState.file}`} |
||||||
|
tooltipClasses="text-nowrap" |
||||||
|
> |
||||||
|
<span>Pos: {opt.locationString}</span> |
||||||
|
</CustomTooltip> |
||||||
|
</div> |
||||||
|
</div> |
||||||
</div> |
</div> |
||||||
</div> |
</div> |
||||||
) |
); |
||||||
} |
}; |
||||||
|
|
||||||
export default ErrorRenderer |
export default ErrorRenderer; |
||||||
|
Loading…
Reference in new issue