|
12 | 12 | * PASS 1 — collect class/module declarations (with lexical nesting), |
13 | 13 | * superclasses, include/prepend/extend mixins, and method tables |
14 | 14 | * (instance vs singleton classified from the AST — `def m` vs |
15 | | - * `def self.m` / `class << self`). |
| 15 | + * `def self.m` / `class << self`). Defs and mixin calls inside a |
| 16 | + * BLOCK (`class_methods do … end`, `included do … end`) belong to |
| 17 | + * some other module and are not recorded. |
16 | 18 | * PASS 1.5 — infer instance-variable types from `@x = Const.new` |
17 | | - * assignments inside method bodies (conflicting types latch to |
18 | | - * "conflicted" and resolve to nothing). |
| 19 | + * (and `@x ||= Const.new`) inside method bodies. Any other write |
| 20 | + * to the ivar latches it as untypable. |
19 | 21 | * PASS 2 — walk method bodies, track local variable types through |
20 | | - * assignments, and resolve call expressions into CBMResolvedCall |
21 | | - * edges via Ruby method lookup (prepends → own → includes → |
22 | | - * superclass chain; extends feed the singleton side). |
| 22 | + * assignments with Ruby's scope gates (fresh scope per def/class, |
| 23 | + * chained scope per block, parameters unknown, untyped writes |
| 24 | + * rebind to unknown), and resolve call expressions into |
| 25 | + * CBMResolvedCall edges via Ruby method lookup (prepends → own → |
| 26 | + * includes → superclass chain; extends feed the singleton side). |
| 27 | + * The walk fails closed the moment an ancestor is unresolved. |
23 | 28 | * |
24 | 29 | * Verified tree-sitter-ruby node/field names (vendored compiled grammar at |
25 | 30 | * internal/cbm/vendored/grammars/ruby/parser.c — ts_symbol_names and |
26 | 31 | * ts_field_names tables): |
27 | 32 | * - call : fields `receiver`, `method`, `arguments`, `block`. Both |
28 | | - * `foo(x)` and command calls (`foo x`) surface as "call" nodes. |
| 33 | + * `foo(x)` and command calls (`foo x`) surface as "call" nodes. A lone |
| 34 | + * `foo` is an `identifier`, never a call — and the extractor emits no |
| 35 | + * call for it either, so the resolver does not treat it as one. |
29 | 36 | * - class : fields `name` (constant | scope_resolution), `superclass` |
30 | 37 | * (a `superclass` wrapper node), `body` (body_statement). |
31 | 38 | * - module : fields `name`, `body`. |
32 | 39 | * - method : fields `name`, `parameters`, `body`. |
33 | 40 | * - singleton_method : fields `object` (self | constant), `name`, `body`. |
34 | 41 | * - singleton_class : `class << self` — fields `value`, body children. |
35 | | - * - assignment : fields `left`, `right`. |
| 42 | + * - assignment : fields `left`, `right` (`left` may be a |
| 43 | + * left_assignment_list for `a, b = …`). |
| 44 | + * - operator_assignment : fields `left`, `operator`, `right` (`||=` etc.). |
| 45 | + * - block / do_block / lambda : field `parameters` (block_parameters / |
| 46 | + * lambda_parameters), body. |
| 47 | + * - method_parameters children: identifier | optional_parameter | |
| 48 | + * keyword_parameter | splat_parameter | hash_splat_parameter | |
| 49 | + * block_parameter (each with a `name` field) | destructured_parameter. |
36 | 50 | * - scope_resolution : fields `scope` (may be absent for ::Foo), `name`. |
37 | 51 | * - leaves: constant, identifier, self, instance_variable, super, |
38 | 52 | * string, array, hash, integer, float, simple_symbol, regex. |
|
50 | 64 | * the edge lands on the Class node, exactly like Python's lsp_constructor. |
51 | 65 | * |
52 | 66 | * Zero-edge guarantee: if a receiver's type is unknown/unindexed, NO edge |
53 | | - * is emitted (false edges are worse than missing edges). Dynamic dispatch |
54 | | - * (`send`, `public_send`, `method_missing`, `define_method`) is |
55 | | - * intentionally ignored. |
| 67 | + * is emitted (false edges are worse than missing edges). Concretely: |
| 68 | + * - dynamic dispatch (`send`, `public_send`, `__send__`, `method_missing`, |
| 69 | + * `define_method`, the eval/exec family) is never guessed through; |
| 70 | + * - a block that rebinds `self` (instance_eval/exec, class_eval/exec, |
| 71 | + * module_eval/exec, define_method, Class.new/Module.new) suppresses bare, |
| 72 | + * `self.` and `super` dispatch inside it; |
| 73 | + * - an unresolved prepend blocks even an own-method hit, an unresolved |
| 74 | + * include/extend/superclass stops the walk, and a blocked walk never |
| 75 | + * falls through to a same-named top-level def or the Object fallback; |
| 76 | + * - a local or ivar written with anything the resolver cannot type loses |
| 77 | + * its type rather than keeping a stale one. |
56 | 78 | */ |
57 | 79 |
|
58 | 80 | #include "ruby_lsp.h" |
|
0 commit comments