From 15dfe174e67ac08724503b55ad0afeeb4b64ce78 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Tue, 12 Jul 2022 10:49:17 -0300 Subject: [PATCH] Set cwd to project root when running Robocop. Fixes #703 --- .../src/robocorp_ls_core/robocop_wrapper.py | 30 ++++++++++++------- .../.settings/org.python.pydev.yaml | 4 +-- robotframework-ls/docs/changelog.md | 2 ++ .../test_server/errors.yml | 8 ++--- .../test_vscode_robot/diagnostics.yml | 8 ++--- .../test_diagnostics_robocop.yml | 12 ++++---- ...diagnostics_robocop_configuration_file.yml | 2 +- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/robocorp-python-ls-core/src/robocorp_ls_core/robocop_wrapper.py b/robocorp-python-ls-core/src/robocorp_ls_core/robocop_wrapper.py index 86880382e1..344ae3d9b6 100644 --- a/robocorp-python-ls-core/src/robocorp_ls_core/robocop_wrapper.py +++ b/robocorp-python-ls-core/src/robocorp_ls_core/robocop_wrapper.py @@ -36,14 +36,24 @@ def collect_robocop_diagnostics( from robocop.utils import issues_to_lsp_diagnostic filename_parent = Path(filename).parent - if filename_parent.exists(): - config = Config(root=filename_parent) - else: - # Unsaved files. - config = Config(root=project_root) - robocop_runner = robocop.Robocop(config=config) - robocop_runner.reload_config() - - issues = robocop_runner.run_check(ast_model, filename, source) - diag_issues = issues_to_lsp_diagnostic(issues) + # Set the working directory to the project root (tricky handling: Robocop + # relies on cwd to deal with the --ext-rules + # See: https://github.com/robocorp/robotframework-lsp/issues/703). + initial_cwd = os.getcwd() + try: + if os.path.exists(project_root): + os.chdir(project_root) + + if filename_parent.exists(): + config = Config(root=filename_parent) + else: + # Unsaved files. + config = Config(root=project_root) + robocop_runner = robocop.Robocop(config=config) + robocop_runner.reload_config() + + issues = robocop_runner.run_check(ast_model, filename, source) + diag_issues = issues_to_lsp_diagnostic(issues) + finally: + os.chdir(initial_cwd) return diag_issues diff --git a/robotframework-ls/.settings/org.python.pydev.yaml b/robotframework-ls/.settings/org.python.pydev.yaml index 6f63002eb4..a0ec7e5536 100644 --- a/robotframework-ls/.settings/org.python.pydev.yaml +++ b/robotframework-ls/.settings/org.python.pydev.yaml @@ -17,8 +17,8 @@ MULTI_BLOCK_COMMENT_SHOW_ONLY_FUNCTION_NAME: true PYDEV_TEST_RUNNER: '2' # PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n auto --tb=native -vv --force-regen # PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n auto --tb=native -vv -PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv -# PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv --force-regen +# PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv +PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv --force-regen PYDEV_USE_PYUNIT_VIEW: true SAVE_ACTIONS_ONLY_ON_WORKSPACE_FILES: true SINGLE_BLOCK_COMMENT_ALIGN_RIGHT: true diff --git a/robotframework-ls/docs/changelog.md b/robotframework-ls/docs/changelog.md index 3506caae43..8817053f1b 100644 --- a/robotframework-ls/docs/changelog.md +++ b/robotframework-ls/docs/changelog.md @@ -7,6 +7,8 @@ NEXT - Fix issue where replacement offset in section completion was wrong. [#700](https://github.com/robocorp/robotframework-lsp/issues/700) - Properly consider extended part of variables in expressions (fixes issue which could make variable not be resolved). [#702](https://github.com/robocorp/robotframework-lsp/issues/702) - Resolve variable files imported as modules. [#699](https://github.com/robocorp/robotframework-lsp/issues/699) +- Vendored Robocop upgraded to 2.2.0. [#703](https://github.com/robocorp/robotframework-lsp/issues/703) +- Robocop is always run with the project root as the cwd. [#703](https://github.com/robocorp/robotframework-lsp/issues/703) - By default Failures/Errors inside a TRY..EXCEPT statement won't suspend execution while debugging. [#698](https://github.com/robocorp/robotframework-lsp/issues/698) - Fixes to support Robot Framework 5.1: - Deal with `robot.running.builder.testsettings.TestDefaults` renamed to `robot.running.builder.settings.Defaults`. diff --git a/robotframework-ls/tests/robotframework_ls_tests/robotframework_server_api/test_server/errors.yml b/robotframework-ls/tests/robotframework_ls_tests/robotframework_server_api/test_server/errors.yml index 282bdff0cd..b109b7066e 100644 --- a/robotframework-ls/tests/robotframework_ls_tests/robotframework_server_api/test_server/errors.yml +++ b/robotframework-ls/tests/robotframework_ls_tests/robotframework_server_api/test_server/errors.yml @@ -1,6 +1,6 @@ - code: '0203' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-doc-suite + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-doc-suite message: Missing documentation in suite range: end: @@ -13,7 +13,7 @@ source: robocop - code: '0401' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#parsing-error + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#parsing-error message: 'Robot Framework syntax error: Unrecognized section header ''*** foo bar ***''. Valid sections: ''Settings'', ''Variables'', ''Keywords'' and ''Comments''.' range: @@ -27,7 +27,7 @@ source: robocop - code: 0813 codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#duplicated-setting + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#duplicated-setting message: 'Unrecognized section header ''*** foo bar ***''. Valid sections: ''Settings'', ''Variables'', ''Keywords'' and ''Comments''.' range: @@ -41,7 +41,7 @@ source: robocop - code: '1002' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-trailing-blank-line + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-trailing-blank-line message: Missing trailing blank line at the end of file range: end: diff --git a/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/diagnostics.yml b/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/diagnostics.yml index 833728a95d..f5bdc8eec4 100644 --- a/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/diagnostics.yml +++ b/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/diagnostics.yml @@ -1,6 +1,6 @@ - code: '0203' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-doc-suite + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-doc-suite message: Missing documentation in suite range: end: @@ -13,7 +13,7 @@ source: robocop - code: '0401' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#parsing-error + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#parsing-error message: 'Robot Framework syntax error: Unrecognized section header ''*** Invalid Invalid ***''. Valid sections: ''Settings'', ''Variables'', ''Keywords'' and ''Comments''.' range: @@ -27,7 +27,7 @@ source: robocop - code: 0813 codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#duplicated-setting + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#duplicated-setting message: 'Unrecognized section header ''*** Invalid Invalid ***''. Valid sections: ''Settings'', ''Variables'', ''Keywords'' and ''Comments''.' range: @@ -41,7 +41,7 @@ source: robocop - code: '1002' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-trailing-blank-line + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-trailing-blank-line message: Missing trailing blank line at the end of file range: end: diff --git a/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop.yml b/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop.yml index 061a0bff41..0158a10cb2 100644 --- a/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop.yml +++ b/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop.yml @@ -1,6 +1,6 @@ - code: '0203' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-doc-suite + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-doc-suite message: Missing documentation in suite range: end: @@ -13,7 +13,7 @@ source: robocop - code: '0704' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#ignored-data + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#ignored-data message: Ignored data found in file range: end: @@ -26,7 +26,7 @@ source: robocop - code: '0202' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-doc-test-case + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-doc-test-case message: Missing documentation in 'Test' test case range: end: @@ -39,7 +39,7 @@ source: robocop - code: '1001' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#trailing-whitespace + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#trailing-whitespace message: Trailing whitespace at the end of line range: end: @@ -52,7 +52,7 @@ source: robocop - code: '0202' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-doc-test-case + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-doc-test-case message: Missing documentation in 'Test' test case range: end: @@ -65,7 +65,7 @@ source: robocop - code: 0801 codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#duplicated-test-case + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#duplicated-test-case message: Multiple test cases with name 'Test' (first occurrence in line 3) range: end: diff --git a/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop_configuration_file.yml b/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop_configuration_file.yml index 9cc803c44a..0277f80cb8 100644 --- a/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop_configuration_file.yml +++ b/robotframework-ls/tests/robotframework_ls_tests/test_vscode_robot/test_diagnostics_robocop_configuration_file.yml @@ -1,6 +1,6 @@ - code: '0203' codeDescription: - href: https://robocop.readthedocs.io/en/2.0.2/rules.html#missing-doc-suite + href: https://robocop.readthedocs.io/en/2.2.0/rules.html#missing-doc-suite message: Missing documentation in suite range: end: