import base64
import os
from abc import ABC, abstractmethod
from typing import List

from .jsonrpc import JSONRPC2Server

class FileException(Exception):
    pass

class Entry:
    """Generic representation of a directory entry."""
    def __init__(self, name, is_dir, size):
        self.name = name
        self.is_dir = is_dir
        self.size = size

class FileSystem(ABC):
    @abstractmethod
    def open(path: str) -> str:
        pass

    @abstractmethod
    def listdir(path: str) -> List[Entry]:
        pass

    def walk(self, top: str):
        dir = self.listdir(top)
        files, dirs = [], []
        for e in dir:
            if e.is_dir:
                dirs.append(os.path.join(top, e.name))
            else:
                files.append(os.path.join(top, e.name))
        yield top, dirs, files
        for d in dirs:
            yield from self.walk(d)

class LocalFileSystem(FileSystem):
    def open(self, path):
        return open(path).read()

    def listdir(self, path):
        entries = []
        names = os.listdir(path)
        for n in names:
            p = os.path.join(path, n)
            entries.append(Entry(n, os.path.isdir(p), os.path.getsize(p)))
        return entries

class RemoteFileSystem(FileSystem):
    def __init__(self, server: JSONRPC2Server):
        self.server = server

    def open(self, path):
        resp = self.server.send_request("fs/readFile", path)
        if resp.get("error") is not None:
            raise FileException(resp["error"])
        return base64.b64decode(resp["result"]).decode("utf-8")

    def listdir(self, path):
        resp = self.server.send_request("fs/readDir", path)
        if resp.get("error") is not None:
            raise FileException(resp["error"])
        entries = []
        for e in resp["result"]:
            entries.append(Entry(e["name"], e["dir"], e["size"]))
        return entries


@@ -53,16 +53,48 @@
 tmethod%0A
+from functools import lru_cache%0A
 from typ
@@ -1358,16 +1358,44 @@
 server%0A%0A
+    @lru_cache(maxsize=128)%0A
     def 
@@ -1627,16 +1627,44 @@
 tf-8%22)%0A%0A
+    @lru_cache(maxsize=128)%0A
     def 

Add caching for remote fs calls