generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...s-lang/src/main/kotlin/cc/unitmesh/devti/language/lints/DevInsDuplicateAgentInspection.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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