Vipitis commited on
Commit
c6524f1
1 Parent(s): 80cd783

Fix non unicode encoding

Browse files
Files changed (1) hide show
  1. utils/tree_utils.py +3 -3
utils/tree_utils.py CHANGED
@@ -13,7 +13,7 @@ def replace_function(old_func_node, new_func_node):
13
  tree = give_tree(old_func_node)
14
  old_func_start, old_func_end = node_str_idx(old_func_node)
15
  # new_func_start, new_func_end = node_str_idx(new_func_node)
16
- new_code = tree.text.decode()[:old_func_start] + new_func_node.text.decode() + tree.text.decode()[old_func_end:]
17
  return new_code
18
 
19
  def get_root(node):
@@ -47,7 +47,7 @@ def parse_functions(in_code):
47
  returns all functions in the code as their actual nodes.
48
  includes any comment made directly after the function definition or diretly after #copilot trigger
49
  """
50
- tree = parser.parse(bytes(in_code, "utf8"))
51
  funcs = [n for n in tree.root_node.children if n.type == "function_definition"]
52
 
53
  return funcs
@@ -81,7 +81,7 @@ def full_func_head(func_node) -> str:
81
  cursor.goto_next_sibling()
82
  end = cursor.node.start_point
83
  # return "\n".join(func_node.text.decode().split("\n")[:(end[0]-func_node.start_point[0])])[:-(last_char)-1]
84
- return func_node.text.decode()[:(last_char - func_node.start_byte)]
85
 
86
  def grab_before_comments(func_node):
87
  """
 
13
  tree = give_tree(old_func_node)
14
  old_func_start, old_func_end = node_str_idx(old_func_node)
15
  # new_func_start, new_func_end = node_str_idx(new_func_node)
16
+ new_code = tree.text[:old_func_start].decode() + new_func_node.text.decode() + tree.text[old_func_end:].decode()
17
  return new_code
18
 
19
  def get_root(node):
 
47
  returns all functions in the code as their actual nodes.
48
  includes any comment made directly after the function definition or diretly after #copilot trigger
49
  """
50
+ tree = parser.parse(bytes(in_code, encoding="utf-8"))
51
  funcs = [n for n in tree.root_node.children if n.type == "function_definition"]
52
 
53
  return funcs
 
81
  cursor.goto_next_sibling()
82
  end = cursor.node.start_point
83
  # return "\n".join(func_node.text.decode().split("\n")[:(end[0]-func_node.start_point[0])])[:-(last_char)-1]
84
+ return func_node.text[:(last_char - func_node.start_byte)].decode()
85
 
86
  def grab_before_comments(func_node):
87
  """