Exemplo n.º 1
0
def _get_errors_from_tokens(node):
    for token in node.tokens:
        if token.type in (token.ERROR, token.FATAL_ERROR):
            start = (token.lineno - 1, token.col_offset)
            end = (token.lineno - 1, token.end_col_offset)
            error = Error(token.error, start, end)
            yield error
Exemplo n.º 2
0
    def m_lint(self, doc_uri):
        if not self._check_min_version((3, 2)):
            from robocorp_ls_core.lsp import Error

            msg = (
                "robotframework version (%s) too old for linting.\n"
                "Please install a newer version and restart the language server."
                % (self.m_version(), ))
            log.info(msg)
            return [Error(msg, (0, 0), (1, 0)).to_lsp_diagnostic()]

        func = partial(self._threaded_lint, doc_uri)
        func = require_monitor(func)
        return func
Exemplo n.º 3
0
def create_error_from_node(node, msg, tokens=None) -> Error:
    if tokens is None:
        tokens = node.tokens

    if not tokens:
        log.info("No tokens found when visiting: %s.", node.__class__)
        start = (0, 0)
        end = (0, 0)
    else:
        # line is 1-based and col is 0-based (make both 0-based for the error).
        start = (tokens[0].lineno - 1, tokens[0].col_offset)
        end = (tokens[-1].lineno - 1, tokens[-1].end_col_offset)

    error = Error(msg, start, end)
    return error
Exemplo n.º 4
0
def create_error_from_tokens(start_token,
                             end_token,
                             message: str,
                             source=None,
                             severity=DiagnosticSeverity.Error) -> Error:
    if not end_token:
        end_token = start_token

    return Error(message,
                 start=(start_token.lineno - 1,
                        start_token.col_offset) if start_token else (-1, -1),
                 end=(end_token.lineno - 1,
                      end_token.end_col_offset) if end_token else (-1, -1),
                 source=source or "robotframework_lsp",
                 severity=severity)