Skip to content

Commit

Permalink
Set cwd to project root when running Robocop. Fixes #703
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Jul 12, 2022
1 parent e60817e commit 15dfe17
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 27 deletions.
30 changes: 20 additions & 10 deletions robocorp-python-ls-core/src/robocorp_ls_core/robocop_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions robotframework-ls/.settings/org.python.pydev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions robotframework-ls/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 15dfe17

Please sign in to comment.