Skip to content

document-symbol: Initial implementation#474

Merged
aviatesk merged 2 commits intomasterfrom
avi/document-symbol
Jan 14, 2026
Merged

document-symbol: Initial implementation#474
aviatesk merged 2 commits intomasterfrom
avi/document-symbol

Conversation

@aviatesk
Copy link
Owner

This commit implements the textDocument/documentSymbol LSP feature, which provides structured outline information for Julia source files.

The implementation uses a hybrid approach:

  1. Surface AST (st0) analysis for top-level symbols
  2. Scope analysis (ctx3) for local symbols within scoped constructs

Top-level symbol extraction covers:

  • Modules (including baremodule)
  • Functions (both long-form and short-form definitions)
  • Macros
  • Structs (with fields and inner constructors)
  • Abstract and primitive types
  • Constants and global variables
  • Top-level assignments (including tuple destructuring)
  • Let/while/for blocks
  • Docstrings
  • Special handling for @enum macrocalls

For scoped constructs (functions, let blocks, etc.), the implementation performs JuliaLowering's scope analysis to extract local bindings:

  • Function arguments with type annotations, default values, and varargs
  • Keyword arguments (including kwsorter scope merging)
  • Local variables with assignments and type annotations
  • For loop iterators
  • Nested functions (recursively extracted as children)
  • Static type parameters

Symbol details provide rich context for editor display:

  • Short-form functions show f(x) = format
  • Long-form functions show function f(x) format
  • Arguments show their full declaration context
  • Local variables show their definition context

The implementation includes caching with invalidation on document changes, and deduplication logic to handle cases where the same binding appears in multiple scopes.

Screenshot 2026-01-15 at 03 47 55

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 87.57396% with 63 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.33%. Comparing base (31e495b) to head (1b54251).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/document-symbol.jl 88.82% 55 Missing ⚠️
src/initialize.jl 44.44% 5 Missing ⚠️
src/JETLS.jl 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #474      +/-   ##
==========================================
+ Coverage   66.67%   68.33%   +1.66%     
==========================================
  Files          44       45       +1     
  Lines        5905     6411     +506     
==========================================
+ Hits         3937     4381     +444     
- Misses       1968     2030      +62     
Flag Coverage Δ
JETLS.jl 68.33% <87.57%> (+1.66%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This commit implements the `textDocument/documentSymbol` LSP feature,
which provides structured outline information for Julia source files.

The implementation uses a hybrid approach:
1. Surface AST (`st0`) analysis for top-level symbols
2. Scope analysis (`ctx3`) for local symbols within scoped constructs

Top-level symbol extraction covers:
- Modules (including baremodule)
- Functions (both long-form and short-form definitions)
- Macros
- Structs (with fields and inner constructors)
- Abstract and primitive types
- Constants and global variables
- Top-level assignments (including tuple destructuring)
- Let/while/for blocks
- Docstrings
- Special handling for `@enum` macrocalls

For scoped constructs (functions, let blocks, etc.), the implementation
performs JuliaLowering's scope analysis to extract local bindings:
- Function arguments with type annotations, default values, and varargs
- Keyword arguments (including kwsorter scope merging)
- Local variables with assignments and type annotations
- For loop iterators
- Nested functions (recursively extracted as children)
- Static type parameters

Symbol details provide rich context for editor display:
- Short-form functions show `f(x) =` format
- Long-form functions show `function f(x)` format
- Arguments show their full declaration context
- Local variables show their definition context

The implementation includes caching with invalidation on document changes,
and deduplication logic to handle cases where the same binding appears
in multiple scopes.
@aviatesk aviatesk force-pushed the avi/document-symbol branch from 8b47538 to 1b54251 Compare January 14, 2026 21:09
@aviatesk aviatesk merged commit 59e85cf into master Jan 14, 2026
11 of 13 checks passed
@aviatesk aviatesk deleted the avi/document-symbol branch January 14, 2026 21:39
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