-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package jp.s6n.idea.typespec.lang | ||
|
||
import com.intellij.icons.AllIcons | ||
import com.intellij.ide.IconProvider | ||
import com.intellij.psi.PsiElement | ||
import jp.s6n.idea.typespec.lang.psi.* | ||
import javax.swing.Icon | ||
|
||
class TypeSpecIconProvider : IconProvider() { | ||
override fun getIcon(element: PsiElement, flags: Int): Icon? { | ||
return when (element) { | ||
is TypeSpecEnumStatement -> AllIcons.Nodes.Enum | ||
is TypeSpecUnionStatement -> AllIcons.Nodes.Enum | ||
is TypeSpecModelStatement -> AllIcons.Nodes.Class | ||
is TypeSpecInterfaceStatement -> AllIcons.Nodes.Interface | ||
is TypeSpecAliasStatement -> AllIcons.Nodes.Type | ||
is TypeSpecOperationStatement -> AllIcons.Nodes.Function | ||
else -> null | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package jp.s6n.idea.typespec.lang | ||
|
||
import com.intellij.ide.projectView.PresentationData | ||
import com.intellij.ide.structureView.StructureViewBuilder | ||
import com.intellij.ide.structureView.StructureViewModelBase | ||
import com.intellij.ide.structureView.StructureViewTreeElement | ||
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder | ||
import com.intellij.ide.util.treeView.smartTree.TreeElement | ||
import com.intellij.lang.PsiStructureViewFactory | ||
import com.intellij.navigation.ItemPresentation | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.psi.NavigatablePsiElement | ||
import com.intellij.psi.PsiFile | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecFile | ||
|
||
class TypeSpecStructureViewFactory : PsiStructureViewFactory { | ||
override fun getStructureViewBuilder(file: PsiFile) = object : TreeBasedStructureViewBuilder() { | ||
override fun createStructureViewModel(editor: Editor?) = TypeSpecStructureViewModel(file, editor) | ||
} | ||
} | ||
|
||
class TypeSpecStructureViewModel(file: PsiFile, editor: Editor?) : StructureViewModelBase(file, editor, TypeSpecStructureViewElement(file)) | ||
|
||
class TypeSpecStructureViewElement(private val element: NavigatablePsiElement) : StructureViewTreeElement { | ||
override fun getValue() = element | ||
|
||
override fun getPresentation(): ItemPresentation = element.presentation ?: PresentationData() | ||
|
||
override fun getChildren(): Array<TreeElement> { | ||
return when (element) { | ||
is TypeSpecFile -> { | ||
element.statements | ||
.filterIsInstance<NavigatablePsiElement>() | ||
.filter { it.presentation != null } | ||
.map { TypeSpecStructureViewElement(it) } | ||
.toTypedArray() | ||
} | ||
else -> TreeElement.EMPTY_ARRAY | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package jp.s6n.idea.typespec.lang.psi.impl | ||
|
||
import com.intellij.navigation.ItemPresentation | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecAliasStatement | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecElement | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecEnumStatement | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecInterfaceStatement | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecModelStatement | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecOperationStatement | ||
import jp.s6n.idea.typespec.lang.psi.TypeSpecUnionStatement | ||
|
||
object TypeSpecImplUtil { | ||
@JvmStatic | ||
fun getPresentation(element: TypeSpecElement): ItemPresentation? { | ||
return when (element) { | ||
is TypeSpecEnumStatement -> object : ItemPresentation { | ||
override fun getPresentableText() = element.identifier.text | ||
override fun getIcon(unused: Boolean) = element.getIcon(0) | ||
} | ||
is TypeSpecUnionStatement -> object : ItemPresentation { | ||
override fun getPresentableText() = element.identifier.text | ||
override fun getIcon(unused: Boolean) = element.getIcon(0) | ||
} | ||
is TypeSpecModelStatement -> object : ItemPresentation { | ||
override fun getPresentableText() = element.identifier.text | ||
override fun getIcon(unused: Boolean) = element.getIcon(0) | ||
} | ||
is TypeSpecInterfaceStatement -> object : ItemPresentation { | ||
override fun getPresentableText() = element.identifier.text | ||
override fun getIcon(unused: Boolean) = element.getIcon(0) | ||
} | ||
is TypeSpecOperationStatement -> object : ItemPresentation { | ||
override fun getPresentableText() = element.operation.identifier.text | ||
override fun getIcon(unused: Boolean) = element.getIcon(0) | ||
} | ||
is TypeSpecAliasStatement -> object : ItemPresentation { | ||
override fun getPresentableText() = element.identifier.text | ||
override fun getIcon(unused: Boolean) = element.getIcon(0) | ||
} | ||
else -> null | ||
} | ||
} | ||
} |