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 e9c8111
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 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,22 @@ 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:
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

0 comments on commit e9c8111

Please sign in to comment.