How to use the pygls.workspace.Document 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_document_multiline_edit():
    old = [
        "def hello(a, b):\n",
        "    print a\n",
        "    print b\n"
    ]
    doc = Document('file:///uri', u''.join(old), sync_kind=TextDocumentSyncKind.INCREMENTAL)
    change = TextDocumentContentChangeEvent(
        Range(Position(1, 4), Position(2, 11)), 0, u'print a, b')
    doc.apply_change(change)

    assert doc.lines == [
        "def hello(a, b):\n",
        "    print a, b\n"
    ]

    doc = Document('file:///uri', u''.join(old), sync_kind=TextDocumentSyncKind.INCREMENTAL)
    change = TextDocumentContentChangeEvent(
        range=Range(Position(1, 4), Position(2, 11)), text=u'print a, b')
    doc.apply_change(change)

    assert doc.lines == [
        "def hello(a, b):\n",
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_document_line_edit():
    doc = Document('file:///uri', u'itshelloworld')
    change = TextDocumentContentChangeEvent(
        Range(Position(0, 3), Position(0, 8)), 0, u'goodbye')
    doc.apply_change(change)
    assert doc.source == u'itsgoodbyeworld'
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_document_full_edit():
    old = [
        "def hello(a, b):\n",
        "    print a\n",
        "    print b\n"
    ]
    doc = Document('file:///uri', u''.join(old), sync_kind=TextDocumentSyncKind.FULL)
    change = TextDocumentContentChangeEvent(
        Range(Position(1, 4), Position(2, 11)), 0, u'print a, b')
    doc.apply_change(change)

    assert doc.lines == [
        "print a, b"
    ]

    doc = Document('file:///uri', u''.join(old), sync_kind=TextDocumentSyncKind.FULL)
    change = TextDocumentContentChangeEvent(range=None, text=u'print a, b')
    doc.apply_change(change)

    assert doc.lines == [
        "print a, b"
    ]
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_document_end_of_file_edit():
    old = [
        "print 'a'\n",
        "print 'b'\n"
    ]
    doc = Document('file:///uri', u''.join(old))

    change = TextDocumentContentChangeEvent(
        Range(Position(2, 0), Position(2, 0)), 0, u'o')
    doc.apply_change(change)

    assert doc.lines == [
        "print 'a'\n",
        "print 'b'\n",
        "o",
    ]
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_document_empty_edit():
    doc = Document('file:///uri', u'')
    change = TextDocumentContentChangeEvent(
        Range(Position(0, 0), Position(0, 0)), 0, u'f')
    doc.apply_change(change)
    assert doc.source == u'f'
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_document_no_edit():
    old = [
        "def hello(a, b):\n",
        "    print a\n",
        "    print b\n"
    ]
    doc = Document('file:///uri', u''.join(old), sync_kind=TextDocumentSyncKind.NONE)
    change = TextDocumentContentChangeEvent(
        Range(Position(1, 4), Position(2, 11)), 0, u'print a, b')
    doc.apply_change(change)

    assert doc.lines == old
github openlawlibrary / pygls / tests / test_document.py View on Github external
def test_document_source_unicode():
    document_mem = Document(DOC_URI, u'my source')
    document_disk = Document(DOC_URI)
    assert isinstance(document_mem.source, type(document_disk.source))
github openlawlibrary / pygls / tests / fixtures.py View on Github external
def doc():
    return Document(DOC_URI, DOC)
github openlawlibrary / pygls / pygls / workspace.py View on Github external
def _create_document(self,
                         doc_uri: str,
                         source: str = None,
                         version: NumType = None) -> Document:
        return Document(doc_uri, source=source, version=version,
                        sync_kind=self._sync_kind)