Ejemplo n.º 1
0
 def gather_diagnostics(self, doc):
     # Gather messages (per file)
     nbr_msgs = errorout_memory.Get_Nbr_Messages()
     diags = {}
     diag = {}
     for i in range(nbr_msgs):
         hdr = errorout_memory.Get_Error_Record(i + 1)
         msg = errorout_memory.Get_Error_Message(i + 1).decode("utf-8")
         if hdr.file == 0:
             # Possible for error limit reached.
             continue
         err_range = {
             "start": {
                 "line": hdr.line - 1,
                 "character": hdr.offset
             },
             "end": {
                 "line": hdr.line - 1,
                 "character": hdr.offset + hdr.length
             },
         }
         if hdr.group <= errorout_memory.Msg_Main:
             if hdr.id <= errorout.Msgid.Msgid_Note:
                 severity = lsp.DiagnosticSeverity.Information
             elif hdr.id <= errorout.Msgid.Msgid_Warning:
                 severity = lsp.DiagnosticSeverity.Warning
             else:
                 severity = lsp.DiagnosticSeverity.Error
             diag = {
                 "source": "ghdl",
                 "range": err_range,
                 "message": msg,
                 "severity": severity,
             }
             if hdr.group == errorout_memory.Msg_Main:
                 diag["relatedInformation"] = []
             fdiag = diags.get(hdr.file, None)
             if fdiag is None:
                 diags[hdr.file] = [diag]
             else:
                 fdiag.append(diag)
         else:
             assert diag
             if True:
                 doc = self.sfe_to_document(hdr.file)
                 diag["relatedInformation"].append({
                     "location": {
                         "uri": doc.uri,
                         "range": err_range
                     },
                     "message": msg,
                 })
     errorout_memory.Clear_Errors()
     # Publish diagnostics
     for sfe, diag in diags.items():
         doc = self.sfe_to_document(sfe)
         self.publish_diagnostics(doc.uri, diag)
     if doc is not None and doc._fe not in diags:
         # Clear previous diagnostics for the doc.
         self.publish_diagnostics(doc.uri, [])
Ejemplo n.º 2
0
def CheckForErrors() -> None:
    errorCount = errorout_memory.Get_Nbr_Messages()
    errors = []
    if errorCount != 0:
        for i in range(errorCount):
            rec = errorout_memory.Get_Error_Record(i + 1)
            # FIXME: needs help from @tgingold
            fileName = ""  # name_table.Get_Name_Ptr(files_map.Get_File_Name(rec.file))
            message = errorout_memory.Get_Error_Message(i + 1)

            errors.append(
                "{file}:{line}:{column}: {msg}".format(file=fileName, line=rec.line, column=rec.offset, msg=message)
            )

        raise DOMException("Error raised in libghdl.") from LibGHDLException("libghdl: Internal error.", errors)