Repository navigation
feat(language-server): complete dictionary items and list indices - #703
testsmith-io wants to merge 2 commits into
Conversation
Offer completions when a variable item access is being typed. For
${VAR}[ the keys of a dictionary or the indices of a list are
suggested, and for the extended dot syntax ${VAR.key} the dictionary
keys are suggested as well (Robot Framework stores dicts as DotDict,
so both forms read the same keys).
The variable is resolved to its actual value to build the suggestions,
the same way hover resolves it. Chained access (${VAR}[a][b]), partial
keys, a missing closing bracket, and several accesses in one argument
token (${d}[a] ${d}[b]) are handled, and "[" now triggers completion.
Closes robotcodedev#50
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved dictionary-completion bugs mishandle escaped keys, overwrite subsequent access segments, and suggest dot-access names that do not resolve to the intended values.
7 open issues
Escape variable sigils in literal dictionary keys · New Preserve escaped delimiters when resolving nested item expressions · New Ignore escaped brackets when tracking dictionary access · New Find the actual closing bracket when replacing a key · New Allow spaces in dictionary base variable names · New Limit completion edits to the current member · New Exclude keywords and class attributes from dot completions · New
What changed in this PR
Adds variable-item completion to RobotCode’s language server, addressing dictionary-key completion requested in #50.
Changes:
- Suggests dictionary keys and list indices for bracket access.
- Adds dictionary-key suggestions for dot syntax and
[as a completion trigger. - Adds focused tests for completion results and common cursor positions.
| File | Description |
|---|---|
| tests/robotcode/language_server/robotframework/parts/test_completion_dictionary_items.py | Tests dictionary, list, dot-syntax, and multiple-access completions. |
| packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py | Resolves variable values and builds item-access completion edits. |
Review effort: Balanced
|
Thanks for taking a stab at #50. I'm closing this PR without a detailed review, for two reasons. First, it doesn't follow the Contribution Guide and the AI and Automated Contribution Policy: the checklist and the AI/tooling disclosure in the PR template are left empty, the commits are not signed, and the second commit doesn't follow Conventional Commits. Second, the approach doesn't fit how RobotCode's analysis works. The PR resolves the variable's value each time completion is requested and checks its type. That evaluates every variable in scope while typing, and it misses dictionaries from variable files (YAML, JSON, Python), the most common source of such values. RobotCode doesn't keep those values at all. The keys need to be recorded where a variable is defined or its variable file is loaded, and completion should only read them. That touches parts of the analysis that are being reworked at the moment, so a revised version of this PR would have no stable base. I'll keep #50 open and describe the direction there. If you want to pick it up again later, please discuss it in the issue first. |
|
Thanks for the detailed close, that makes sense. You're right that resolving the value on each request is the wrong model, and I didn't realize imported variable files only keep native scalars, so dicts from .py/YAML/JSON wouldn't complete anyway. Recording the keys at definition/load time and just reading them in completion sounds like the way to go. I'd like to have another go once the direction is clear. Main thing I'm unsure about is where the keys should live (a field on VariableDefinition, or something separate) and whether you want flat keys or nested. Also, any rough idea when the analysis rework will be done? |
|
Thanks for the quick reply and for wanting to give it another go. I'd rather leave the whole topic open for now. A lot in RobotCode's analysis is being rebuilt at the moment: I'm working on a new semantic analyzer that will replace the current one completely, and it will probably be ready with one of the next releases. It first has to do everything the current analyzer does. New features come only after that, because anything built on the current analyzer now would have to be built a second time. So I can't answer your questions yet: where the keys live, how deep they go and how they get there will be decided on the new analyzer. I've written down the open points in #50. If you're still interested once the new analyzer is ready, that's the place to pick it up. |

Offer completions when a variable item access is being typed. For ${VAR}[ the keys of a dictionary or the indices of a list are suggested, and for the extended dot syntax ${VAR.key} the dictionary keys are suggested as well (Robot Framework stores dicts as DotDict, so both forms read the same keys).
The variable is resolved to its actual value to build the suggestions, the same way hover resolves it. Chained access (${VAR}[a][b]), partial keys, a missing closing bracket, and several accesses in one argument token (${d}[a] ${d}[b]) are handled, and "[" now triggers completion.
Closes #50
Summary
Type of change
Checklist
hatch run test:testfor the Python packages (RF matrix against the default Python),npm testfor the VS Code extension,./gradlew testinintellij-client/for the PyCharm plugin — or N/A for documentation-only / non-code changes. See Running Tests for faster iteration options and the full matrix.hatch run lint:allpasses, andnpm run lintfor changes to the VS Code extension (also enforced by the pre-commit hooks if installed) — or N/A for documentation-only / non-code changes.git commit -S, GPG/SSH).AI / tooling disclosure
Additional notes