Skip to content

Commit 9d34ed4

Browse files
committed
feat(analyzer): introduce robotcode.analysis.robot.globalLibrarySearchOrder setting to specify a global search for libs and resources
Implemented this, because analyse `Set Library Search Order` is to hard.
1 parent b43dba2 commit 9d34ed4

File tree

7 files changed

+39
-3
lines changed

7 files changed

+39
-3
lines changed

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,15 @@
564564
"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`.",
565565
"scope": "resource"
566566
},
567+
"robotcode.analysis.robot.globalLibrarySearchOrder": {
568+
"type": "array",
569+
"default": [],
570+
"items": {
571+
"type": "string"
572+
},
573+
"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.",
574+
"scope": "resource"
575+
},
567576
"robotcode.run.openOutputAfterRun": {
568577
"type": "string",
569578
"enum": [

packages/analyze/src/robotcode/analyze/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ class AnalyzerConfig(BaseOptions):
5050
- `myvars.subpackage.subpackage`
5151
""",
5252
)
53+
54+
global_library_search_order: List[str] = field(
55+
default_factory=list,
56+
description="""\
57+
TODO
58+
""",
59+
)

packages/language_server/src/robotcode/language_server/robotframework/configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from robotcode.core.workspace import ConfigBase, config_section
55
from robotcode.language_server.common.parts.diagnostics import AnalysisProgressMode, DiagnosticsMode
6-
from robotcode.robot.diagnostics.workspace_config import CacheConfig, RobotConfig
6+
from robotcode.robot.diagnostics.workspace_config import AnalysisRobotConfig, CacheConfig, RobotConfig
77

88

99
@config_section("robotcode.languageServer")
@@ -67,6 +67,7 @@ class AnalysisConfig(ConfigBase):
6767
references_code_lens: bool = False
6868
find_unused_references: bool = False
6969
cache: CacheConfig = field(default_factory=CacheConfig)
70+
robot: AnalysisRobotConfig = field(default_factory=AnalysisRobotConfig)
7071

7172

7273
@config_section("robotcode")

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from ..utils.stubs import Languages
3434
from .imports_manager import ImportsManager
3535
from .namespace import DocumentType, Namespace
36-
from .workspace_config import CacheConfig, RobotConfig
36+
from .workspace_config import AnalysisRobotConfig, CacheConfig, RobotConfig
3737

3838

3939
class UnknownFileTypeError(Exception):
@@ -474,6 +474,7 @@ def create_imports_manager(self, root_uri: Uri) -> ImportsManager:
474474
*robot_config.variable_files,
475475
]
476476

477+
analysis_config = self.workspace.get_configuration(AnalysisRobotConfig, root_uri)
477478
return ImportsManager(
478479
self.documents_manager,
479480
self.file_watcher_manager,
@@ -484,6 +485,7 @@ def create_imports_manager(self, root_uri: Uri) -> ImportsManager:
484485
environment,
485486
cache_config.ignored_libraries,
486487
cache_config.ignored_variables,
488+
analysis_config.global_library_search_order,
487489
cache_base_path,
488490
)
489491

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ def __init__(
489489
environment: Optional[Dict[str, str]],
490490
ignored_libraries: List[str],
491491
ignored_variables: List[str],
492+
global_library_search_order: List[str],
492493
cache_base_path: Optional[Path],
493494
) -> None:
494495
super().__init__()
@@ -530,6 +531,9 @@ def __init__(
530531

531532
self.ignored_libraries_patters = [Pattern(s) for s in ignored_libraries]
532533
self.ignored_variables_patters = [Pattern(s) for s in ignored_variables]
534+
535+
self.global_library_search_order = global_library_search_order
536+
533537
self._libaries_lock = threading.RLock()
534538
self._libaries: OrderedDict[_LibrariesEntryKey, _LibrariesEntry] = OrderedDict()
535539
self._resources_lock = threading.RLock()

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def __init__(
596596
self._keywords_lock = RLock(default_timeout=120, name="Namespace.keywords")
597597

598598
# TODO: how to get the search order from model
599-
self.search_order: Tuple[str, ...] = ()
599+
self._search_order: Optional[Tuple[str, ...]] = None
600600

601601
self._finder: Optional[KeywordFinder] = None
602602

@@ -625,6 +625,13 @@ def has_analysed(sender) -> None: ...
625625
def document(self) -> Optional[TextDocument]:
626626
return self._document() if self._document is not None else None
627627

628+
@property
629+
def search_order(self) -> Tuple[str, ...]:
630+
if self._search_order is None:
631+
return tuple(self.imports_manager.global_library_search_order)
632+
633+
return self._search_order
634+
628635
def imports_changed(self, sender: Any, uri: DocumentUri) -> None:
629636
# TODO: optimise this by checking our imports
630637
if self.document is not None:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ 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+
52+
53+
@config_section("robotcode.analysis.robot")
54+
@dataclass
55+
class AnalysisRobotConfig(ConfigBase):
56+
global_library_search_order: List[str] = field(default_factory=list)

0 commit comments

Comments
 (0)