From 13b66e2875a0146f7da033e18b370d21b5c4b7bc Mon Sep 17 00:00:00 2001 From: gregorni Date: Thu, 7 Sep 2023 21:59:20 +0200 Subject: [PATCH] Formatter: LSP: Return TextEdit as JSON --- blueprintcompiler/lsp.py | 6 ++++-- blueprintcompiler/lsp_utils.py | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/blueprintcompiler/lsp.py b/blueprintcompiler/lsp.py index 6c976a8..ad8a385 100644 --- a/blueprintcompiler/lsp.py +++ b/blueprintcompiler/lsp.py @@ -213,6 +213,7 @@ class LanguageServer: "hoverProvider": True, "documentSymbolProvider": True, "definitionProvider": True, + "documentFormattingProvider": True, }, "serverInfo": { "name": "Blueprint", @@ -310,8 +311,9 @@ class LanguageServer: if tag in ("replace", "insert", "delete"): lst.append( TextEdit( - Range(i1, i2), "" if tag == "delete" else formatted_blp[j1:j2] - ) + Range(i1, i2, open_file.text), + "" if tag == "delete" else formatted_blp[j1:j2], + ).to_json() ) self._send_response(id, lst) diff --git a/blueprintcompiler/lsp_utils.py b/blueprintcompiler/lsp_utils.py index 18c64af..60ddd4e 100644 --- a/blueprintcompiler/lsp_utils.py +++ b/blueprintcompiler/lsp_utils.py @@ -192,3 +192,6 @@ class LocationLink: class TextEdit: range: Range newText: str + + def to_json(self): + return {"range": self.range.to_json(), "newText": self.newText}