Beispiel #1
0
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 = {}
Beispiel #2
0
 def lsp_text_document_edits(self) -> Iterator[TextDocumentEdit]:
     """Get all text document edits."""
     changed_files = self.refactoring.get_changed_files()
     for path, changed_file in changed_files.items():
         uri = path.as_uri()
         text_edits = lsp_text_edits(changed_file)
         yield TextDocumentEdit(
             text_document=VersionedTextDocumentIdentifier(
                 uri=uri,
                 version=None,  # type: ignore
             ),
             edits=text_edits,
         )
Beispiel #3
0
 def lsp_text_document_edits(self) -> Iterator[TextDocumentEdit]:
     """Get all text document edits."""
     changed_files = self.refactoring.get_changed_files()
     for path, changed_file in changed_files.items():
         uri = path.as_uri()
         document = self.workspace.get_document(uri)
         version = 0 if document.version is None else document.version
         text_edits = lsp_text_edits(changed_file)
         yield TextDocumentEdit(
             text_document=VersionedTextDocumentIdentifier(
                 uri=uri,
                 version=version,
             ),
             edits=text_edits,
         )
Beispiel #4
0
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 lsp_text_document_edits(self) -> Iterator[TextDocumentEdit]:
        """Get all text document edits.

        Note: version number defaults to `0` because the spec changed from 3.15
        to 3.16, introducing a new concept of
        `OptionalVersionedTextDocumentIdentifier` and disallowing a `null`
        version for `VersionedTextDocumentIdentifier`.

        TODO: more elegantly support textDocumentEdit versions in case they
        turn out to be either useful or necessary for some clients.
        """
        changed_files = self.refactoring.get_changed_files()
        for path, changed_file in changed_files.items():
            uri = path.as_uri()
            text_edits = lsp_text_edits(changed_file)
            yield TextDocumentEdit(
                text_document=VersionedTextDocumentIdentifier(
                    uri=uri,
                    version=0,
                ),
                edits=text_edits,
            )