How to use the pygls.types.Position function in pygls

To help you get started, we’ve selected a few pygls examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_word_at_position(doc):
    """
    Return the position under the cursor (or last in line if past the end)
    """
    assert doc.word_at_position(Position(0, 8)) == 'document'
    assert doc.word_at_position(Position(0, 1000)) == 'document'
    assert doc.word_at_position(Position(1, 5)) == 'for'
    assert doc.word_at_position(Position(2, 0)) == 'testing'
    assert doc.word_at_position(Position(3, 10)) == 'unicode'
    assert doc.word_at_position(Position(4, 0)) == ''
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_word_at_position(doc):
    """
    Return the position under the cursor (or last in line if past the end)
    """
    assert doc.word_at_position(Position(0, 8)) == 'document'
    assert doc.word_at_position(Position(0, 1000)) == 'document'
    assert doc.word_at_position(Position(1, 5)) == 'for'
    assert doc.word_at_position(Position(2, 0)) == 'testing'
    assert doc.word_at_position(Position(3, 10)) == 'unicode'
    assert doc.word_at_position(Position(4, 0)) == ''
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_offset_at_position(doc):
    assert doc.offset_at_position(Position(0, 8)) == 8
    assert doc.offset_at_position(Position(1, 5)) == 14
    assert doc.offset_at_position(Position(2, 0)) == 13
    assert doc.offset_at_position(Position(2, 4)) == 17
    assert doc.offset_at_position(Position(3, 6)) == 27
    assert doc.offset_at_position(Position(3, 7)) == 27
    assert doc.offset_at_position(Position(3, 8)) == 28
    assert doc.offset_at_position(Position(4, 0)) == 39
    assert doc.offset_at_position(Position(5, 0)) == 39
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_offset_at_position(doc):
    assert doc.offset_at_position(Position(0, 8)) == 8
    assert doc.offset_at_position(Position(1, 5)) == 14
    assert doc.offset_at_position(Position(2, 0)) == 13
    assert doc.offset_at_position(Position(2, 4)) == 17
    assert doc.offset_at_position(Position(3, 6)) == 27
    assert doc.offset_at_position(Position(3, 7)) == 27
    assert doc.offset_at_position(Position(3, 8)) == 28
    assert doc.offset_at_position(Position(4, 0)) == 39
    assert doc.offset_at_position(Position(5, 0)) == 39
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_position_to_utf16():
    assert position_to_utf16(['x="😋"'], Position(0, 3)) == Position(0, 3)
    assert position_to_utf16(['x="😋"'], Position(0, 4)) == Position(0, 5)

    position = Position(0, 4)
    position_to_utf16(['x="😋"'], position)
    assert position == Position(0, 4)
github openlawlibrary / pygls / examples / json-extension / server / server.py View on Github external
def _validate_json(source):
    """Validates json file."""
    diagnostics = []

    try:
        json.loads(source)
    except JSONDecodeError as err:
        msg = err.msg
        col = err.colno
        line = err.lineno

        d = Diagnostic(
            Range(
                Position(line - 1, col - 1),
                Position(line - 1, col)
            ),
            msg,
            source=type(json_server).__name__
        )

        diagnostics.append(d)

    return diagnostics
github openlawlibrary / pygls / examples / json-extension / server / server.py View on Github external
def _validate_json(source):
    """Validates json file."""
    diagnostics = []

    try:
        json.loads(source)
    except JSONDecodeError as err:
        msg = err.msg
        col = err.colno
        line = err.lineno

        d = Diagnostic(
            Range(
                Position(line - 1, col - 1),
                Position(line - 1, col)
            ),
            msg,
            source=type(json_server).__name__
        )

        diagnostics.append(d)

    return diagnostics
github openlawlibrary / pygls / pygls / types.py View on Github external
def __eq__(self, other):
        return (
            isinstance(other, Position)
            and self.line == other.line
            and self.character == other.character)