Skip to content

Commit df2bb82

Browse files
committed
fix(devins-linting): improve detection of duplicate agent IDs in DevInsDuplicateAgentInspection #101
The DevInsDuplicateAgentInspection now uses a set of `DevInUsed` objects instead of strings to more accurately detect and report duplicate agent IDs. This change ensures that the inspection correctly identifies and flags only unique agent IDs within the context of their usage, improving the precision and reliability of the linting process.
1 parent e3b7960 commit df2bb82

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/lints/DevInsDuplicateAgentInspection.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ class DevInsDuplicateAgentInspection : LocalInspectionTool() {
1717
}
1818

1919
private class DevInsDuplicateAgentVisitor(val holder: ProblemsHolder) : DevInVisitor() {
20-
private var agentIds: MutableSet<String> = mutableSetOf()
20+
private var agentIds: MutableSet<DevInUsed> = mutableSetOf()
2121

2222
override fun visitUsed(o: DevInUsed) {
23-
o.firstChild.let { next ->
24-
if (next.nextSibling.elementType == DevInTypes.AGENT_ID) {
25-
if (agentIds.contains(next.text)) {
26-
holder.registerProblem(
27-
o,
28-
DevInBundle.message("inspection.duplicate.agent")
29-
)
30-
} else {
31-
agentIds.add(next.text)
23+
if (o.firstChild.nextSibling.elementType == DevInTypes.AGENT_ID) {
24+
agentIds.add(o)
25+
26+
if (agentIds.contains(o)) {
27+
agentIds.forEachIndexed { index, it ->
28+
if (index > 0) {
29+
holder.registerProblem(it, DevInBundle.message("inspection.duplicate.agent"))
30+
}
3231
}
3332
}
3433
}

0 commit comments

Comments
 (0)