Ejemplo n.º 1
0
    def _get_block_level_adjusted_error_span(self):
        block_start = self.currentBlock().position()
        block_end = self.currentBlock().position() + self.currentBlock().length() - 2
        if block_start > block_end:
            return None

        error_span = self._get_document_level_adjusted_error_span()
        if error_span is None:
            return None

        start = clamp(error_span.start_pos, block_start, block_end + 1) - block_start
        end = clamp(error_span.end_pos, block_start - 1, block_end) - block_start
        if start > end:
            return None

        return SourceSpan.from_start_end(start, end, self.currentBlock().text())
Ejemplo n.º 2
0
    def _get_document_level_adjusted_error_span(self):
        if self._error_span is None:
            return None

        source = self.document().toPlainText() + "\n"
        start = clamp(self._error_span.start_pos, 0, len(source) - 1)
        end = clamp(self._error_span.end_pos, start, len(source) - 1)

        # An error that occurs between two tokens will be extended backwards until it touches the last character in
        # the first token; this is so that we can be sure it shows up in the highlighter
        while start > 0 and str.isspace(source[start]):
            start -= 1

        while end > start and source[end] == "\n":
            end -= 1

        return SourceSpan.from_start_end(start, end, source)