You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[QUESTION] How to enable collection of unused keywords and variables in CLI #587
Please describe.
When running robotcode analyze code robotcode does not report unused keywords and variables by default. The vscode extension does do this. After reviewing the source code, i found these lines in robot_framework_language_provider.py, which were commented. Is this feature not implemented yet, or can it be enabled by changing the configuration?
Desktop (please complete the following information):
This feature is currently disabled because it was too slow on the command line for whole-project usage.
The code for it is already there, but I decided not to enable it yet. I’m currently working on a project-wide cacheable dependency/reference index to speed this up and improve related functionality.
I also want to add some command line options and robot.toml settings so it can be enabled or disabled when needed.
So please bear with me — it will likely be enabled in one of the next releases.
Thanks for the quick response. I myself noticed it being quite slow and researched it with cProfile to find out what was the culprit. For the project i was working on, it was caused by the variable_not_found function in robotframework, specifically the recommendation finder, as it would search for a similar variable name for creating a suggestion before resolving it and do nothing with the raised VariableError afterwards when it is resolved. This is very very slow for projects with lots and lots of variables. Manually changing the function in my venv to just this:
def variable_not_found(name, candidates, message=None, deco_braces=True):
"""Raise DataError for missing variable name.
Return recommendations for similar variable names if any are found.
"""
raise VariableError(message)
Would make the diagnostics for running it within vscode using the robotcode language server take about 30-ish minutes for 375 .robot/.resource files. Quite significant.
I also messed around with monkeypatching robotframework to fix this issue in my own project. perhaps you could try my approach and see if it improves it:
# ---------------------------------------------------------------------------
# Monkey-patch: suppress the slow "Did you mean ...?" RecommendationFinder
# in robot.variables.notfound.variable_not_found.
#
# The original function builds fuzzy-match recommendations against all known
# variables, which is expensive. We replace it with a fast version that just
# raises immediately.
#
# IMPORTANT: evaluation.py does `from .notfound import variable_not_found`,
# so it holds a *direct reference* to the original function object. We must
# patch BOTH the module attribute AND every caller that already imported it.
# ---------------------------------------------------------------------------
from robot.errors import VariableError
import robot.variables.notfound as _notfound_module
import robot.variables.evaluation as _evaluation_module
import robot.variables.finders as _finders_module
import robot.variables.store as _store_module
import robot.variables as _variables_pkg
_original_variable_not_found = _notfound_module.variable_not_found
def _patched_variable_not_found(name, candidates, message=None, deco_braces=True):
raise VariableError(message or f"Variable '{name}' not found.")
# Patch every module that does `from .notfound import variable_not_found`
_PATCH_TARGETS = [
(_notfound_module, "robot.variables.notfound"),
(_evaluation_module, "robot.variables.evaluation"),
(_finders_module, "robot.variables.finders"),
(_store_module, "robot.variables.store"),
(_variables_pkg, "robot.variables.__init__"),
]
for _mod, _name in _PATCH_TARGETS:
_mod.variable_not_found = _patched_variable_not_found
Thanks for the detailed analysis @MikeAckerschott! Your monkey-patch approach was spot on.
I've now implemented this fix directly in RobotCode — we patch variable_not_found across all RF modules that import it, exactly as you suggested. This will be included in the next release.
I've also filed an upstream issue at Robot Framework to add an official way to disable the RecommendationFinder so we don't need the monkey-patch long-term: robotframework/robotframework#5644
The --collect-unused CLI option and robot.toml setting for enabling unused keyword/variable collection on the command line is also coming soon. see here 5734690
Activity
d-biehl commentedon Mar 24, 2026
This feature is currently disabled because it was too slow on the command line for whole-project usage.
The code for it is already there, but I decided not to enable it yet. I’m currently working on a project-wide cacheable dependency/reference index to speed this up and improve related functionality.
I also want to add some command line options and
robot.tomlsettings so it can be enabled or disabled when needed.So please bear with me — it will likely be enabled in one of the next releases.
MikeAckerschott commentedon Mar 24, 2026
Thanks for the quick response. I myself noticed it being quite slow and researched it with cProfile to find out what was the culprit. For the project i was working on, it was caused by the variable_not_found function in robotframework, specifically the recommendation finder, as it would search for a similar variable name for creating a suggestion before resolving it and do nothing with the raised VariableError afterwards when it is resolved. This is very very slow for projects with lots and lots of variables. Manually changing the function in my venv to just this:
Would make the diagnostics for running it within vscode using the robotcode language server take about 30-ish minutes for 375 .robot/.resource files. Quite significant.
I also messed around with monkeypatching robotframework to fix this issue in my own project. perhaps you could try my approach and see if it improves it:
d-biehl commentedon Mar 30, 2026
Thanks for the detailed analysis @MikeAckerschott! Your monkey-patch approach was spot on.
I've now implemented this fix directly in RobotCode — we patch
variable_not_foundacross all RF modules that import it, exactly as you suggested. This will be included in the next release.I've also filed an upstream issue at Robot Framework to add an official way to disable the
RecommendationFinderso we don't need the monkey-patch long-term: robotframework/robotframework#5644The
--collect-unusedCLI option and robot.toml setting for enabling unused keyword/variable collection on the command line is also coming soon. see here 5734690perf(robot): patch RF's variable_not_found to skip slow Recommendatio…