Skip to content

Commit 79d14e4

Browse files
committed
feat(robotcode): Automatically create .gitignore in .robotcode_cache
You no longer need to manually add `.robotcode_cache` to your `.gitignore` file, as it is now automatically ignored. If you already have an existing `.robotcode_cache` folder, simply run the command `RobotCode: Clear Cache and Restart Language Servers`. For IntelliJ-based platforms, you can find this command in the **RobotCode** menu under the **Tools** main menu. Closes #384
1 parent df43bbe commit 79d14e4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/robot/src/robotcode/robot/diagnostics/data_cache.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,20 @@ def read_cache_data(
2727
def save_cache_data(self, section: CacheSection, entry_name: str, data: Any) -> None: ...
2828

2929

30-
class JsonDataCache(DataCache):
30+
class FileCacheDataBase(DataCache, ABC):
3131
def __init__(self, cache_dir: Path) -> None:
3232
self.cache_dir = cache_dir
3333

34+
if not Path.exists(self.cache_dir):
35+
Path.mkdir(self.cache_dir, parents=True)
36+
Path(self.cache_dir / ".gitignore").write_text(
37+
"# Created by robotcode\n*\n",
38+
"utf-8",
39+
)
40+
41+
42+
class JsonDataCache(FileCacheDataBase):
43+
3444
def build_cache_data_filename(self, section: CacheSection, entry_name: str) -> Path:
3545
return self.cache_dir / section.value / (entry_name + ".json")
3646

@@ -51,10 +61,7 @@ def save_cache_data(self, section: CacheSection, entry_name: str, data: Any) ->
5161
cached_file.write_text(as_json(data), "utf-8")
5262

5363

54-
class PickleDataCache(DataCache):
55-
def __init__(self, cache_dir: Path) -> None:
56-
self.cache_dir = cache_dir
57-
64+
class PickleDataCache(FileCacheDataBase):
5865
def build_cache_data_filename(self, section: CacheSection, entry_name: str) -> Path:
5966
return self.cache_dir / section.value / (entry_name + ".pkl")
6067

packages/robot/src/robotcode/robot/diagnostics/imports_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ def get_namespace_for_resource(self, document: TextDocument) -> "Namespace":
610610

611611
def clear_cache(self) -> None:
612612
if self.cache_path.exists():
613-
shutil.rmtree(self.cache_path)
613+
shutil.rmtree(self.cache_path, ignore_errors=True)
614+
614615
self._logger.debug(lambda: f"Cleared cache {self.cache_path}")
615616

616617
@_logger.call

0 commit comments

Comments
 (0)