Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape dollar signs in completions returned by kernel #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
HELIUM_OBJECT_INSPECT_PANEL = "helium_object_inspect"

ANSI_ESCAPE_PATTERN = re.compile(r"\x1b[^m]*m")
DOLLAR_REGEX = re.compile(r"(?<!\\)\$")

OUTPUT_VIEW_SEPARATOR = "-" * 80

Expand Down Expand Up @@ -94,6 +95,14 @@ def remove_ansi_escape(text: str):
return ANSI_ESCAPE_PATTERN.sub("", text)


# Dollar sign have meanings in ST completions but not in Jupyter
# We must therefore escape them
def escape_dollar_signs(string):
"""Escape any dollar sign present in string"""
return DOLLAR_REGEX.sub(r'\\$', string)



def get_msg_type(message):
return message["header"]["msg_type"]

Expand Down Expand Up @@ -629,14 +638,14 @@ def get_complete(self, code, cursor_pos, timeout=None):
+ (
"<no type info>" if match["type"] is None else match["type"]
),
match["text"],
escape_dollar_signs(match["text"]),
)
for match in recv_content["metadata"]["_jupyter_types_experimental"]
]
else:
# Just say the completion is came from this plugin, otherwise.
return [
(match + "\tHelium", match) for match in recv_content["matches"]
(match + "\tHelium", escape_dollar_signs(match)) for match in recv_content["matches"]
]
except Empty:
self._logger.info("Completion timeout.")
Expand Down