Appearance
| 1 | namespace Analysis is | |
| 2 | use IoC; | |
| 3 | ||
| 4 | use Semantic.Symbols.SignaturePart; | |
| 5 | ||
| 6 | use Syntax.Process.Printer.SIGNATURE_RENDERER; | |
| 7 | ||
| 8 | // Renders a symbol's declaration head against a column budget by | |
| 9 | // walking the SignaturePart tree that `Symbol.describe(context)` | |
| 10 | // produces. The layout work lives in SIGNATURE_RENDERER (shared with | |
| 11 | // the narrowing-inlay type renderer); this adds the hover-specific | |
| 12 | // step of turning a HOVER_USE into that tree and rendering it relative | |
| 13 | // to the use's scope. | |
| 14 | // | |
| 15 | // Variable uses carry their observed (narrowed) type through the | |
| 16 | // context so a hover on a narrowed variable shows the narrowed shape. | |
| 17 | class SIGNATURE_DOC is | |
| 18 | // Column budget for hover signatures. Narrow enough that a | |
| 19 | // long-parameter method wraps in a typical VS Code hover | |
| 20 | // popover; wide enough that short signatures do not break | |
| 21 | // gratuitously. | |
| 22 | DEFAULT_WIDTH: int static => 60; | |
| 23 | ||
| 24 | build(hover: Semantic.HOVER_USE) -> string static => | |
| 25 | build(hover, DEFAULT_WIDTH); | |
| 26 | ||
| 27 | build(hover: Semantic.HOVER_USE, width: int) -> string static is | |
| 28 | let context = hover.context(); | |
| 29 | let s = hover.symbol.collapse_group_if_single_member(); | |
| 30 | let part = s.describe(context); | |
| 31 | ||
| 32 | // Render names relative to the scope the use was recorded in, | |
| 33 | // so a type keeps only the qualification it needs from where | |
| 34 | // the reader's cursor is. | |
| 35 | let use render_scope = IoC.CONTAINER.instance.name_display.with_scope(hover.scope); | |
| 36 | ||
| 37 | return SIGNATURE_RENDERER.render(part, width); | |
| 38 | si | |
| 39 | ||
| 40 | // Render an arbitrary part directly — used by unit tests to pin | |
| 41 | // the layout without constructing a Symbol fixture. | |
| 42 | render(part: SignaturePart, width: int) -> string static => | |
| 43 | SIGNATURE_RENDERER.render(part, width); | |
| 44 | si | |
| 45 | si |