Skip to content

Commit

Permalink
feat(devins-lang): add duplicate agent declaration inspection #101
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 20, 2024
1 parent cbc9f05 commit d2df012
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
@@ -0,0 +1,33 @@
package cc.unitmesh.devti.language.lints

import cc.unitmesh.devti.language.psi.DevInTypes
import cc.unitmesh.devti.language.psi.DevInUsed
import cc.unitmesh.devti.language.psi.DevInVisitor
import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.util.elementType

class DevInsDuplicateAgentInspection : LocalInspectionTool() {
override fun getDisplayName() = "Duplicate agent calling"

override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return DevInsDuplicateAgentVisitor(holder)
}

private class DevInsDuplicateAgentVisitor(val holder: ProblemsHolder) : DevInVisitor() {
private var agentIds: MutableSet<String> = mutableSetOf()

override fun visitUsed(o: DevInUsed) {
o.firstChild.let { next ->
if (next.nextSibling.elementType == DevInTypes.AGENT_ID) {
if (agentIds.contains(next.text)) {
holder.registerProblem(next, "Duplicate agent calling")
} else {
agentIds.add(next.text)
}
}
}
}
}
}
Expand Up @@ -41,6 +41,12 @@
id="devinsDocumentationProvider"
implementationClass="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>
<documentationProvider implementation="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>

<localInspection language="DevIn" groupPath="DevIn" groupName="Lints"
displayName="Duplicate agent declaration"
enabledByDefault="true"
level="ERROR"
implementationClass="cc.unitmesh.devti.language.lints.DevInsDuplicateAgentInspection"/>
</extensions>

<actions>
Expand Down

0 comments on commit d2df012

Please sign in to comment.