Skip to content

feat(language-server): complete dictionary items and list indices - #703

Closed
testsmith-io wants to merge 2 commits into
robotcodedev:mainfrom
testsmith-io:main
Closed

testsmith-io wants to merge 2 commits into
robotcodedev:mainfrom
testsmith-io:main

Conversation

@testsmith-io

Copy link
Copy Markdown

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

  • Bug fix
  • New feature
  • Refactor / internal change
  • Documentation
  • Build / CI / tooling
  • Breaking change

Checklist

  • I have read the Contribution Guide and the AI and Automated Contribution Policy.
  • The change is focused on a single concern (no unrelated refactors or formatting noise).
  • Tests for the change have been added or updated, and the tests of every changed part pass locally: hatch run test:test for the Python packages (RF matrix against the default Python), npm test for the VS Code extension, ./gradlew test in intellij-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:all passes, and npm run lint for changes to the VS Code extension (also enforced by the pre-commit hooks if installed) — or N/A for documentation-only / non-code changes.
  • Documentation has been updated where relevant (user docs, code comments, README).
  • Generated files (if any) were regenerated with the documented script, not edited by hand.
  • Commits follow Conventional Commits and are cryptographically signed (git commit -S, GPG/SSH).

AI / tooling disclosure

  • No AI/automation was used beyond ordinary editor autocomplete.
  • AI/automation was used; tool(s):
    • I reviewed the generated output manually, understand it, and verified it locally.

Additional notes

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

@d-biehl

d-biehl commented Dec 6, 2026

Copy link
Copy Markdown
Member

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.

@testsmith-io

Copy link
Copy Markdown
Author

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?

@d-biehl

d-biehl commented Dec 6, 2026

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Support Completion of dictionary items

4 participants