sia_tp_sample / AlphaMycelium__pathfinder.vim.jsonl
shahp7575's picture
commit files to HF hub
3a7f06a
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/debytes.py","language":"python","identifier":"debytes","parameters":"(string)","argument_list":"","return_statement":"","docstring":"Decode string if it is a bytes object.\n\n This is necessary since Neovim, correctly, gives strings as a str, but regular\n Vim leaves them encoded as bytes.","docstring_summary":"Decode string if it is a bytes object.","docstring_tokens":["Decode","string","if","it","is","a","bytes","object","."],"function":"def debytes(string):\n \"\"\"\n Decode string if it is a bytes object.\n\n This is necessary since Neovim, correctly, gives strings as a str, but regular\n Vim leaves them encoded as bytes.\n \"\"\"\n try:\n return string.decode()\n except AttributeError:\n return string","function_tokens":["def","debytes","(","string",")",":","try",":","return","string",".","decode","(",")","except","AttributeError",":","return","string"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/debytes.py#L1-L11"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/window.py","language":"python","identifier":"cursor_in_same_position","parameters":"(a, b)","argument_list":"","return_statement":"return a.lnum == b.lnum and a.col == b.col","docstring":"Check if the given views have the cursor on the same position.\n\n The scroll position and other properties may differ.","docstring_summary":"Check if the given views have the cursor on the same position.","docstring_tokens":["Check","if","the","given","views","have","the","cursor","on","the","same","position","."],"function":"def cursor_in_same_position(a, b):\n \"\"\"\n Check if the given views have the cursor on the same position.\n\n The scroll position and other properties may differ.\n \"\"\"\n return a.lnum == b.lnum and a.col == b.col","function_tokens":["def","cursor_in_same_position","(","a",",","b",")",":","return","a",".","lnum","==","b",".","lnum","and","a",".","col","==","b",".","col"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/window.py#L19-L25"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/server.py","language":"python","identifier":"Server.message_loop","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Continuously wait for and handle instructions from the client.\n\n This waiting blocks Vim, but that does not matter since nobody is looking at\n it. Blocking also prevents CPU resources from being wasted on redrawing.\n\n :raises EOFError: when the connection is closed.","docstring_summary":"Continuously wait for and handle instructions from the client.","docstring_tokens":["Continuously","wait","for","and","handle","instructions","from","the","client","."],"function":"def message_loop(self):\n \"\"\"\n Continuously wait for and handle instructions from the client.\n\n This waiting blocks Vim, but that does not matter since nobody is looking at\n it. Blocking also prevents CPU resources from being wasted on redrawing.\n\n :raises EOFError: when the connection is closed.\n \"\"\"\n while True:\n try:\n data = self.client_connection.recv()\n\n # If there is still data waiting, then multiple requests were sent,\n # so we skip pathfinding and move on to the next one\n if not self.client_connection.poll():\n self.do_action(data)\n except:\n # Send any unexpected exceptions back to the client\n # to be displayed for debugging purposes\n self.client_connection.send((\"ERROR\", traceback.format_exc()))","function_tokens":["def","message_loop","(","self",")",":","while","True",":","try",":","data","=","self",".","client_connection",".","recv","(",")","# If there is still data waiting, then multiple requests were sent,","# so we skip pathfinding and move on to the next one","if","not","self",".","client_connection",".","poll","(",")",":","self",".","do_action","(","data",")","except",":","# Send any unexpected exceptions back to the client","# to be displayed for debugging purposes","self",".","client_connection",".","send","(","(","\"ERROR\"",",","traceback",".","format_exc","(",")",")",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/server.py#L41-L61"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/server.py","language":"python","identifier":"Server.do_action","parameters":"(self, data)","argument_list":"","return_statement":"","docstring":"Process an instruction from the client.","docstring_summary":"Process an instruction from the client.","docstring_tokens":["Process","an","instruction","from","the","client","."],"function":"def do_action(self, data):\n \"\"\"Process an instruction from the client.\"\"\"\n self.start_view = data[\"start\"]\n self.target_view = data[\"target\"]\n self.min_line = data[\"min_line\"]\n self.max_line = data[\"max_line\"]\n\n vim.current.buffer[:] = data[\"buffer\"]\n\n vim.current.window.options[\"wrap\"] = data[\"wrap\"]\n vim.options[\"scrolloff\"] = data[\"scrolloff\"]\n vim.options[\"sidescrolloff\"] = data[\"sidescrolloff\"]\n\n # Set size of the entire Vim display to match the size of the\n # corresponding window in the client\n vim.options[\"columns\"] = int(data[\"size\"][0])\n vim.options[\"lines\"] = vim.options[\"cmdheight\"] + int(data[\"size\"][1])\n\n self.pathfind()","function_tokens":["def","do_action","(","self",",","data",")",":","self",".","start_view","=","data","[","\"start\"","]","self",".","target_view","=","data","[","\"target\"","]","self",".","min_line","=","data","[","\"min_line\"","]","self",".","max_line","=","data","[","\"max_line\"","]","vim",".","current",".","buffer","[",":","]","=","data","[","\"buffer\"","]","vim",".","current",".","window",".","options","[","\"wrap\"","]","=","data","[","\"wrap\"","]","vim",".","options","[","\"scrolloff\"","]","=","data","[","\"scrolloff\"","]","vim",".","options","[","\"sidescrolloff\"","]","=","data","[","\"sidescrolloff\"","]","# Set size of the entire Vim display to match the size of the","# corresponding window in the client","vim",".","options","[","\"columns\"","]","=","int","(","data","[","\"size\"","]","[","0","]",")","vim",".","options","[","\"lines\"","]","=","vim",".","options","[","\"cmdheight\"","]","+","int","(","data","[","\"size\"","]","[","1","]",")","self",".","pathfind","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/server.py#L63-L81"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/server.py","language":"python","identifier":"Server.pathfind","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Run the pathfinder, then send the result back to the client.","docstring_summary":"Run the pathfinder, then send the result back to the client.","docstring_tokens":["Run","the","pathfinder","then","send","the","result","back","to","the","client","."],"function":"def pathfind(self):\n \"\"\"Run the pathfinder, then send the result back to the client.\"\"\"\n dijkstra = Dijkstra(\n self.start_view, self.target_view, self.min_line, self.max_line\n )\n motions = dijkstra.find_path(self.client_connection)\n\n # If motions is None, that means we cancelled pathfinding because a new\n # request was received. We also check for another request now in case one was\n # sent during the last iteration of the pathfinding loop.\n if not (motions is None or self.client_connection.poll()):\n self.client_connection.send((\"RESULT\", motions))","function_tokens":["def","pathfind","(","self",")",":","dijkstra","=","Dijkstra","(","self",".","start_view",",","self",".","target_view",",","self",".","min_line",",","self",".","max_line",")","motions","=","dijkstra",".","find_path","(","self",".","client_connection",")","# If motions is None, that means we cancelled pathfinding because a new","# request was received. We also check for another request now in case one was","# sent during the last iteration of the pathfinding loop.","if","not","(","motions","is","None","or","self",".","client_connection",".","poll","(",")",")",":","self",".","client_connection",".","send","(","(","\"RESULT\"",",","motions",")",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/server.py#L83-L94"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/dijkstra.py","language":"python","identifier":"Dijkstra.find_path","parameters":"(self, client_connection)","argument_list":"","return_statement":"","docstring":"Use Dijkstra's algorithm to find the optimal sequence of motions.\n\n :param client_connection: If another pathfinding request is waiting on this\n connection, exit (returning None) as soon as possible. This cancels the\n pathfinding, moving on to the new request immediately.","docstring_summary":"Use Dijkstra's algorithm to find the optimal sequence of motions.","docstring_tokens":["Use","Dijkstra","s","algorithm","to","find","the","optimal","sequence","of","motions","."],"function":"def find_path(self, client_connection):\n \"\"\"\n Use Dijkstra's algorithm to find the optimal sequence of motions.\n\n :param client_connection: If another pathfinding request is waiting on this\n connection, exit (returning None) as soon as possible. This cancels the\n pathfinding, moving on to the new request immediately.\n \"\"\"\n while len(self._open_queue) > 0 and not client_connection.poll():\n current_node_key, current_distance = self._open_queue.popitem()\n current_node = self._open_nodes.pop(current_node_key)\n self._closed_nodes.add(current_node_key)\n\n if current_node.is_target():\n return current_node.reconstruct_path()\n\n for node in current_node.get_neighbours():\n if node.key in self._closed_nodes:\n continue\n\n new_distance = current_distance + current_node.motion_weight(\n node.came_by_motion\n )\n if (\n node.key not in self._open_nodes\n or new_distance < self._open_queue[node.key]\n ):\n node.set_came_from(current_node)\n self._open_nodes[node.key] = node\n self._open_queue[node.key] = new_distance","function_tokens":["def","find_path","(","self",",","client_connection",")",":","while","len","(","self",".","_open_queue",")",">","0","and","not","client_connection",".","poll","(",")",":","current_node_key",",","current_distance","=","self",".","_open_queue",".","popitem","(",")","current_node","=","self",".","_open_nodes",".","pop","(","current_node_key",")","self",".","_closed_nodes",".","add","(","current_node_key",")","if","current_node",".","is_target","(",")",":","return","current_node",".","reconstruct_path","(",")","for","node","in","current_node",".","get_neighbours","(",")",":","if","node",".","key","in","self",".","_closed_nodes",":","continue","new_distance","=","current_distance","+","current_node",".","motion_weight","(","node",".","came_by_motion",")","if","(","node",".","key","not","in","self",".","_open_nodes","or","new_distance","<","self",".","_open_queue","[","node",".","key","]",")",":","node",".","set_came_from","(","current_node",")","self",".","_open_nodes","[","node",".","key","]","=","node","self",".","_open_queue","[","node",".","key","]","=","new_distance"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/dijkstra.py#L39-L68"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/node.py","language":"python","identifier":"Node.get_neighbours","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Yield all neighbours of this node.","docstring_summary":"Yield all neighbours of this node.","docstring_tokens":["Yield","all","neighbours","of","this","node","."],"function":"def get_neighbours(self):\n \"\"\"Yield all neighbours of this node.\"\"\"\n for motion_generator in self.dijkstra.motion_generators:\n for node in motion_generator.generate(self.view):\n if (\n node.view.lnum >= self.dijkstra.min_line\n and node.view.lnum <= self.dijkstra.max_line\n ):\n yield node","function_tokens":["def","get_neighbours","(","self",")",":","for","motion_generator","in","self",".","dijkstra",".","motion_generators",":","for","node","in","motion_generator",".","generate","(","self",".","view",")",":","if","(","node",".","view",".","lnum",">=","self",".","dijkstra",".","min_line","and","node",".","view",".","lnum","<=","self",".","dijkstra",".","max_line",")",":","yield","node"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/node.py#L17-L25"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/node.py","language":"python","identifier":"Node.motion_weight","parameters":"(self, motion)","argument_list":"","return_statement":"","docstring":"Return the weight of using a motion from this node.","docstring_summary":"Return the weight of using a motion from this node.","docstring_tokens":["Return","the","weight","of","using","a","motion","from","this","node","."],"function":"def motion_weight(self, motion):\n \"\"\"Return the weight of using a motion from this node.\"\"\"\n if motion != self.came_by_motion:\n # First repetition, return number of characters in the motion\n return len(motion.motion) + (\n 0 if motion.argument is None else len(motion.argument)\n )\n elif self.came_by_motion_repetitions == 1:\n # Second repetition, adding a \"2\" is 1 extra character\n return 1\n else:\n # Difference in length of current and future count\n # 2j -> 3j = 0\n # 9j -> 10j = 1\n return len(str(self.came_by_motion_repetitions + 1)) - len(\n str(self.came_by_motion_repetitions)\n )","function_tokens":["def","motion_weight","(","self",",","motion",")",":","if","motion","!=","self",".","came_by_motion",":","# First repetition, return number of characters in the motion","return","len","(","motion",".","motion",")","+","(","0","if","motion",".","argument","is","None","else","len","(","motion",".","argument",")",")","elif","self",".","came_by_motion_repetitions","==","1",":","# Second repetition, adding a \"2\" is 1 extra character","return","1","else",":","# Difference in length of current and future count","# 2j -> 3j = 0","# 9j -> 10j = 1","return","len","(","str","(","self",".","came_by_motion_repetitions","+","1",")",")","-","len","(","str","(","self",".","came_by_motion_repetitions",")",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/node.py#L27-L43"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/node.py","language":"python","identifier":"Node.set_came_from","parameters":"(self, node)","argument_list":"","return_statement":"","docstring":"Set the node this node was reached from.","docstring_summary":"Set the node this node was reached from.","docstring_tokens":["Set","the","node","this","node","was","reached","from","."],"function":"def set_came_from(self, node):\n \"\"\"Set the node this node was reached from.\"\"\"\n self.came_from = node\n\n if node.came_by_motion == self.came_by_motion:\n self.came_by_motion_repetitions = node.came_by_motion_repetitions + 1\n else:\n self.came_by_motion_repetitions = 1","function_tokens":["def","set_came_from","(","self",",","node",")",":","self",".","came_from","=","node","if","node",".","came_by_motion","==","self",".","came_by_motion",":","self",".","came_by_motion_repetitions","=","node",".","came_by_motion_repetitions","+","1","else",":","self",".","came_by_motion_repetitions","=","1"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/node.py#L45-L52"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/node.py","language":"python","identifier":"Node.reconstruct_path","parameters":"(self)","argument_list":"","return_statement":"return motions","docstring":"Return the sequence of motions used to reach this node.","docstring_summary":"Return the sequence of motions used to reach this node.","docstring_tokens":["Return","the","sequence","of","motions","used","to","reach","this","node","."],"function":"def reconstruct_path(self):\n \"\"\"Return the sequence of motions used to reach this node.\"\"\"\n motions = list()\n node = self\n while node.came_from is not None:\n motions.insert(0, node.came_by_motion)\n node = node.came_from\n return motions","function_tokens":["def","reconstruct_path","(","self",")",":","motions","=","list","(",")","node","=","self","while","node",".","came_from","is","not","None",":","motions",".","insert","(","0",",","node",".","came_by_motion",")","node","=","node",".","came_from","return","motions"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/node.py#L57-L64"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/motions\/search.py","language":"python","identifier":"SearchMotionGenerator._escape_magic","parameters":"(self, search_query)","argument_list":"","return_statement":"return search_query","docstring":"Add backslash escapes to any \"magic\" characters in a query.","docstring_summary":"Add backslash escapes to any \"magic\" characters in a query.","docstring_tokens":["Add","backslash","escapes","to","any","magic","characters","in","a","query","."],"function":"def _escape_magic(self, search_query):\n \"\"\"Add backslash escapes to any \"magic\" characters in a query.\"\"\"\n for char in r\"\\^$.*[~\/\":\n search_query = search_query.replace(char, \"\\\\\" + char)\n return search_query","function_tokens":["def","_escape_magic","(","self",",","search_query",")",":","for","char","in","r\"\\^$.*[~\/\"",":","search_query","=","search_query",".","replace","(","char",",","\"\\\\\"","+","char",")","return","search_query"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/motions\/search.py#L27-L31"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/motions\/search.py","language":"python","identifier":"SearchMotionGenerator._search","parameters":"(self, text, start, target)","argument_list":"","return_statement":"","docstring":"Return the simplest possible searching motion to reach the given target.\n\n :param text: Contents of the file.\n :param start: Index in ``text`` to start the search from.\n :param target: Index of the target position in ``text``.","docstring_summary":"Return the simplest possible searching motion to reach the given target.","docstring_tokens":["Return","the","simplest","possible","searching","motion","to","reach","the","given","target","."],"function":"def _search(self, text, start, target):\n \"\"\"\n Return the simplest possible searching motion to reach the given target.\n\n :param text: Contents of the file.\n :param start: Index in ``text`` to start the search from.\n :param target: Index of the target position in ``text``.\n \"\"\"\n search_text = text[target:]\n\n # (\"a\", \"ab\", \"abc\", \"abcd\"...) until we reach\n # the end of search_text or find a working query\n for query_length in range(1, len(search_text) + 1):\n query = search_text[:query_length]\n\n # Get a list of all match positions for this search query\n # query=\"x\" text=\"x___x_xx\" == [0, 4, 6, 7]\n pattern = re.escape(query)\n matches = [m.start() for m in re.finditer(pattern, text)]\n\n if matches:\n # Sort the list so it begins with matches after `start`, rather\n # than matches at the beginning of the file\n # sorted([True, False]) == [False, True]\n matches.sort(key=lambda position: position <= start)\n\n if matches[0] == target:\n return self._create_motion(query)\n if matches[-1] == target:\n return self._create_motion(query, \"?\")","function_tokens":["def","_search","(","self",",","text",",","start",",","target",")",":","search_text","=","text","[","target",":","]","# (\"a\", \"ab\", \"abc\", \"abcd\"...) until we reach","# the end of search_text or find a working query","for","query_length","in","range","(","1",",","len","(","search_text",")","+","1",")",":","query","=","search_text","[",":","query_length","]","# Get a list of all match positions for this search query","# query=\"x\" text=\"x___x_xx\" == [0, 4, 6, 7]","pattern","=","re",".","escape","(","query",")","matches","=","[","m",".","start","(",")","for","m","in","re",".","finditer","(","pattern",",","text",")","]","if","matches",":","# Sort the list so it begins with matches after `start`, rather","# than matches at the beginning of the file","# sorted([True, False]) == [False, True]","matches",".","sort","(","key","=","lambda","position",":","position","<=","start",")","if","matches","[","0","]","==","target",":","return","self",".","_create_motion","(","query",")","if","matches","[","-","1","]","==","target",":","return","self",".","_create_motion","(","query",",","\"?\"",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/motions\/search.py#L33-L62"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/motions\/search.py","language":"python","identifier":"SearchMotionGenerator._search_lines","parameters":"(self, lines, start_line, start_col, target_line, target_col)","argument_list":"","return_statement":"return self._search(text, start, target)","docstring":"Wrapper around _search which handles 2d coordinates and a list of lines.\n\n :param lines: List of lines.\n :param start_line: Starting line, indexed from 0.\n :param start_col: Starting column.\n :param target_line: Target line, indexed from 0.\n :param target_col: Target column.","docstring_summary":"Wrapper around _search which handles 2d coordinates and a list of lines.","docstring_tokens":["Wrapper","around","_search","which","handles","2d","coordinates","and","a","list","of","lines","."],"function":"def _search_lines(self, lines, start_line, start_col, target_line, target_col):\n \"\"\"\n Wrapper around _search which handles 2d coordinates and a list of lines.\n\n :param lines: List of lines.\n :param start_line: Starting line, indexed from 0.\n :param start_col: Starting column.\n :param target_line: Target line, indexed from 0.\n :param target_col: Target column.\n \"\"\"\n text = \"\\n\".join(lines)\n start = sum(len(line) + 1 for line in lines[:start_line]) + start_col\n target = sum(len(line) + 1 for line in lines[:target_line]) + target_col\n return self._search(text, start, target)","function_tokens":["def","_search_lines","(","self",",","lines",",","start_line",",","start_col",",","target_line",",","target_col",")",":","text","=","\"\\n\"",".","join","(","lines",")","start","=","sum","(","len","(","line",")","+","1","for","line","in","lines","[",":","start_line","]",")","+","start_col","target","=","sum","(","len","(","line",")","+","1","for","line","in","lines","[",":","target_line","]",")","+","target_col","return","self",".","_search","(","text",",","start",",","target",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/motions\/search.py#L64-L77"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/motions\/simple.py","language":"python","identifier":"SimpleMotionGenerator._try_motion","parameters":"(self, view, motion)","argument_list":"","return_statement":"return winsaveview()","docstring":"Use a motion inside Vim, starting from the given view.\n\n If the motion causes an error, return None.","docstring_summary":"Use a motion inside Vim, starting from the given view.","docstring_tokens":["Use","a","motion","inside","Vim","starting","from","the","given","view","."],"function":"def _try_motion(self, view, motion):\n \"\"\"\n Use a motion inside Vim, starting from the given view.\n\n If the motion causes an error, return None.\n \"\"\"\n winrestview(view)\n try:\n vim.command(f\"silent! normal! {motion}\")\n except:\n return None\n return winsaveview()","function_tokens":["def","_try_motion","(","self",",","view",",","motion",")",":","winrestview","(","view",")","try",":","vim",".","command","(","f\"silent! normal! {motion}\"",")","except",":","return","None","return","winsaveview","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/motions\/simple.py#L73-L84"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/server\/motions\/__init__.py","language":"python","identifier":"MotionGenerator.generate","parameters":"(self, view)","argument_list":"","return_statement":"","docstring":"Yield all neighbouring nodes found from the given view.","docstring_summary":"Yield all neighbouring nodes found from the given view.","docstring_tokens":["Yield","all","neighbouring","nodes","found","from","the","given","view","."],"function":"def generate(self, view):\n \"\"\"Yield all neighbouring nodes found from the given view.\"\"\"\n pass","function_tokens":["def","generate","(","self",",","view",")",":","pass"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/server\/motions\/__init__.py#L16-L18"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/explore_lines.py","language":"python","identifier":"get_explore_lines","parameters":"(search_area_lines)","argument_list":"","return_statement":"","docstring":":param search_area_lines: Number of lines between, and including, the start and\n target positions.\n :returns: Number of lines to explore either side of the search area.","docstring_summary":":param search_area_lines: Number of lines between, and including, the start and\n target positions.\n :returns: Number of lines to explore either side of the search area.","docstring_tokens":[":","param","search_area_lines",":","Number","of","lines","between","and","including","the","start","and","target","positions",".",":","returns",":","Number","of","lines","to","explore","either","side","of","the","search","area","."],"function":"def get_explore_lines(search_area_lines):\n \"\"\"\n :param search_area_lines: Number of lines between, and including, the start and\n target positions.\n :returns: Number of lines to explore either side of the search area.\n \"\"\"\n # Get setting values from Vim variables\n explore_scale = float(vim.vars[\"pf_explore_scale\"])\n max_explore = int(vim.vars[\"pf_max_explore\"])\n\n if explore_scale < 0:\n # This filtering is disabled, explore the entire buffer\n return len(vim.current.buffer)\n\n # Number of lines to explore above and below the search area is scaled based\n # on the length of the area. This setting defaults to 0.5, if the search area\n # was e.g. 6 lines then 3 more lines would be explored on either side.\n explore_lines = search_area_lines * explore_scale\n if max_explore >= 0:\n # Limit to no more than max_explore lines\n return min(max_explore, explore_lines)\n else:\n # Do not limit\n return explore_lines","function_tokens":["def","get_explore_lines","(","search_area_lines",")",":","# Get setting values from Vim variables","explore_scale","=","float","(","vim",".","vars","[","\"pf_explore_scale\"","]",")","max_explore","=","int","(","vim",".","vars","[","\"pf_max_explore\"","]",")","if","explore_scale","<","0",":","# This filtering is disabled, explore the entire buffer","return","len","(","vim",".","current",".","buffer",")","# Number of lines to explore above and below the search area is scaled based","# on the length of the area. This setting defaults to 0.5, if the search area","# was e.g. 6 lines then 3 more lines would be explored on either side.","explore_lines","=","search_area_lines","*","explore_scale","if","max_explore",">=","0",":","# Limit to no more than max_explore lines","return","min","(","max_explore",",","explore_lines",")","else",":","# Do not limit","return","explore_lines"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/explore_lines.py#L4-L27"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/explore_lines.py","language":"python","identifier":"get_line_limits","parameters":"(start_view, target_view)","argument_list":"","return_statement":"return (\n max(1, min_line - explore_lines),\n min(len(vim.current.buffer), max_line + explore_lines),\n )","docstring":"Return the minimum and maximum line numbers to explore.\n\n :param start_view: The start position.\n :param target_view: The target position.\n :returns: Tuple of (min line, max line)","docstring_summary":"Return the minimum and maximum line numbers to explore.","docstring_tokens":["Return","the","minimum","and","maximum","line","numbers","to","explore","."],"function":"def get_line_limits(start_view, target_view):\n \"\"\"\n Return the minimum and maximum line numbers to explore.\n\n :param start_view: The start position.\n :param target_view: The target position.\n :returns: Tuple of (min line, max line)\n \"\"\"\n min_line = min(int(start_view.lnum), int(target_view.lnum))\n max_line = max(int(start_view.lnum), int(target_view.lnum))\n explore_lines = get_explore_lines(max_line - min_line)\n\n return (\n max(1, min_line - explore_lines),\n min(len(vim.current.buffer), max_line + explore_lines),\n )","function_tokens":["def","get_line_limits","(","start_view",",","target_view",")",":","min_line","=","min","(","int","(","start_view",".","lnum",")",",","int","(","target_view",".","lnum",")",")","max_line","=","max","(","int","(","start_view",".","lnum",")",",","int","(","target_view",".","lnum",")",")","explore_lines","=","get_explore_lines","(","max_line","-","min_line",")","return","(","max","(","1",",","min_line","-","explore_lines",")",",","min","(","len","(","vim",".","current",".","buffer",")",",","max_line","+","explore_lines",")",",",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/explore_lines.py#L30-L45"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/state_tracker.py","language":"python","identifier":"StateTracker.choose_action_using","parameters":"(self, function)","argument_list":"","return_statement":"return result","docstring":"Choose an action to take using the given function.\n\n Function will be called with the arguments (start state, current state,\n time of most recent update). It may return \"reset\" or \"set_target\" to\n call the corresponding method, or any other value to do nothing. The\n function's return value is passed through this method, so can be used\n to take further actions elsewhere.","docstring_summary":"Choose an action to take using the given function.","docstring_tokens":["Choose","an","action","to","take","using","the","given","function","."],"function":"def choose_action_using(self, function):\n \"\"\"\n Choose an action to take using the given function.\n\n Function will be called with the arguments (start state, current state,\n time of most recent update). It may return \"reset\" or \"set_target\" to\n call the corresponding method, or any other value to do nothing. The\n function's return value is passed through this method, so can be used\n to take further actions elsewhere.\n \"\"\"\n current_state = self._record_state()\n\n result = function(self.start_state, current_state, self.update_time)\n if result == \"reset\":\n self._reset(current_state)\n elif result == \"set_target\":\n self._set_target(current_state)\n\n return result","function_tokens":["def","choose_action_using","(","self",",","function",")",":","current_state","=","self",".","_record_state","(",")","result","=","function","(","self",".","start_state",",","current_state",",","self",".","update_time",")","if","result","==","\"reset\"",":","self",".","_reset","(","current_state",")","elif","result","==","\"set_target\"",":","self",".","_set_target","(","current_state",")","return","result"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/state_tracker.py#L45-L63"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/output.py","language":"python","identifier":"strtrans","parameters":"(string)","argument_list":"","return_statement":"return vim.eval(f\"strtrans('{escaped_string}')\")","docstring":"Convert special characters like '\u0004' to '^D'.","docstring_summary":"Convert special characters like '\u0004' to '^D'.","docstring_tokens":["Convert","special","characters","like","\u0004","to","^D","."],"function":"def strtrans(string):\n \"\"\"Convert special characters like '\u0004' to '^D'.\"\"\"\n escaped_string = string.replace(\"'\", \"\\\\'\").replace(\"\\\\\", \"\\\\\\\\\")\n return vim.eval(f\"strtrans('{escaped_string}')\")","function_tokens":["def","strtrans","(","string",")",":","escaped_string","=","string",".","replace","(","\"'\"",",","\"\\\\'\"",")",".","replace","(","\"\\\\\"",",","\"\\\\\\\\\"",")","return","vim",".","eval","(","f\"strtrans('{escaped_string}')\"",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/output.py#L10-L13"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/output.py","language":"python","identifier":"get_count","parameters":"(motion, count)","argument_list":"","return_statement":"return str(count) + motion_str","docstring":"Build a string like 'k', 'hh', '15w","docstring_summary":"Build a string like 'k', 'hh', '15w","docstring_tokens":["Build","a","string","like","k","hh","15w"],"function":"def get_count(motion, count):\n \"\"\"Build a string like 'k', 'hh', '15w'\"\"\"\n motion_str = strtrans(motion.motion + (motion.argument or \"\"))\n if count == 1:\n return motion_str\n\n elif count == 2 and len(motion_str) == 1:\n # It's easier to press a single-character motion twice\n # than to type a 2 before it\n return (motion_str) * 2\n\n return str(count) + motion_str","function_tokens":["def","get_count","(","motion",",","count",")",":","motion_str","=","strtrans","(","motion",".","motion","+","(","motion",".","argument","or","\"\"",")",")","if","count","==","1",":","return","motion_str","elif","count","==","2","and","len","(","motion_str",")","==","1",":","# It's easier to press a single-character motion twice","# than to type a 2 before it","return","(","motion_str",")","*","2","return","str","(","count",")","+","motion_str"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/output.py#L16-L27"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/output.py","language":"python","identifier":"compact_motions","parameters":"(motions)","argument_list":"","return_statement":"return \" \".join(\n [\n get_count(motion, len(list(group)))\n for motion, group in itertools.groupby(motions)\n ]\n )","docstring":"Return the given motion sequence in single-line form.\n\n e.g. 2* 5j $","docstring_summary":"Return the given motion sequence in single-line form.","docstring_tokens":["Return","the","given","motion","sequence","in","single","-","line","form","."],"function":"def compact_motions(motions):\n \"\"\"\n Return the given motion sequence in single-line form.\n\n e.g. 2* 5j $\n \"\"\"\n return \" \".join(\n [\n get_count(motion, len(list(group)))\n for motion, group in itertools.groupby(motions)\n ]\n )","function_tokens":["def","compact_motions","(","motions",")",":","return","\" \"",".","join","(","[","get_count","(","motion",",","len","(","list","(","group",")",")",")","for","motion",",","group","in","itertools",".","groupby","(","motions",")","]",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/output.py#L30-L41"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/output.py","language":"python","identifier":"explained_motions","parameters":"(motions)","argument_list":"","return_statement":"","docstring":"Yield each motion in the form \"motion <padding> help\"\n\n e.g. ['5j Down 5 lines', '$ To the end of the line']","docstring_summary":"Yield each motion in the form \"motion <padding> help\"","docstring_tokens":["Yield","each","motion","in","the","form","motion","<padding",">","help"],"function":"def explained_motions(motions):\n \"\"\"\n Yield each motion in the form \"motion <padding> help\"\n\n e.g. ['5j Down 5 lines', '$ To the end of the line']\n \"\"\"\n for motion, group in itertools.groupby(motions):\n repetitions = len(list(group))\n yield (\n get_count(motion, repetitions) + \" \" + get_description(motion, repetitions)\n )","function_tokens":["def","explained_motions","(","motions",")",":","for","motion",",","group","in","itertools",".","groupby","(","motions",")",":","repetitions","=","len","(","list","(","group",")",")","yield","(","get_count","(","motion",",","repetitions",")","+","\" \"","+","get_description","(","motion",",","repetitions",")",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/output.py#L52-L62"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/client.py","language":"python","identifier":"Client.open","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Launch and connect to the server Vim.","docstring_summary":"Launch and connect to the server Vim.","docstring_tokens":["Launch","and","connect","to","the","server","Vim","."],"function":"def open(self):\n \"\"\"Launch and connect to the server Vim.\"\"\"\n # Create a file used to communicate with the server\n self.file_path = os.path.join(\n tempfile.gettempdir(), \"pathfinder_vim_\" + vim.eval(\"getpid()\")\n )\n\n self.server_process = subprocess.Popen(\n self._build_server_cmd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE\n )\n\n self.server_connection = None\n self.to_send = None","function_tokens":["def","open","(","self",")",":","# Create a file used to communicate with the server","self",".","file_path","=","os",".","path",".","join","(","tempfile",".","gettempdir","(",")",",","\"pathfinder_vim_\"","+","vim",".","eval","(","\"getpid()\"",")",")","self",".","server_process","=","subprocess",".","Popen","(","self",".","_build_server_cmd","(",")",",","stdout","=","subprocess",".","PIPE",",","stderr","=","subprocess",".","PIPE",")","self",".","server_connection","=","None","self",".","to_send","=","None"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/client.py#L26-L38"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/client.py","language":"python","identifier":"Client._build_server_cmd","parameters":"(self)","argument_list":"","return_statement":"return options","docstring":"Build the command used to launch the server Vim.","docstring_summary":"Build the command used to launch the server Vim.","docstring_tokens":["Build","the","command","used","to","launch","the","server","Vim","."],"function":"def _build_server_cmd(self):\n \"\"\"Build the command used to launch the server Vim.\"\"\"\n progpath = vim.eval(\"v:progpath\")\n\n options = [\n progpath,\n \"--clean\",\n \"--cmd\",\n f\"let g:pf_server_communication_file='{self.file_path}'\",\n \"-u\",\n os.path.normpath(\n # serverrc.vim in the root of this repository, instead of the user's\n # regular .vimrc or init.vim\n os.path.join(os.path.dirname(__file__), \"..\", \"..\", \"serverrc.vim\")\n ),\n ]\n\n if progpath.endswith(\"nvim\"):\n python3_host_prog = vim.eval(\"g:python3_host_prog\")\n options += [\n \"--headless\",\n \"--cmd\",\n f\"let g:python3_host_prog='{python3_host_prog}'\",\n ]\n else:\n options += [\"-v\", \"--not-a-term\"]\n\n return options","function_tokens":["def","_build_server_cmd","(","self",")",":","progpath","=","vim",".","eval","(","\"v:progpath\"",")","options","=","[","progpath",",","\"--clean\"",",","\"--cmd\"",",","f\"let g:pf_server_communication_file='{self.file_path}'\"",",","\"-u\"",",","os",".","path",".","normpath","(","# serverrc.vim in the root of this repository, instead of the user's","# regular .vimrc or init.vim","os",".","path",".","join","(","os",".","path",".","dirname","(","__file__",")",",","\"..\"",",","\"..\"",",","\"serverrc.vim\"",")",")",",","]","if","progpath",".","endswith","(","\"nvim\"",")",":","python3_host_prog","=","vim",".","eval","(","\"g:python3_host_prog\"",")","options","+=","[","\"--headless\"",",","\"--cmd\"",",","f\"let g:python3_host_prog='{python3_host_prog}'\"",",","]","else",":","options","+=","[","\"-v\"",",","\"--not-a-term\"","]","return","options"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/client.py#L40-L67"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/client.py","language":"python","identifier":"Client.close","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Shut down the server Vim.","docstring_summary":"Shut down the server Vim.","docstring_tokens":["Shut","down","the","server","Vim","."],"function":"def close(self):\n \"\"\"Shut down the server Vim.\"\"\"\n if self.server_connection is not None:\n # Server will shut down Vim gracefully when we disconnect\n self.server_connection.close()\n elif self.server_process is not None:\n # Not connected yet, terminate the process instead\n self.server_process.terminate()","function_tokens":["def","close","(","self",")",":","if","self",".","server_connection","is","not","None",":","# Server will shut down Vim gracefully when we disconnect","self",".","server_connection",".","close","(",")","elif","self",".","server_process","is","not","None",":","# Not connected yet, terminate the process instead","self",".","server_process",".","terminate","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/client.py#L69-L76"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/client.py","language":"python","identifier":"Client.connect","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Attempt to connect to the server.\n\n :returns: whether a connection is ready.","docstring_summary":"Attempt to connect to the server.","docstring_tokens":["Attempt","to","connect","to","the","server","."],"function":"def connect(self):\n \"\"\"\n Attempt to connect to the server.\n\n :returns: whether a connection is ready.\n \"\"\"\n if self.server_connection is not None:\n return True\n\n if self.server_process is None:\n # Server process has exited but we already raised an exception\n return False\n\n return_code = self.server_process.poll()\n if return_code is not None:\n # Server process has exited\n stdout, stderr = self.server_process.communicate()\n self.server_process = None\n raise Exception(\n f\"Pathfinding server process exited with return code {return_code}:\\n\"\n + stderr.decode()\n )\n\n try:\n # Attempt to connect\n self.server_connection = connection.Client(self.file_path)\n return True\n except FileNotFoundError:\n return False","function_tokens":["def","connect","(","self",")",":","if","self",".","server_connection","is","not","None",":","return","True","if","self",".","server_process","is","None",":","# Server process has exited but we already raised an exception","return","False","return_code","=","self",".","server_process",".","poll","(",")","if","return_code","is","not","None",":","# Server process has exited","stdout",",","stderr","=","self",".","server_process",".","communicate","(",")","self",".","server_process","=","None","raise","Exception","(","f\"Pathfinding server process exited with return code {return_code}:\\n\"","+","stderr",".","decode","(",")",")","try",":","# Attempt to connect","self",".","server_connection","=","connection",".","Client","(","self",".","file_path",")","return","True","except","FileNotFoundError",":","return","False"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/client.py#L93-L121"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/client.py","language":"python","identifier":"Client.handle_response","parameters":"(self, response_type, data)","argument_list":"","return_statement":"","docstring":"Process a response recieved from the server.\n\n This will be one of:\n - ``RESULT`` - A pathfinding result. Call the first queued callback.\n - ``ERROR`` - An unexpected exception was caught and the server has exited.\n Relay the traceback to the user for debugging.","docstring_summary":"Process a response recieved from the server.","docstring_tokens":["Process","a","response","recieved","from","the","server","."],"function":"def handle_response(self, response_type, data):\n \"\"\"\n Process a response recieved from the server.\n\n This will be one of:\n - ``RESULT`` - A pathfinding result. Call the first queued callback.\n - ``ERROR`` - An unexpected exception was caught and the server has exited.\n Relay the traceback to the user for debugging.\n \"\"\"\n if response_type == \"RESULT\":\n # Get the first callback function and pass the result to it\n self.callback(data)\n del self.callback\n elif response_type == \"ERROR\":\n raise Exception(\"Pathfinding server encountered an exception:\\n\" + data)\n else:\n raise Exception(\"Received an unexpected response \" + response_type)","function_tokens":["def","handle_response","(","self",",","response_type",",","data",")",":","if","response_type","==","\"RESULT\"",":","# Get the first callback function and pass the result to it","self",".","callback","(","data",")","del","self",".","callback","elif","response_type","==","\"ERROR\"",":","raise","Exception","(","\"Pathfinding server encountered an exception:\\n\"","+","data",")","else",":","raise","Exception","(","\"Received an unexpected response \"","+","response_type",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/client.py#L123-L139"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/client.py","language":"python","identifier":"Client.pathfind","parameters":"(self, buffer_contents, start_view, target_view, callback)","argument_list":"","return_statement":"","docstring":"Request a pathfinding result from the server.\n\n :param buffer_contents: List of lines we are pathfinding inside.\n :param start_view: The start position, in the current window.\n :param target_view: The target position, in the current window.\n :param callback: Function to be called once a path is found. Recieves a list\n of motions as a parameter.","docstring_summary":"Request a pathfinding result from the server.","docstring_tokens":["Request","a","pathfinding","result","from","the","server","."],"function":"def pathfind(self, buffer_contents, start_view, target_view, callback):\n \"\"\"\n Request a pathfinding result from the server.\n\n :param buffer_contents: List of lines we are pathfinding inside.\n :param start_view: The start position, in the current window.\n :param target_view: The target position, in the current window.\n :param callback: Function to be called once a path is found. Recieves a list\n of motions as a parameter.\n \"\"\"\n self.callback = callback\n\n min_line, max_line = get_line_limits(start_view, target_view)\n self.to_send = {\n \"start\": start_view,\n \"target\": target_view,\n \"min_line\": min_line,\n \"max_line\": max_line,\n \"size\": (\n # WindowTextWidth() - see plugin\/dimensions.vim\n vim.eval(\"WindowTextWidth()\"),\n vim.eval(\"winheight(0)\"),\n ),\n \"buffer\": buffer_contents,\n \"wrap\": vim.current.window.options[\"wrap\"],\n \"scrolloff\": vim.options[\"scrolloff\"],\n \"sidescrolloff\": vim.options[\"sidescrolloff\"],\n }","function_tokens":["def","pathfind","(","self",",","buffer_contents",",","start_view",",","target_view",",","callback",")",":","self",".","callback","=","callback","min_line",",","max_line","=","get_line_limits","(","start_view",",","target_view",")","self",".","to_send","=","{","\"start\"",":","start_view",",","\"target\"",":","target_view",",","\"min_line\"",":","min_line",",","\"max_line\"",":","max_line",",","\"size\"",":","(","# WindowTextWidth() - see plugin\/dimensions.vim","vim",".","eval","(","\"WindowTextWidth()\"",")",",","vim",".","eval","(","\"winheight(0)\"",")",",",")",",","\"buffer\"",":","buffer_contents",",","\"wrap\"",":","vim",".","current",".","window",".","options","[","\"wrap\"","]",",","\"scrolloff\"",":","vim",".","options","[","\"scrolloff\"","]",",","\"sidescrolloff\"",":","vim",".","options","[","\"sidescrolloff\"","]",",","}"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/client.py#L141-L168"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/popup.py","language":"python","identifier":"_neovim_popup","parameters":"(text, line_offset)","argument_list":"","return_statement":"","docstring":"Create a popup using Neovim 0.4+ floating windows.","docstring_summary":"Create a popup using Neovim 0.4+ floating windows.","docstring_tokens":["Create","a","popup","using","Neovim","0",".","4","+","floating","windows","."],"function":"def _neovim_popup(text, line_offset):\n \"\"\"Create a popup using Neovim 0.4+ floating windows.\"\"\"\n # Insert text into a scratch buffer\n buffer = vim.api.create_buf(False, True)\n vim.api.buf_set_lines(buffer, 0, -1, True, [f\" {text} \"])\n\n # Create a window containing the buffer\n window = vim.api.open_win(\n buffer,\n 0,\n {\n \"relative\": \"cursor\",\n \"row\": int(line_offset),\n \"col\": 0,\n \"style\": \"minimal\",\n \"focusable\": 0,\n \"height\": 1,\n \"width\": len(text) + 2,\n },\n )\n # Set the highlight of the window to match the cursor\n vim.api.win_set_option(window, \"winhl\", \"Normal:PathfinderPopup\")\n\n # Create a timer to close the window\n popup_time = int(vim.vars[\"pf_popup_time\"])\n vim.eval(f\"timer_start({popup_time}, {{-> nvim_win_close({window.handle}, 1)}})\")","function_tokens":["def","_neovim_popup","(","text",",","line_offset",")",":","# Insert text into a scratch buffer","buffer","=","vim",".","api",".","create_buf","(","False",",","True",")","vim",".","api",".","buf_set_lines","(","buffer",",","0",",","-","1",",","True",",","[","f\" {text} \"","]",")","# Create a window containing the buffer","window","=","vim",".","api",".","open_win","(","buffer",",","0",",","{","\"relative\"",":","\"cursor\"",",","\"row\"",":","int","(","line_offset",")",",","\"col\"",":","0",",","\"style\"",":","\"minimal\"",",","\"focusable\"",":","0",",","\"height\"",":","1",",","\"width\"",":","len","(","text",")","+","2",",","}",",",")","# Set the highlight of the window to match the cursor","vim",".","api",".","win_set_option","(","window",",","\"winhl\"",",","\"Normal:PathfinderPopup\"",")","# Create a timer to close the window","popup_time","=","int","(","vim",".","vars","[","\"pf_popup_time\"","]",")","vim",".","eval","(","f\"timer_start({popup_time}, {{-> nvim_win_close({window.handle}, 1)}})\"",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/popup.py#L6-L31"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/popup.py","language":"python","identifier":"_vim_popup","parameters":"(text, line_offset)","argument_list":"","return_statement":"","docstring":"Create a popup using Vim +popupwin.","docstring_summary":"Create a popup using Vim +popupwin.","docstring_tokens":["Create","a","popup","using","Vim","+","popupwin","."],"function":"def _vim_popup(text, line_offset):\n \"\"\"Create a popup using Vim +popupwin.\"\"\"\n vim.Function(\"popup_create\")(\n text,\n {\n \"line\": f\"cursor{line_offset}\",\n \"col\": \"cursor\",\n \"wrap\": False,\n \"padding\": (0, 1, 0, 1),\n \"highlight\": \"PathfinderPopup\",\n \"time\": int(vim.vars[\"pf_popup_time\"]),\n \"zindex\": 1000,\n },\n )","function_tokens":["def","_vim_popup","(","text",",","line_offset",")",":","vim",".","Function","(","\"popup_create\"",")","(","text",",","{","\"line\"",":","f\"cursor{line_offset}\"",",","\"col\"",":","\"cursor\"",",","\"wrap\"",":","False",",","\"padding\"",":","(","0",",","1",",","0",",","1",")",",","\"highlight\"",":","\"PathfinderPopup\"",",","\"time\"",":","int","(","vim",".","vars","[","\"pf_popup_time\"","]",")",",","\"zindex\"",":","1000",",","}",",",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/popup.py#L34-L47"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/plugin.py","language":"python","identifier":"Plugin._run","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Start calculating a path in the background.","docstring_summary":"Start calculating a path in the background.","docstring_tokens":["Start","calculating","a","path","in","the","background","."],"function":"def _run(self):\n \"\"\"Start calculating a path in the background.\"\"\"\n self.client.pathfind(\n self.state_tracker.start_state.lines,\n self.state_tracker.start_state.view,\n self.state_tracker.target_state.view,\n self.popup,\n )","function_tokens":["def","_run","(","self",")",":","self",".","client",".","pathfind","(","self",".","state_tracker",".","start_state",".","lines",",","self",".","state_tracker",".","start_state",".","view",",","self",".","state_tracker",".","target_state",".","view",",","self",".","popup",",",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/plugin.py#L19-L26"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/plugin.py","language":"python","identifier":"Plugin.autorun","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Called on a timer several times per second.","docstring_summary":"Called on a timer several times per second.","docstring_tokens":["Called","on","a","timer","several","times","per","second","."],"function":"def autorun(self):\n \"\"\"Called on a timer several times per second.\"\"\"\n if self.state_tracker.choose_action_using(choose_action) == \"pathfind\":\n if not cursor_in_same_position(\n self.state_tracker.start_state.view,\n self.state_tracker.target_state.view,\n ):\n self._run()\n self.state_tracker.reset()","function_tokens":["def","autorun","(","self",")",":","if","self",".","state_tracker",".","choose_action_using","(","choose_action",")","==","\"pathfind\"",":","if","not","cursor_in_same_position","(","self",".","state_tracker",".","start_state",".","view",",","self",".","state_tracker",".","target_state",".","view",",",")",":","self",".","_run","(",")","self",".","state_tracker",".","reset","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/plugin.py#L32-L40"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/plugin.py","language":"python","identifier":"Plugin.command_begin","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Called for the :PathfinderBegin command.","docstring_summary":"Called for the :PathfinderBegin command.","docstring_tokens":["Called","for","the",":","PathfinderBegin","command","."],"function":"def command_begin(self):\n \"\"\"Called for the :PathfinderBegin command.\"\"\"\n self.state_tracker.reset()","function_tokens":["def","command_begin","(","self",")",":","self",".","state_tracker",".","reset","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/plugin.py#L42-L44"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/plugin.py","language":"python","identifier":"Plugin.command_run","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Called for the :PathfinderRun command.","docstring_summary":"Called for the :PathfinderRun command.","docstring_tokens":["Called","for","the",":","PathfinderRun","command","."],"function":"def command_run(self):\n \"\"\"Called for the :PathfinderRun command.\"\"\"\n self.state_tracker.set_target()\n\n if cursor_in_same_position(\n self.state_tracker.start_state.view,\n self.state_tracker.target_state.view,\n ):\n print(\"You must move the cursor to a new location first!\")\n else:\n self._run()","function_tokens":["def","command_run","(","self",")",":","self",".","state_tracker",".","set_target","(",")","if","cursor_in_same_position","(","self",".","state_tracker",".","start_state",".","view",",","self",".","state_tracker",".","target_state",".","view",",",")",":","print","(","\"You must move the cursor to a new location first!\"",")","else",":","self",".","_run","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/plugin.py#L46-L56"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/plugin.py","language":"python","identifier":"Plugin.command_explain","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Called for the :PathfinderExplain command.","docstring_summary":"Called for the :PathfinderExplain command.","docstring_tokens":["Called","for","the",":","PathfinderExplain","command","."],"function":"def command_explain(self):\n \"\"\"Called for the :PathfinderExplain command.\"\"\"\n if self.last_output is None:\n print(\"No suggestion to explain.\")\n else:\n # explained_motions yields each line\n # sep tells print to put \\n between them rather than space\n print(*output.explained_motions(self.last_output), sep=\"\\n\")","function_tokens":["def","command_explain","(","self",")",":","if","self",".","last_output","is","None",":","print","(","\"No suggestion to explain.\"",")","else",":","# explained_motions yields each line","# sep tells print to put \\n between them rather than space","print","(","*","output",".","explained_motions","(","self",".","last_output",")",",","sep","=","\"\\n\"",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/plugin.py#L58-L65"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/plugin.py","language":"python","identifier":"Plugin.stop","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Called when Vim is about to shut down.","docstring_summary":"Called when Vim is about to shut down.","docstring_tokens":["Called","when","Vim","is","about","to","shut","down","."],"function":"def stop(self):\n \"\"\"Called when Vim is about to shut down.\"\"\"\n self.client.close()","function_tokens":["def","stop","(","self",")",":","self",".","client",".","close","(",")"],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/plugin.py#L67-L69"}
{"nwo":"danth\/pathfinder.vim","sha":"4f67053cbea56a45020d004b6bd059e38934a21a","path":"pathfinder\/client\/autorun.py","language":"python","identifier":"choose_action","parameters":"(start_state, current_state, update_time)","argument_list":"","return_statement":"","docstring":"Select an action to take automatically.\n\n This is intended for use with StateTracker.choose_action_using().\n\n Returns one of:\n \"reset\" - Set start and target to the current state\n \"set_target\" - Set target to the current state\n \"pathfind\" - Start pathfinding, using the target from last time it was set\n None - Do nothing","docstring_summary":"Select an action to take automatically.","docstring_tokens":["Select","an","action","to","take","automatically","."],"function":"def choose_action(start_state, current_state, update_time):\n \"\"\"\n Select an action to take automatically.\n\n This is intended for use with StateTracker.choose_action_using().\n\n Returns one of:\n \"reset\" - Set start and target to the current state\n \"set_target\" - Set target to the current state\n \"pathfind\" - Start pathfinding, using the target from last time it was set\n None - Do nothing\n \"\"\"\n if (\n start_state.window != current_state.window\n or start_state.buffer != current_state.buffer\n ):\n # Reset to ensure the start or target view isn't set to a location\n # which is now impossible to access\n return \"reset\"\n\n delay = vim.vars[\"pf_autorun_delay\"]\n if delay > 0: # If delay <= 0, then the user disabled autorun\n if start_state.mode not in {\"n\", \"v\", \"V\", \"\u0016\"}:\n # Motions are not used in this mode, so pathfinding is useless\n return \"reset\"\n\n if (\n time.time() >= update_time + delay\n or start_state.mode != current_state.mode\n or start_state.lines != current_state.lines\n ):\n return \"pathfind\"\n else:\n return \"set_target\"","function_tokens":["def","choose_action","(","start_state",",","current_state",",","update_time",")",":","if","(","start_state",".","window","!=","current_state",".","window","or","start_state",".","buffer","!=","current_state",".","buffer",")",":","# Reset to ensure the start or target view isn't set to a location","# which is now impossible to access","return","\"reset\"","delay","=","vim",".","vars","[","\"pf_autorun_delay\"","]","if","delay",">","0",":","# If delay <= 0, then the user disabled autorun","if","start_state",".","mode","not","in","{","\"n\"",",","\"v\"",",","\"V\"",",","\"\u0016\"","}",":","# Motions are not used in this mode, so pathfinding is useless","return","\"reset\"","if","(","time",".","time","(",")",">=","update_time","+","delay","or","start_state",".","mode","!=","current_state",".","mode","or","start_state",".","lines","!=","current_state",".","lines",")",":","return","\"pathfind\"","else",":","return","\"set_target\""],"url":"https:\/\/github.com\/danth\/pathfinder.vim\/blob\/4f67053cbea56a45020d004b6bd059e38934a21a\/pathfinder\/client\/autorun.py#L6-L39"}