Skip to content

feat: add global variable symbols to workspace search#37

Open
harshatba wants to merge 1 commit into
ram-nadella:mainfrom
harshatba:add-global-variable-symbols
Open

feat: add global variable symbols to workspace search#37
harshatba wants to merge 1 commit into
ram-nadella:mainfrom
harshatba:add-global-variable-symbols

Conversation

@harshatba
Copy link
Copy Markdown

Summary

Extends symbol indexing to include module-level variable definitions, making them searchable via workspace symbol search (Cmd+T / Ctrl+T).

Changes

  • ✅ Add Variable variant to SymbolKind enum
  • ✅ Update LSP handler to map Variable to LspSymbolKind::VARIABLE
  • ✅ Implement assignment extraction in tree-sitter parser
    • Simple assignments: MY_VAR = 42
    • Annotated assignments: name: str = "hello", server: str
    • Tuple unpacking: x, y = 1, 2
    • Chained assignments: a = b = 10
  • ✅ Implement assignment extraction in Ruff parser with same support
  • ✅ Add comprehensive unit and integration tests (both parser backends)
  • ✅ Create test fixture with positive and negative test cases

Behavior

  • Included: Module-level (global) variables only
  • Excluded: Local variables in functions, class attributes (to avoid cluttering search results)

Test Plan

All 57 tests pass:

  • 28 unit tests (including 7 new variable-specific tests)
  • 27 integration tests (including new global variables test)
  • 2 parallel indexing tests

Both parser backends (tree-sitter and ruff) produce matching results.

Testing Locally

  1. Build: cd pylight && cargo build --release
  2. Copy binary: cp pylight/target/release/pylight pydance/
  3. Package extension: cd pydance && npx @vscode/vsce package
  4. Install: code --install-extension pydance-*.vsix
  5. Test with a Python file containing global variables

🤖 Generated with Claude Code

Extends symbol indexing to include module-level variable definitions,
making them searchable via workspace symbol search (Cmd+T).

Changes:
- Add `Variable` variant to `SymbolKind` enum
- Update LSP handler to map Variable to LspSymbolKind::VARIABLE
- Implement assignment extraction in tree-sitter parser
  - Handles simple assignments (MY_VAR = 42)
  - Handles annotated assignments (name: str = "hello")
  - Handles tuple unpacking (x, y = 1, 2)
  - Handles chained assignments (a = b = 10)
- Implement assignment extraction in Ruff parser with same support
- Add comprehensive unit and integration tests
- Create test fixture with positive and negative cases

Only module-level variables are indexed; local variables and class
attributes are excluded to avoid cluttering search results.

All 57 tests pass (28 unit + 27 integration + 2 parallel indexing).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@harshatba harshatba force-pushed the add-global-variable-symbols branch from fe45676 to 6fa5c02 Compare May 11, 2026 16:58
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