6262from robot .variables .filesetter import PythonImporter , YamlImporter
6363from robot .variables .finders import VariableFinder
6464from robot .variables .replacer import VariableReplacer
65- from robot .variables .search import contains_variable
6665from robotcode .core .lsp .types import Position , Range
6766from robotcode .core .utils .path import normalized_path
6867from robotcode .robot .diagnostics .entities import (
8483from robotcode .robot .utils .match import normalize , normalize_namespace
8584from robotcode .robot .utils .stubs import HasError , HasErrors
8685
86+ from ..utils .variables import contains_variable
87+
8788if get_robot_version () < (7 , 0 ):
8889 from robot .running .handlers import _PythonHandler , _PythonInitHandler # pyright: ignore[reportMissingImports]
8990 from robot .running .model import ResourceFile # pyright: ignore[reportMissingImports]
@@ -1669,9 +1670,8 @@ def _find_library_internal(
16691670
16701671 robot_variables = None
16711672
1672- robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
1673-
16741673 if contains_variable (name , "$@&%" ):
1674+ robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
16751675 try :
16761676 name = robot_variables .replace_string (name , ignore_errors = False )
16771677 except DataError as error :
@@ -1840,7 +1840,11 @@ def get_test_library(
18401840 library_name ,
18411841 args ,
18421842 create_handlers = False ,
1843- variables = robot_variables ,
1843+ variables = (
1844+ robot_variables
1845+ if robot_variables is not None
1846+ else resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
1847+ ),
18441848 )
18451849 if get_robot_version () < (7 , 0 ):
18461850 _ = lib .get_instance ()
@@ -2099,9 +2103,8 @@ def _find_variables_internal(
20992103
21002104 _update_env (working_dir )
21012105
2102- robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2103-
21042106 if contains_variable (name , "$@&%" ):
2107+ robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
21052108 try :
21062109 name = robot_variables .replace_string (name , ignore_errors = False )
21072110 except DataError as error :
@@ -2122,12 +2125,18 @@ def resolve_args(
21222125 command_line_variables : Optional [Dict [str , Optional [Any ]]] = None ,
21232126 variables : Optional [Dict [str , Optional [Any ]]] = None ,
21242127) -> Tuple [Any , ...]:
2125- robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2128+ # robot_variables = resolve_robot_variables(working_dir, base_dir, command_line_variables, variables)
2129+ robot_variables : Any = None
21262130
21272131 result = []
21282132 for arg in args :
21292133 if isinstance (arg , str ):
2130- result .append (robot_variables .replace_string (arg , ignore_errors = True ))
2134+ if contains_variable (arg , "$@&%" ):
2135+ if robot_variables is None :
2136+ robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2137+ result .append (robot_variables .replace_string (arg , ignore_errors = True ))
2138+ else :
2139+ result .append (arg )
21312140 else :
21322141 result .append (arg )
21332142
@@ -2402,8 +2411,8 @@ def find_file(
24022411) -> str :
24032412 _update_env (working_dir )
24042413
2405- robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
24062414 if contains_variable (name , "$@&%" ):
2415+ robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
24072416 try :
24082417 name = robot_variables .replace_string (name , ignore_errors = False )
24092418 except DataError as error :
@@ -2505,7 +2514,7 @@ def complete_library_import(
25052514 if e not in DEFAULT_LIBRARIES
25062515 ]
25072516
2508- if name is not None :
2517+ if name is not None and contains_variable ( name , "$@&%" ) :
25092518 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
25102519
25112520 name = robot_variables .replace_string (name , ignore_errors = True )
@@ -2581,7 +2590,7 @@ def complete_resource_import(
25812590
25822591 result : List [CompleteResult ] = []
25832592
2584- if name is not None :
2593+ if name is not None and contains_variable ( name , "$@&%" ) :
25852594 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
25862595
25872596 name = robot_variables .replace_string (name , ignore_errors = True )
@@ -2621,7 +2630,7 @@ def complete_variables_import(
26212630
26222631 result : List [CompleteResult ] = []
26232632
2624- if name is not None :
2633+ if name is not None and contains_variable ( name , "$@&%" ) :
26252634 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
26262635
26272636 name = robot_variables .replace_string (name , ignore_errors = True )
0 commit comments