Skip to content

Add context-aware autocomplete for QueryDescendants selectors#1368

Draft
JohnnyMorganz wants to merge 1 commit intomainfrom
feature/query-descendants-autocomplete
Draft

Add context-aware autocomplete for QueryDescendants selectors#1368
JohnnyMorganz wants to merge 1 commit intomainfrom
feature/query-descendants-autocomplete

Conversation

@JohnnyMorganz
Copy link
Owner

@JohnnyMorganz JohnnyMorganz commented Feb 14, 2026

TODO: We now trigger a lot of completion for common punctuation. Is this a performance concern? Maybe we need to scope it down to just ClassNames.

A lot of roblox specific details are leaking into the generic Completion.cpp, can we improve this?

Summary

Completion Contexts

Cursor position Completions
Empty string or after >, >>, ,, space All Instance subclass names
After : Pseudo-classes (not, has) with snippet parentheses
Inside [...] Properties of the preceding class (or Instance if none)
After . or # None (tags/names have no LSP data available)

Implementation Details

  • RobloxLuauExt.cpp: Attaches "QuerySelector" tag to QueryDescendants
  • RobloxCompletion.cpp: Selector context parser (detectSelectorContext, findPrecedingClassName) and "QuerySelector" handler in completionCallback. Extracts shared getPropertiesOfType() helper to deduplicate with existing "Properties" handler
  • Completion.cpp: Computes string content up to cursor for context detection; token-level textEdit replaces only the current token instead of the full string; pseudo-class entries get snippet parentheses and documentation
  • LanguageServer.cpp: Registers [, (, ,, > as completion trigger characters, suppressed outside QuerySelector context

Test plan

  • 22 test cases covering all selector contexts, mid-identifier completion, textEdit ranges, pseudo-class snippets/documentation, fallback to Instance properties, and no-completion cases
  • Full test suite passes (677 tests)
  • Tests pass with --new-solver

🤖 Generated with Claude Code

Commit 6b87442 added magic type narrowing for QueryDescendants but no
autocomplete support. This adds context-aware completions that understand
the CSS-like selector syntax and provide appropriate suggestions based on
cursor position within the selector string.

Completion contexts:
- Class names after combinators (>, >>), commas, parentheses, or spaces
- Pseudo-classes (:not, :has) after colons, with snippet parentheses
- Property names inside brackets ([...]), scoped to the preceding class
- No completions after . or # (tags/names have no LSP data)

Implementation:
- Attach "QuerySelector" tag to QueryDescendants in RobloxLuauExt.cpp
- Add detectSelectorContext() to parse selector content up to cursor
- Add findPrecedingClassName() for bracket property completions
- Extract getPropertiesOfType() to deduplicate with "Properties" handler
- Token-level textEdit replaces only the current token, not the full string
- Pseudo-class entries tagged "SelectorPseudoClass" for snippet post-processing
- Register [, (, ,, > as completion trigger characters, suppressed outside
  QuerySelector context
- Pseudo-class completions include documentation strings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant