Repository navigation
Feat/struct size info on hover - #1
Conversation
- track if field layouts are known - support more types like scalars, aliases, distinct types, and fixed arrays - suppress size information for unsupported field types
Detect recursive by-value type layouts and treat them as unknown instead of recursing indefinitely. This prevents OLS from crashing when hovering malformed self-referential or mutually recursive structs.
Calculate SIMD vector layouts using Odin’s target-specific alignment rules.
Keep completion and signature documentation free of hover-only layout details. This also avoids unnecessary recursive layout calculations.
Render size and alignment as a distinct Markdown section so clients do not combine layout metadata with the struct's documentation.
Add layout mappings for UTF-16 strings, runtime descriptor types, fixed-width booleans, and endian-specific integers and floats.
Support configuration directives, conversions, conditionals, size_of, and align_of when calculating layout attributes and container bounds.
Return an unknown layout when a complement operand is unsigned, context-dependent, or cannot be resolved. This prevents hover information from reporting sizes based on incorrect integer semantics.
There was a problem hiding this comment.
🟡 Changes recommended
There is a verified syntax error in src/server/hover.odin (}} else if ...) that will prevent compilation and must be fixed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds optional struct layout (size/alignment/padding) information to hover output, controlled by a new configuration flag, and refactors symbol documentation generation so hover-only layout details don’t leak into signature help/completion docs.
Changes:
- Add
enable_hover_struct_size_infoconfig plumbing (schema → init options → runtime config) and pass config into hover computation. - Implement a layout evaluator for many Odin type forms (structs, unions, arrays, bit_sets, constants/#config, etc.) and append layout info to hover when enabled and target profile matches.
- Update/extend tests to cover hover layout output and to ensure signature help/completions docs exclude hover-only layout content.
File summaries
| File | Description |
|---|---|
| tests/signatures_test.odin | Adds regression coverage to ensure hover-only layout info doesn’t appear in signature docs. |
| tests/hover_test.odin | Adds extensive hover tests for struct layout reporting across many type constructs. |
| tests/completions_test.odin | Ensures completions documentation remains stable even when hover layout is enabled. |
| src/testing/testing.odin | Extends test helpers for signature doc assertions and passes config into hover helper calls. |
| src/server/types.odin | Adds enable_hover_struct_size_info to OLS initialize options struct. |
| src/server/symbol.odin | Improves polymorphic argument application and tags #simd types when reconstructing AST expressions. |
| src/server/signature.odin | Switches signature documentation to symbol-only content (no hover-specific layout). |
| src/server/requests.odin | Reads new config option and passes config into hover requests. |
| src/server/hover.odin | Implements layout evaluation and appends layout summary to hover output when enabled. |
| src/server/generics.odin | Refactors polymorphic argument applicatio 8000 n and tracks union specialization state. |
| src/server/constant.odin | Adds integer/boolean constant evaluation to support layout resolution. |
| src/server/completion.odin | Switches completion item documentation to symbol-only content (no hover-specific layout). |
| src/server/collector.odin | Ensures package aliases are replaced in more collected type/value expressions and tags SOA/SIMD flags. |
| src/server/analysis.odin | Updates polymorphic struct handling to use the new argument application helper. |
| src/common/config.odin | Adds enable_hover_struct_size_info to runtime config. |
| misc/ols.schema.json | Exposes enable_hover_struct_size_info in the JSON schema with default false. |
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
Four moderate correctness issues can cause missing or inaccurate layout information.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (7)
Previously missed (3) — in code that hasn't changed since the last review.
src/server/generics.odin:913
- The traversal stores only one mutable
parentand never restores it after descending. In a specialized expression such as[(N + 1) * N]u8, visiting the nested parentheses overwrites the root binary parent, so the later siblingNis not substituted; it may then resolve to an unrelated package constant and produce a wrong layout. Use a parent-aware rewrite or a parent stack so every occurrence is replaced.
src/server/hover.odin:393 - The tag thresholds incorrectly reserve a nil tag for
#no_nilunions. A#no_nilunion with exactly 256 variants has 256 tag states and still fits in one byte, but the strict< 1 << 8check selects two bytes and reports the wrong size (the same off-by-one occurs at the 16-bit boundary). Base the thresholds on the actual number of tag states.
This issue also appears in the following locations of the same file:
- line 471
- line 612
- line 629
- line 1188
src/server/symbol.odin:431
- This substitution only visits
b.types;b.align,b.min_field_align, andb.max_field_alignare assigned afterward and never receive polymorphic arguments. Consequently a valid specialization such asFoo :: struct($A: int) #align(A) {value: u8}/Foo(16)cannot produce layout information becauseAremains unresolved. Include cloned directive expressions in the substitution input and restore them afterward, asresolve_poly_unionnow does foralign(and apply the same treatment inresolve_symbol_return).
src/server/hover.odin:630
#sparseis not retained inSymbolFixedArrayValueor the symbol flags, so this path always computes an enumerated array's length fromupper - lower + 1. For#sparse[Sparse_Index]u8with values 2 and 5 (the new test attests/hover_test.odin:5946), that produces four elements even though the sparse array stores two, inflating the reported struct size. Preserve the sparse directive during collection/resolution and use the enum member count for sparse arrays.
case SymbolFixedArrayValue:
length, length_known := resolve_array_element_count(evaluation, value.len)
src/server/hover.odin:1189
- This new enum implicit-selector early return does not set
hover.range. BecauseHover.rangeis non-optional, clients receive the zero range instead of the selector's token range; the previous shared path assigned this before returning.
hover.contents = write_hover_content(&ast_context, symbol, config)
return hover, true, true
src/server/hover.odin:618
- Generic structs are evaluated even when their polymorphic parameters are not fully bound. Unlike unions, there is no specialization guard; unresolved parameter identifiers can then resolve as package constants/types (for example, global
N :: 4plusFoo :: struct($N: int) { data: [N]u8 }), causing an unspecializedFoohover to report a concrete but invalid size. Track full struct specialization and reject layout evaluation until all parameters are bound.
case SymbolStructValue:
layout, known := resolve_struct_layout(evaluation, value)
if !known {
return {}, false
}
return {layout.size, layout.alignment}, true
src/server/hover.odin:474
#max_field_alignlimits field alignment, not the explicit alignment of the containing struct. This rejects valid combinations such asstruct #align(16) #max_field_align(4)and suppresses layout information even though the calculation below already handles the two directives independently. Remove the aggregate-vs-field comparison.
if max_field_alignment > 0 && min_field_alignment > max_field_alignment ||
custom_alignment > 0 && custom_alignment < min_field_alignment ||
max_field_alignment > 0 && custom_alignment > max_field_alignment {
return {}, false
- Files reviewed: 16/16 changed files
- Comments generated: 1
- Review effort level: Balanced
| key := extract_config_key(call.args[0]) or_return | ||
| if evaluation.config != nil { | ||
| if configured, found := evaluation.config.profile.defines[key]; found { | ||
| return strconv.parse_int(configured) | ||
| } |
No description provided.