def test_invalid_textxfile_diagnostics_on_doc_change(client_server): client, server = client_server doc = doc_from_path(TEXTXFILE_WITH_ERROR_PATH, 'textxfile') content = doc.text doc.text = '' # Add doc to server's workspace directly server.workspace.put_document(doc) versioned_doc = VersionedTextDocumentIdentifier(doc.uri, doc.version + 1) content_change = TextDocumentContentChangeEvent( Range(Position(0, 0), Position(0, 0)), 0, content ) send_text_doc_did_change_request(client, versioned_doc, [content_change]) params = builtin_notifications.get(timeout=CALL_TIMEOUT) assert params.uri == doc.uri d = params.diagnostics[0] r = d.range assert d.message == "Expected ',' or ']'" assert r.start.line == 0 assert r.start.character == 0 assert r.end.line == 0 assert r.end.character == 500 # Remove all docs from the workspace server.workspace._docs = {}
def test_document_multiline_edit(): old = ["def hello(a, b):\n", " print a\n", " print b\n"] doc = Document('file:///uri', u''.join(old)) 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"]
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"]
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", ]
def test_valid_textxfile_diagnostics_on_doc_change(client_server): client, server = client_server doc = doc_from_path(TEXTXFILE_PATH, 'textxfile') content = doc.text doc.text = '' # Add doc to server's workspace directly server.workspace.put_document(doc) versioned_doc = VersionedTextDocumentIdentifier(doc.uri, doc.version + 1) content_change = TextDocumentContentChangeEvent( Range(Position(0, 0), Position(0, 0)), 0, content ) send_text_doc_did_change_request(client, versioned_doc, [content_change]) params = builtin_notifications.get(timeout=CALL_TIMEOUT) assert params.uri == doc.uri assert params.diagnostics == [] # Remove all docs from the workspace server.workspace._docs = {}
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'
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'