def _add_session(self, view: View, defx: Defx, context: Context) -> None: path = context.args[0] if context.args else defx._cwd if path[-1] == '/': # Remove the last slash path = path[:-1] opened_candidates = [] if context.args else list( defx._opened_candidates) opened_candidates.sort() session: Session if path in view._sessions: old_session = view._sessions[path] session = Session(name=old_session.name, path=old_session.path, opened_candidates=opened_candidates) else: name = Path(path).name session = Session(name=name, path=path, opened_candidates=opened_candidates) view.print_msg(f'session "{name}" is created') view._sessions[session.path] = session self._save_session(view, defx, context)
def _load_session(self, view: View, defx: Defx, context: Context) -> None: session_file = Path(context.session_file) if not context.session_file or not session_file.exists(): return loaded_session = json.loads(session_file.read_text()) if 'sessions' not in loaded_session: return view._sessions = {} for path, session in loaded_session['sessions'].items(): view._sessions[path] = Session(**session) view._vim.current.buffer.vars['defx#_sessions'] = [ x._asdict() for x in view._sessions.values() ]