From 32d2afb677095da1e2f63ba9b4f0bf321f1dc02e Mon Sep 17 00:00:00 2001
From: Moosems <95927277+Moosems@users.noreply.github.com>
Date: Wed, 10 Jul 2024 12:04:22 -0600
Subject: [PATCH] Fix bug when no new_tokens exist (#61)
* Fix bug when no new_tokens exist
if no new_tokens existed it would not give out any new tokens since the overwrite method did not have anything to compare against.
* Format
* Bump version
---
README.md | 2 +-
salve_ipc/server_functions/highlight/highlight.py | 2 +-
salve_ipc/server_functions/highlight/tokens.py | 3 +++
setup.py | 2 +-
tests/test_ipc.py | 9 +++++++++
5 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index bb94e93..1756809 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
Salve v0.7.0
+Salve v0.7.1
# Installation
diff --git a/salve_ipc/server_functions/highlight/highlight.py b/salve_ipc/server_functions/highlight/highlight.py
index 2f4ab64..1510170 100644
--- a/salve_ipc/server_functions/highlight/highlight.py
+++ b/salve_ipc/server_functions/highlight/highlight.py
@@ -50,7 +50,7 @@ def get_highlights(
# Lexer adds the newline back as its own token
continue
- if not token_str.strip() and new_type == "Text":
+ if not token_str.strip() or new_type == "Text":
# If the token is empty or is plain Text we simply skip it because thats ultimately useless info
start_index = (start_index[0], start_index[1] + token_len)
continue
diff --git a/salve_ipc/server_functions/highlight/tokens.py b/salve_ipc/server_functions/highlight/tokens.py
index 32c08b0..3e72ac4 100644
--- a/salve_ipc/server_functions/highlight/tokens.py
+++ b/salve_ipc/server_functions/highlight/tokens.py
@@ -103,6 +103,9 @@ def merge_tokens(tokens: list[Token]) -> list[Token]:
def overwrite_tokens(old_tokens: list[Token], new_tokens: list[Token]):
+ if not new_tokens:
+ return old_tokens
+
output_tokens: list[Token] = []
dont_add_tokens: list[Token] = []
for new_token in new_tokens:
diff --git a/setup.py b/setup.py
index 1fae367..2e41857 100644
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@
setup(
name="salve_ipc",
- version="0.7.0",
+ version="0.7.1",
description="Salve is an IPC library that can be used by code editors to easily get autocompletions, replacements, editorconfig suggestions, definitions, and syntax highlighting.",
author="Moosems",
author_email="moosems.j@gmail.com",
diff --git a/tests/test_ipc.py b/tests/test_ipc.py
index b4c0cbc..8e1a0d8 100644
--- a/tests/test_ipc.py
+++ b/tests/test_ipc.py
@@ -168,6 +168,15 @@ def test_IPC():
assert highlight_output == expected_output
+ context.update_file(
+ "foo", open(Path("tests/testing_file2.py"), "r+").read()
+ )
+ context.request(HIGHLIGHT, file="foo", language="python")
+ while not (output := context.get_response(HIGHLIGHT)):
+ pass
+ response = output["result"] # type: ignore
+ assert response != []
+
context.remove_file("test")
context.kill_IPC()