From 06476f3a28ab874407596ae433802d07ca399d64 Mon Sep 17 00:00:00 2001 From: yeger Date: Fri, 21 Jun 2019 04:51:53 -0400 Subject: [PATCH] adding did change method --- classes.dot | 21 ++++++++++--------- pylspclient/lsp_client.py | 15 +++++++++++++- pylspclient/lsp_structs.py | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/classes.dot b/classes.dot index b88ad9f..39d9b6a 100644 --- a/classes.dot +++ b/classes.dot @@ -58,15 +58,18 @@ rankdir=BT "54" [label="Struct", shape="record"]; "55" [label="SymbolInformation", shape="record"]; "56" [label="SymbolKind", shape="record"]; -"57" [label="TextDocumentIdentifier", shape="record"]; -"58" [label="TextDocumentItem", shape="record"]; -"59" [label="TextDocumentPositionParams", shape="record"]; -"60" [label="TextEdit", shape="record"]; -"61" [label="TypeParameter", shape="record"]; -"62" [label="UnknownErrorCode", shape="record"]; -"63" [label="Variable", shape="record"]; -"64" [label="serverErrorEnd", shape="record"]; -"65" [label="serverErrorStart", shape="record"]; +"57" [label="TextDocumentContentChangeEvent", shape="record"]; +"58" [label="TextDocumentIdentifier", shape="record"]; +"59" [label="TextDocumentItem", shape="record"]; +"60" [label="TextDocumentPositionParams", shape="record"]; +"61" [label="TextEdit", shape="record"]; +"62" [label="TypeParameter", shape="record"]; +"63" [label="UnknownErrorCode", shape="record"]; +"64" [label="Variable", shape="record"]; +"65" [label="VersionedTextDocumentIdentifier", shape="record"]; +"66" [label="serverErrorEnd", shape="record"]; +"67" [label="serverErrorStart", shape="record"]; +"65" -> "58" [arrowhead="empty", arrowtail="none"]; "29" -> "55" [arrowhead="diamond", arrowtail="none", fontcolor="green", label="location", style="solid"]; "45" -> "47" [arrowhead="diamond", arrowtail="none", fontcolor="green", label="start", style="solid"]; "45" -> "47" [arrowhead="diamond", arrowtail="none", fontcolor="green", label="end", style="solid"]; diff --git a/pylspclient/lsp_client.py b/pylspclient/lsp_client.py index 2edae43..e7dce79 100644 --- a/pylspclient/lsp_client.py +++ b/pylspclient/lsp_client.py @@ -81,9 +81,22 @@ class LspClient(object): client needs to send a textDocument/didClose to the server followed by a textDocument/didOpen with the new language id if the server handles the new language id as well. - :param TextDocumentItem textDocument: The initial trace setting. If omitted trace is disabled ('off'). + :param TextDocumentItem textDocument: The document that was opened. """ return self.lsp_endpoint.send_notification("textDocument/didOpen", textDocument=textDocument) + + + def didChange(self, textDocument, contentChanges): + """ + The document change notification is sent from the client to the server to signal changes to a text document. + In 2.0 the shape of the params has changed to include proper version numbers and language ids. + + :param VersionedTextDocumentIdentifier textDocument: The initial trace setting. If omitted trace is disabled ('off'). + :param TextDocumentContentChangeEvent[] contentChanges: The actual content changes. The content changes describe single state changes + to the document. So if there are two content changes c1 and c2 for a document in state S then c1 move the document + to S' and c2 to S''. + """ + return self.lsp_endpoint.send_notification("textDocument/didChange", textDocument=textDocument, contentChanges=contentChanges) def documentSymbol(self, textDocument): diff --git a/pylspclient/lsp_structs.py b/pylspclient/lsp_structs.py index d5f09ed..1123839 100644 --- a/pylspclient/lsp_structs.py +++ b/pylspclient/lsp_structs.py @@ -160,6 +160,47 @@ class TextDocumentIdentifier(object): """ self.uri = uri + +class VersionedTextDocumentIdentifier(TextDocumentIdentifier): + """ + An identifier to denote a specific version of a text document. + """ + def __init__(self, uri, version): + """ + Constructs a new TextDocumentIdentifier instance. + + :param DocumentUri uri: The text document's URI. + :param int version: The version number of this document. If a versioned + text document identifier is sent from the server to the client and + the file is not open in the editor (the server has not received an + open notification before) the server can send `null` to indicate + that the version is known and the content on disk is the truth (as + speced with document content ownership). + The version number of a document will increase after each change, including + undo/redo. The number doesn't need to be consecutive. + """ + super(VersionedTextDocumentIdentifier, self).__init__(uri) + self.version = version + + +class TextDocumentContentChangeEvent(object): + """ + An event describing a change to a text document. If range and rangeLength are omitted + the new text is considered to be the full content of the document. + """ + def __init__(self, range, rangeLength, text): + """ + Constructs a new TextDocumentContentChangeEvent instance. + + :param Range range: The range of the document that changed. + :param int rangeLength: The length of the range that got replaced. + :param str text: The new text of the range/document. + """ + self.range = range + self.rangeLength = rangeLength + self.text = text + + class TextDocumentPositionParams(object): """ A parameter literal used in requests to pass a text document and a position inside that document.