Skip to content

Commit d2df012

Browse files
committed
feat(devins-lang): add duplicate agent declaration inspection #101
This commit introduces a new LocalInspectionTool for the DevIns language, which detects and reports duplicate agent declarations. The inspection is implemented in `DevInsDuplicateAgentInspection` and is registered in the `.xml` file under the `localInspection` tag.
1 parent cbc9f05 commit d2df012

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cc.unitmesh.devti.language.lints
2+
3+
import cc.unitmesh.devti.language.psi.DevInTypes
4+
import cc.unitmesh.devti.language.psi.DevInUsed
5+
import cc.unitmesh.devti.language.psi.DevInVisitor
6+
import com.intellij.codeInspection.LocalInspectionTool
7+
import com.intellij.codeInspection.ProblemsHolder
8+
import com.intellij.psi.PsiElementVisitor
9+
import com.intellij.psi.util.elementType
10+
11+
class DevInsDuplicateAgentInspection : LocalInspectionTool() {
12+
override fun getDisplayName() = "Duplicate agent calling"
13+
14+
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
15+
return DevInsDuplicateAgentVisitor(holder)
16+
}
17+
18+
private class DevInsDuplicateAgentVisitor(val holder: ProblemsHolder) : DevInVisitor() {
19+
private var agentIds: MutableSet<String> = mutableSetOf()
20+
21+
override fun visitUsed(o: DevInUsed) {
22+
o.firstChild.let { next ->
23+
if (next.nextSibling.elementType == DevInTypes.AGENT_ID) {
24+
if (agentIds.contains(next.text)) {
25+
holder.registerProblem(next, "Duplicate agent calling")
26+
} else {
27+
agentIds.add(next.text)
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}

exts/devins-lang/src/main/resources/cc.unitmesh.devti.language.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
id="devinsDocumentationProvider"
4242
implementationClass="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>
4343
<documentationProvider implementation="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>
44+
45+
<localInspection language="DevIn" groupPath="DevIn" groupName="Lints"
46+
displayName="Duplicate agent declaration"
47+
enabledByDefault="true"
48+
level="ERROR"
49+
implementationClass="cc.unitmesh.devti.language.lints.DevInsDuplicateAgentInspection"/>
4450
</extensions>
4551

4652
<actions>

0 commit comments

Comments
 (0)