Module:ClangDiagnostic

From emmtrix Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:ClangDiagnostic/doc

local p = {}

-- Function to detect diagnostic type and format message
function p.format(frame)
    local message = frame.args[1] or ""
    local prefix, mainText = message:match("^([%w ]+:)(.*)$")
    local formattedMessage = ""

    -- Apply different formatting based on the diagnostic type
    if prefix and mainText then
    	local prefixStyle = "color: #007bfd; font-weight: bolder;"
    	local messageStyle = "color: #007bfd; font-weight: bolder;"
        if prefix:lower() == "error:" or prefix:lower() == "fatal error:"  then
    		prefixStyle = "color: #A00; font-weight: bolder;"
        elseif prefix:lower() == "warning:" then
    		prefixStyle = "color: #A0A; font-weight: bolder;"
        elseif prefix:lower() == "note:" then
    		prefixStyle = "color: #000; font-weight: bolder;"
    		messageStyle = "color: #007bfd;"
        elseif prefix:lower() == "remark:" then
    		prefixStyle = "color: #00A; font-weight: bolder;"
        end
        
        formattedMessage = string.format("<span style=\"%s\">%s</span><span style=\"%s\">%s</span>", prefixStyle, prefix, messageStyle, mainText)
    else
        -- If the message does not match the expected pattern, return it without modification
        formattedMessage = message
    end

    return formattedMessage
end

return p