def parse_line(line, document=None):
result = re.match(line_pattern, line)<EOL>if result:<EOL><INDENT>_, lineno, offset, severity, msg = result.groups()<EOL>lineno = int(lineno or <NUM_LIT:1>)<EOL>offset = int(offset or <NUM_LIT:0>)<EOL>errno = <NUM_LIT:2><EOL>if severity == '<STR_LIT:error>':<EOL><INDENT>errno = <NUM_LIT:1><EOL><DEDENT>diag = {<EOL>'<STR_LIT:source>': '<STR_LIT>',<EOL>'<STR_LIT>': {<EOL>'<STR_LIT:start>': {'<STR_LIT>': lineno - <NUM_LIT:1>, '<STR_LIT>': offset},<EOL>'<STR_LIT:end>': {'<STR_LIT>': lineno - <NUM_LIT:1>, '<STR_LIT>': offset + <NUM_LIT:1>}<EOL>},<EOL>'<STR_LIT:message>': msg,<EOL>'<STR_LIT>': errno<EOL>}<EOL>if document:<EOL><INDENT>word = document.word_at_position(diag['<STR_LIT>']['<STR_LIT:start>'])<EOL>if word:<EOL><INDENT>diag['<STR_LIT>']['<STR_LIT:end>']['<STR_LIT>'] = (<EOL>diag['<STR_LIT>']['<STR_LIT:start>']['<STR_LIT>'] + len(word))<EOL><DEDENT><DEDENT>return diag<EOL><DEDENT>
Return a language-server diagnostic from a line of the Mypy error report;
optionally, use the whole document to provide more context on it.