Repository navigation
fix: match JDT LS on same-arity overloads, type arguments and varargs - #2
Merged
Merged
Conversation
Comparing definition targets with JDT LS on Nacos (3 x 1500 positions)
found two wrong jumps, both overloads with the same parameter count
(new AccessException("...") went to AccessException(int)), and a few
positions JDT LS resolves that this index missed.
- Overloads with the same arity are scored against what the arguments
are known to be: literals, casts, new expressions, declared types of
locals and fields, and the expression types the resolver follows.
As in Java, a fixed-arity candidate beats one needing varargs.
- Explicit type arguments (RestResult.<T>builder()) no longer hide the
qualifier.
- Qualified annotations (@Outer.Inner(...)) resolve to the nested type.
- Varargs parameters (String... keys) are found as locals.
Parameter types are stored as one interned string per member; an A/B
run on ruoyi-vue-pro shows no memory or latency change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
在 Nacos(2886 个 Java 文件)上同时问 JDT LS 和本插件同一批位置(3 组种子 × 1500 个),比较跳转目标。修复前唯一的两处跳错都是参数个数相同的重载,另有几类 JDT LS 能跳而本插件跳不了的写法。
改动
internal/codenav/overloads.go):索引给每个方法/构造器记下参数的简单类型名(每个成员一个驻留字符串,同签名共享)。调用处有多个候选时,按实参里看得出的类型打分:字面量(字符串、字符、数字后缀、布尔、null)、字符串拼接、强转、X.class、new表达式、局部变量和字段声明的类型、解析器能跟下去的表达式类型。规则和 Java 一样:不需要展开可变参数就能匹配的候选优先于可变参数候选;分数相同取第一个(与原来行为一致)。new AccessException("user not found!")原来跳到AccessException(int),现在跳到AccessException(String);initClassMethod(Set.of(...))跳到Set版本;Preconditions.checkArgument(x, "msg")跳到两参数版本而不是可变参数版本。internal/codenav/qualified.go):RestResult.<T>builder()的builder和其后的调用链能跳。@ExtractorManager.Extractor(...)的Extractor跳到嵌套注解类型。String... keys、Type... typeArguments原来在声明和使用处都跳不了(findLocal没认出...)。resolve.go/parse.go的改动(Viff 上游文件)都记在internal/codenav/UPSTREAM.md:Viff 还没发布 codenav,上游发布后连同新文件一起提回去。docs/releases/v0.0.1.md同步。验证
internal/codenav/jdtls_cases_test.go(修复前失败 12+5 条,修复后通过);go test -race ./...通过。剩下的“不一样”都不是跳错:
org.xml.sax.Attributes在 JDK 里(JDT LS 归为依赖库);Properties.putAll是 JDK 9 起的重写(模块按 JDK 8 编译)。🤖 Generated with Claude Code