diff --git a/robotframework-ls/src/robotframework_ls/impl/completion_context.py b/robotframework-ls/src/robotframework_ls/impl/completion_context.py index 1a9710e1e3..b5ea2b0d82 100644 --- a/robotframework-ls/src/robotframework_ls/impl/completion_context.py +++ b/robotframework-ls/src/robotframework_ls/impl/completion_context.py @@ -458,6 +458,10 @@ def _resolve_builtin(self, var_name, value_if_not_found, log_info): ret = BUILTIN_VARIABLES_RESOLVED.get(var_name, Sentinel.SENTINEL) if ret is Sentinel.SENTINEL: + if var_name == "CURDIR": + import os + + return os.path.dirname(self._doc.path) log.info(*log_info) return value_if_not_found return ret diff --git a/robotframework-ls/tests/robotframework_ls_tests/_resources/case_curdir/main.robot b/robotframework-ls/tests/robotframework_ls_tests/_resources/case_curdir/main.robot new file mode 100644 index 0000000000..b5856690d7 --- /dev/null +++ b/robotframework-ls/tests/robotframework_ls_tests/_resources/case_curdir/main.robot @@ -0,0 +1,7 @@ +*** Settings *** +Resource ${CURDIR}/lib/my.resource + + +*** Test Cases *** +Test + Some Keyword \ No newline at end of file diff --git a/robotframework-ls/tests/robotframework_ls_tests/test_find_definition.py b/robotframework-ls/tests/robotframework_ls_tests/test_find_definition.py index d5b4bee99e..b8aaa0a5cb 100644 --- a/robotframework-ls/tests/robotframework_ls_tests/test_find_definition.py +++ b/robotframework-ls/tests/robotframework_ls_tests/test_find_definition.py @@ -492,6 +492,19 @@ def test_find_definition_variables_dict_access( ) +def test_find_definition_curdir(workspace, libspec_manager, data_regression): + from robotframework_ls.impl.completion_context import CompletionContext + from robotframework_ls.impl.find_definition import find_definition + + workspace.set_root("case_curdir", libspec_manager=libspec_manager) + doc = workspace.get_doc("main.robot") + + completion_context = CompletionContext(doc, workspace=workspace.ws) + data_regression.check( + _definitions_to_data_regression(find_definition(completion_context)) + ) + + def test_variables_completions_recursive(workspace, libspec_manager, data_regression): from robotframework_ls.impl.completion_context import CompletionContext from robotframework_ls.impl.find_definition import find_definition diff --git a/robotframework-ls/tests/robotframework_ls_tests/test_find_definition/test_find_definition_curdir.yml b/robotframework-ls/tests/robotframework_ls_tests/test_find_definition/test_find_definition_curdir.yml new file mode 100644 index 0000000000..48aac11fcf --- /dev/null +++ b/robotframework-ls/tests/robotframework_ls_tests/test_find_definition/test_find_definition_curdir.yml @@ -0,0 +1,5 @@ +- col_offset: 0 + end_col_offset: 37 + end_lineno: 2 + lineno: 1 + source: my.resource