Commit 0343b68
go-to-definition on calls jumps to __init__/__new__/__call__
Summary:
When go-to-definition is invoked on a call expression, jump to the
underlying method definition instead of the class or variable:
- Constructor calls (`Foo(1)`, `mod.Foo(1)`): jump to `__init__` and/or
`__new__` on the class
- Callable instances (`adder(5)` where `adder` has `__call__`): jump to
`__call__` on the instance's class
- Regular function calls: unchanged (still jumps to the function def)
The implementation detects call context via `covering_nodes`, resolves the
callee's type, and dispatches to `find_call_target_definitions` which uses
the existing `find_attribute_definition_for_base_type` machinery. Only
`ClassDef` types get constructor lookup; only `ClassType` (instances) get
`__call__` lookup; functions and other callables fall through to normal
go-to-definition.
Note: this stack is a different implementation from D87102818. D87102818 reused the find-references queue which ended up being more complicated and required storing a reverse-mapping in state. it was more correct (it would only go to the constructor pyrefly thought was used). instead, this implementation goes to all `__init__`, `__new__`, `__call__`. it might be more useful to see all of them as separate definitions and is much cleaner to implement.
fixes #1877
fixes #1728
Reviewed By: yangdanny97
Differential Revision: D96921976
fbshipit-source-id: c9bfad0699a421720a75ad146b0db92b33b97d361 parent 6701f6a commit 0343b68
File tree
4 files changed
+162
-24
lines changed- pyrefly/lib
- state
- test/lsp
- lsp_interaction
4 files changed
+162
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1402 | 1402 | | |
1403 | 1403 | | |
1404 | 1404 | | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
1405 | 1439 | | |
1406 | 1440 | | |
1407 | 1441 | | |
| |||
1740 | 1774 | | |
1741 | 1775 | | |
1742 | 1776 | | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
1743 | 1794 | | |
1744 | 1795 | | |
1745 | 1796 | | |
| |||
1900 | 1951 | | |
1901 | 1952 | | |
1902 | 1953 | | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
1903 | 1966 | | |
1904 | 1967 | | |
1905 | 1968 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2238 | 2238 | | |
2239 | 2239 | | |
2240 | 2240 | | |
2241 | | - | |
2242 | | - | |
2243 | | - | |
2244 | | - | |
2245 | 2241 | | |
2246 | 2242 | | |
2247 | 2243 | | |
| |||
2259 | 2255 | | |
2260 | 2256 | | |
2261 | 2257 | | |
2262 | | - | |
2263 | | - | |
| 2258 | + | |
| 2259 | + | |
2264 | 2260 | | |
2265 | 2261 | | |
2266 | 2262 | | |
| |||
2289 | 2285 | | |
2290 | 2286 | | |
2291 | 2287 | | |
2292 | | - | |
2293 | | - | |
| 2288 | + | |
| 2289 | + | |
2294 | 2290 | | |
2295 | 2291 | | |
2296 | 2292 | | |
| |||
2326 | 2322 | | |
2327 | 2323 | | |
2328 | 2324 | | |
2329 | | - | |
2330 | | - | |
| 2325 | + | |
| 2326 | + | |
2331 | 2327 | | |
2332 | 2328 | | |
2333 | 2329 | | |
| |||
2357 | 2353 | | |
2358 | 2354 | | |
2359 | 2355 | | |
2360 | | - | |
2361 | | - | |
| 2356 | + | |
| 2357 | + | |
2362 | 2358 | | |
2363 | 2359 | | |
2364 | 2360 | | |
| |||
2384 | 2380 | | |
2385 | 2381 | | |
2386 | 2382 | | |
2387 | | - | |
2388 | | - | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
2389 | 2388 | | |
2390 | 2389 | | |
2391 | 2390 | | |
| |||
2414 | 2413 | | |
2415 | 2414 | | |
2416 | 2415 | | |
2417 | | - | |
2418 | | - | |
| 2416 | + | |
| 2417 | + | |
2419 | 2418 | | |
2420 | 2419 | | |
2421 | 2420 | | |
| |||
2424 | 2423 | | |
2425 | 2424 | | |
2426 | 2425 | | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1020 | 1020 | | |
1021 | 1021 | | |
1022 | 1022 | | |
1023 | | - | |
| 1023 | + | |
1024 | 1024 | | |
1025 | 1025 | | |
1026 | 1026 | | |
| |||
1030 | 1030 | | |
1031 | 1031 | | |
1032 | 1032 | | |
1033 | | - | |
1034 | | - | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1035 | 1036 | | |
1036 | 1037 | | |
1037 | 1038 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
492 | | - | |
| 492 | + | |
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
504 | 504 | | |
505 | 505 | | |
506 | 506 | | |
| |||
0 commit comments