Skip to content

Commit 5087c91

Browse files
committed
feat: new setting robotcode.analysis.cache.ignoredLibraries to define which libraries should never be cached
1 parent 228ae4e commit 5087c91

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,17 @@
486486
"default": "workspaceStorage",
487487
"scope": "resource"
488488
},
489+
"robotcode.analysis.cache.ignoredLibraries": {
490+
"type": "array",
491+
"default": [],
492+
"items": {
493+
"type": "string"
494+
},
495+
"markdownDescription": [
496+
"Specifies the library names that should not be cached. This is useful if you have a dynamic or hybrid library that has different keywords depending on the arguments. You can specify a glob pattern that matches the library name or the source file. \n\nExamples:\n- `**/mylibfolder/mylib.py`\n- `MyLib`\n- `mylibfolder.mylib.subpackage` \n\nFor robot framework internal libraries, you have to specify the full module name like `robot.libraries.Remote`.\n\nIf you change this setting, you may need to run the command `Robot Code: Clear Cache and Restart Language Servers`."
497+
],
498+
"scope": "resource"
499+
},
489500
"robotcode.run.openOutputAfterRun": {
490501
"type": "string",
491502
"enum": [

robotcode/language_server/robotframework/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class WorkspaceConfig(ConfigBase):
8282
@dataclass
8383
class Cache(ConfigBase):
8484
save_location: CacheSaveLocation = CacheSaveLocation.WORKSPACE_STORAGE
85+
ignored_libraries: List[str] = field(default_factory=list)
8586

8687

8788
@config_section("robotcode.analysis")

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from ....utils.async_cache import AsyncSimpleLRUCache
3232
from ....utils.async_tools import Lock, async_tasking_event, create_sub_task, threaded
3333
from ....utils.dataclasses import as_json, from_json
34-
from ....utils.glob_path import iter_files
34+
from ....utils.glob_path import Pattern, iter_files
3535
from ....utils.logging import LoggingDescriptor
3636
from ....utils.path import path_is_relative_to
3737
from ....utils.uri import Uri
@@ -59,7 +59,6 @@
5959
KeywordDoc,
6060
KeywordStore,
6161
LibraryDoc,
62-
LibraryType,
6362
ModuleSpec,
6463
VariablesDoc,
6564
complete_library_import,
@@ -521,6 +520,8 @@ def __init__(self, parent_protocol: RobotLanguageServerProtocol, folder: Uri, co
521520
/ "libdoc"
522521
)
523522
self.config = config
523+
524+
self.ignored_libraries_patters = [Pattern(s) for s in config.analysis.cache.ignored_libraries]
524525
self._libaries_lock = Lock()
525526
self._libaries: OrderedDict[_LibrariesEntryKey, _LibrariesEntry] = OrderedDict()
526527
self._resources_lock = Lock()
@@ -788,7 +789,18 @@ async def get_library_meta(
788789
module_spec.submodule_search_locations,
789790
False,
790791
)
792+
791793
if result is not None:
794+
if any(
795+
(p.matches(result.name) if result.name is not None else False)
796+
or (p.matches(result.origin) if result.origin is not None else False)
797+
for p in self.ignored_libraries_patters
798+
):
799+
self._logger.critical(
800+
lambda: f"Ignore library {result.name or ''} {result.origin or ''} for caching." # type: ignore
801+
)
802+
return None, import_name
803+
792804
if result.origin is not None:
793805
result.mtimes = {result.origin: Path(result.origin).resolve().stat().st_mtime_ns}
794806

@@ -954,7 +966,7 @@ async def _get_libdoc(name: str, args: Tuple[Any, ...], working_dir: str, base_d
954966
lambda: f"stdout captured at loading library {name}{repr(args)}:\n{result.stdout}"
955967
)
956968
try:
957-
if meta is not None and result.library_type in [LibraryType.CLASS, LibraryType.MODULE]:
969+
if meta is not None:
958970
meta_file = Path(self.lib_doc_cache_path, meta.filepath_base.with_suffix(".meta.json"))
959971
meta_file.parent.mkdir(parents=True, exist_ok=True)
960972
meta_file.write_text(as_json(meta), "utf-8")

tests/robotcode/language_server/robotframework/parts/data/.vscode/settings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
},
1515
"robotcode.languageServer.args": [
16-
"--debugpy",
16+
//"--debugpy",
1717
// "--log",
1818
// "--log-all",
1919
// "--log-level",
@@ -32,5 +32,10 @@
3232
//"python.analysis.diagnosticMode": "workspace"
3333
//"robotcode.robot.paths": ["./tests", "./tests1"]
3434
"robotcode.analysis.diagnosticMode": "workspace",
35-
"robotcode.analysis.progressMode": "detailed"
35+
"robotcode.analysis.progressMode": "detailed",
36+
"robotcode.analysis.cache.saveLocation": "workspaceFolder",
37+
"robotcode.analysis.cache.ignoredLibraries": [
38+
//"robot.libraries.Remote",
39+
"**/lib/alibrary.py"
40+
]
3641
}

tests/robotcode/language_server/robotframework/parts/data/tests/remotetest.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*** Settings ***
2-
# Library Remote uri=http://127.0.0.1:8270
2+
Library Remote uri=http://127.0.0.1:8270
33

44

55
*** Test Cases ***

0 commit comments

Comments
 (0)