Skip to content

Commit bb55ff4

Browse files
committed
feat(langserver): introduce new setting robotcode.analysis.cache.ignoreArgumentsForLibrary
This is usefull if you have library that get's variables from a python file that contains complex data like big dictionaries or complex objects that robotcode can't handle.
1 parent b846504 commit bb55ff4

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,13 +666,22 @@
666666
"markdownDescription": "Specifies the variable files that should not be cached. This is useful if you have a dynamic or hybrid variable files that has different variables depending on the arguments. You can specify a glob pattern that matches the variable module name or the source file. \n\nExamples:\n- `**/variables/myvars.py`\n- `MyVariables`\n- `myvars.subpackage.subpackage` \n\nIf you change this setting, you may need to run the command `RobotCode: Clear Cache and Restart Language Servers`.",
667667
"scope": "resource"
668668
},
669+
"robotcode.analysis.cache.ignoreArgumentsForLibrary": {
670+
"type": "array",
671+
"default": [],
672+
"items": {
673+
"type": "string"
674+
},
675+
"markdownDescription": "Specifies a list of libraries for which arguments will be ignored during analysis. This is usefull if you have library that gets variables from a python file as arguments that contains complex data like big dictionaries or complex objects that **RobotCode** can't handle. You can specify a glob pattern that matches the library name or the source file. \n\nExamples:\n- `**/mylibfolder/mylib.py`\n- `MyLib`\n- `mylib.subpackage.subpackage` \n\nIf you change this setting, you may need to run the command `RobotCode: Clear Cache and Restart Language Servers`.\n\n _Ensure your library functions correctly without arguments e.g. by defining default values for all arguments._",
676+
"scope": "resource"
677+
},
669678
"robotcode.analysis.robot.globalLibrarySearchOrder": {
670679
"type": "array",
671680
"default": [],
672681
"items": {
673682
"type": "string"
674683
},
675-
"markdownDescription": "Specifies a global [search order](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-explicit-priority-between-libraries-and-resources) for libraries and resources. This is handy when you have libraries containing keywords with the same name. RobotCode is unable to analyze the library search order in a file specified with [`Set Library Search Order`](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order), so you can define a global order here. Just make sure to call the `Set Library Search Order` keyword somewhere in your robot file or internally in your library.",
684+
"markdownDescription": "Specifies a global [search order](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-explicit-priority-between-libraries-and-resources) for libraries and resources. This is usefull when you have libraries containing keywords with the same name. **RobotCode** is unable to analyze the library search order in a file specified with [`Set Library Search Order`](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order), so you can define a global order here. Just make sure to call the `Set Library Search Order` keyword somewhere in your robot file or internally in your library.",
676685
"scope": "resource"
677686
},
678687
"robotcode.analysis.findUnusedReferences": {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ def create_imports_manager(self, root_uri: Uri) -> ImportsManager:
505505
environment,
506506
cache_config.ignored_libraries,
507507
cache_config.ignored_variables,
508+
cache_config.ignore_arguments_for_library,
508509
analysis_config.global_library_search_order,
509510
cache_base_path,
510511
)

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ def __init__(
496496
environment: Optional[Dict[str, str]],
497497
ignored_libraries: List[str],
498498
ignored_variables: List[str],
499+
ignore_arguments_for_library: List[str],
499500
global_library_search_order: List[str],
500501
cache_base_path: Optional[Path],
501502
) -> None:
@@ -538,6 +539,7 @@ def __init__(
538539

539540
self.ignored_libraries_patters = [Pattern(s) for s in ignored_libraries]
540541
self.ignored_variables_patters = [Pattern(s) for s in ignored_variables]
542+
self.ignore_arguments_for_library_patters = [Pattern(s) for s in ignore_arguments_for_library]
541543

542544
self.global_library_search_order = global_library_search_order
543545

@@ -864,7 +866,8 @@ def get_library_meta(
864866
name: str,
865867
base_dir: str = ".",
866868
variables: Optional[Dict[str, Optional[Any]]] = None,
867-
) -> Tuple[Optional[LibraryMetaData], str]:
869+
) -> Tuple[Optional[LibraryMetaData], str, bool]:
870+
ignore_arguments = False
868871
try:
869872
import_name = self.find_library(name, base_dir=base_dir, variables=variables)
870873

@@ -886,6 +889,12 @@ def get_library_meta(
886889
)
887890

888891
if result is not None:
892+
ignore_arguments = any(
893+
(p.matches(result.name) if result.name is not None else False)
894+
or (p.matches(result.origin) if result.origin is not None else False)
895+
for p in self.ignore_arguments_for_library_patters
896+
)
897+
889898
if any(
890899
(p.matches(result.name) if result.name is not None else False)
891900
or (p.matches(result.origin) if result.origin is not None else False)
@@ -895,7 +904,7 @@ def get_library_meta(
895904
lambda: f"Ignore library {result.name or '' if result is not None else ''}"
896905
f" {result.origin or '' if result is not None else ''} for caching."
897906
)
898-
return None, import_name
907+
return None, import_name, ignore_arguments
899908

900909
if result.origin is not None:
901910
result.mtimes = {result.origin: Path(result.origin).stat().st_mtime_ns}
@@ -912,13 +921,13 @@ def get_library_meta(
912921
}
913922
)
914923

915-
return result, import_name
924+
return result, import_name, ignore_arguments
916925
except (SystemExit, KeyboardInterrupt):
917926
raise
918927
except BaseException:
919928
pass
920929

921-
return None, import_name
930+
return None, import_name, ignore_arguments
922931

923932
def get_variables_meta(
924933
self,
@@ -1131,7 +1140,7 @@ def _get_library_libdoc(
11311140
base_dir: str,
11321141
variables: Optional[Dict[str, Any]] = None,
11331142
) -> LibraryDoc:
1134-
meta, source = self.get_library_meta(name, base_dir, variables)
1143+
meta, source, ignore_arguments = self.get_library_meta(name, base_dir, variables)
11351144

11361145
self._logger.debug(lambda: f"Load Library {source}{args!r}")
11371146

@@ -1171,7 +1180,7 @@ def _get_library_libdoc(
11711180
result = executor.submit(
11721181
get_library_doc,
11731182
name,
1174-
args,
1183+
args if not ignore_arguments else (),
11751184
working_dir,
11761185
base_dir,
11771186
self.get_resolvable_command_line_variables(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CacheConfig(ConfigBase):
4848
save_location: CacheSaveLocation = CacheSaveLocation.WORKSPACE_STORAGE
4949
ignored_libraries: List[str] = field(default_factory=list)
5050
ignored_variables: List[str] = field(default_factory=list)
51+
ignore_arguments_for_library: List[str] = field(default_factory=list)
5152

5253

5354
@config_section("robotcode.analysis.robot")

0 commit comments

Comments
 (0)