Skip to content

Commit

Permalink
🐛 Fix support for clion
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavst committed Jul 19, 2024
1 parent eff869c commit d18797f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface Language {
val lang = newLang("com.yoavst.graffiti.intellij.lang.Kotlin")
languages[lang.name] = lang
}
if (isPluginEnabled("com.intellij.modules.clion")) {
if (isPluginEnabled("com.intellij.modules.clion") || isPluginEnabled("com.intellij.clion")) {
val lang = newLang("com.yoavst.graffiti.intellij.lang.Cpp")
languages[lang.name] = lang
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.yoavst.graffiti.intellij.lang

import com.intellij.psi.*
import com.intellij.psi.util.PsiTreeUtil
import com.jetbrains.cidr.lang.psi.OCCppNamespace
import com.jetbrains.cidr.lang.psi.OCDeclarator
import com.jetbrains.cidr.lang.psi.OCFile
import com.jetbrains.cidr.lang.psi.OCFunctionDeclaration
Expand All @@ -11,23 +12,23 @@ import com.yoavst.graffiti.intellij.models.MemberType
import com.yoavst.graffiti.intellij.toAddress

object Cpp : Language {
override val name get() = "OCSlow"
override val name get() = "ObjectiveC"

override fun getNodeInfo(element: PsiElement?, psiFile: PsiFile): Info? {
if (psiFile !is OCFile) {
return null
}

// TODO: support Cpp namespaces
val outerStruct = PsiTreeUtil.getParentOfType(element, OCStruct::class.java)
val outerContainer = PsiTreeUtil.getParentOfType(element, OCStruct::class.java) ?:
PsiTreeUtil.getParentOfType(element, OCCppNamespace::class.java)

val method = PsiTreeUtil.getParentOfType(element, OCFunctionDeclaration::class.java)
if (method != null) return getMemberInfo(psiFile, method, method.declarator?.namespaceQualifier?.name ?: outerStruct?.name, MemberType.Method)
if (method != null) return getMemberInfo(psiFile, method, method.declarator?.namespaceQualifier?.name ?: outerContainer?.name, MemberType.Method)

val declarator = PsiTreeUtil.getParentOfType(element, OCDeclarator::class.java)
if (declarator != null) return getMemberInfo(psiFile, declarator, declarator.namespaceQualifier?.name ?: outerStruct?.name, MemberType.Field)
if (declarator != null) return getMemberInfo(psiFile, declarator, declarator.namespaceQualifier?.name ?: outerContainer?.name, MemberType.Field)

if (outerStruct != null) return Info.Class(outerStruct, outerStruct.name ?: "<anonymous>", psiFile.name, outerStruct.toAddress())
if (outerContainer != null) return Info.Class(outerContainer, outerContainer.name ?: "<anonymous>", psiFile.name, outerContainer.toAddress())
return Info.File(psiFile.name, psiFile.toAddress())
}

Expand Down

0 comments on commit d18797f

Please sign in to comment.