8000 Feat/struct size info on hover by giuinktse7 · Pull Request #1 · giuinktse7/ols · GitHub
[go: up one dir, main page]

Skip to content

Feat/struct size info on hover - #1

Merged
giuinktse7 merged 38 commits into
masterfrom
feat/struct-size-info-on-hover
Sep 9, 2026
Merged

giuinktse7 merged 38 commits into
masterfrom
feat/struct-size-info-on-hover

Conversation

@giuinktse7
Copy link
Copy Markdown
Owner

No description provided.

xdk78 and others added 30 commits July 29, 2025 00:12
- 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.
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

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_info config 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.

Comment thread src/server/hover.odin Resolved
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

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 parent and 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 sibling N is 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_nil unions. A #no_nil union with exactly 256 variants has 256 tag states and still fits in one byte, but the strict < 1 << 8 check 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, and b.max_field_align are assigned afterward and never receive polymorphic arguments. Consequently a valid specialization such as Foo :: struct($A: int) #align(A) {value: u8} / Foo(16) cannot produce layout information because A remains unresolved. Include cloned directive expressions in the substitution input and restore them afterward, as resolve_poly_union now does for align (and apply the same treatment in resolve_symbol_return).

src/server/hover.odin:630

  • #sparse is not retained in SymbolFixedArrayValue or the symbol flags, so this path always computes an enumerated array's length from upper - lower + 1. For #sparse[Sparse_Index]u8 with values 2 and 5 (the new test at tests/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. Because Hover.range is 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 :: 4 plus Foo :: struct($N: int) { data: [N]u8 }), causing an unspecialized Foo hover 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_align limits field alignment, not the explicit alignment of the containing struct. This rejects valid combinations such as struct #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

Comment thread src/server/constant.odin
Comment on lines +45 to +49
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)
}
@giuinktse7
giuinktse7 merged commit d48e97b into master Sep 9, 2026
4 checks passed
@giuinktse7
giuinktse7 deleted the feat/struct-size-info-on-hover branch October 25, 2026 08:35
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.

3 participants

0