generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
103 additions
and
74 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,26 +1,18 @@ | ||
package com.feakin.intellij | ||
|
||
import com.intellij.openapi.fileTypes.LanguageFileType | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import javax.swing.Icon | ||
|
||
class FeakinFileType : LanguageFileType(FeakinLanguage) { | ||
override fun getName(): String { | ||
return "Feakin File" | ||
} | ||
object FeakinFileType : LanguageFileType(FeakinLanguage) { | ||
|
||
override fun getDescription(): String { | ||
return "Feakin language file" | ||
} | ||
override fun getName(): String = "Feakin File" | ||
|
||
override fun getDefaultExtension(): String { | ||
return "fkl" | ||
} | ||
override fun getIcon(): Icon = FeakinIcons.FILE | ||
|
||
override fun getIcon(): Icon { | ||
return FeakinIcons.FILE | ||
} | ||
override fun getDefaultExtension(): String = "fkl" | ||
|
||
companion object { | ||
val INSTANCE = FeakinFileType() | ||
} | ||
override fun getCharset(file: VirtualFile, content: ByteArray): String = "UTF-8" | ||
|
||
override fun getDescription(): String = "Feakin DSL file" | ||
} |
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
1 change: 0 additions & 1 deletion
1
src/main/kotlin/com/feakin/intellij/completion/FeakinCommenter.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
67 changes: 43 additions & 24 deletions
67
src/main/kotlin/com/feakin/intellij/edit/FeakinFoldingBuilder.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 |
---|---|---|
@@ -1,42 +1,61 @@ | ||
package com.feakin.intellij.edit | ||
|
||
import com.feakin.intellij.FeakinFile | ||
import com.feakin.intellij.psi.FeakinContextMapDeclaration | ||
import com.feakin.intellij.lexer.FeakinElementTypes.LBRACE | ||
import com.feakin.intellij.lexer.FeakinElementTypes.RBRACE | ||
import com.feakin.intellij.psi.FeakinContextBody | ||
import com.feakin.intellij.psi.FeakinContextMapBody | ||
import com.feakin.intellij.psi.FeakinVisitor | ||
import com.intellij.lang.ASTNode | ||
import com.intellij.lang.folding.FoldingBuilderEx | ||
import com.intellij.lang.folding.CustomFoldingBuilder | ||
import com.intellij.lang.folding.FoldingDescriptor | ||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.PsiComment | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.tree.TokenSet | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import java.util.* | ||
|
||
class FeakinFoldingBuilder : FoldingBuilderEx() { | ||
override fun getPlaceholderText(node: ASTNode): String { | ||
return "..." | ||
class FeakinFoldingBuilder : CustomFoldingBuilder(), DumbAware { | ||
|
||
override fun buildLanguageFoldRegions( | ||
descriptors: MutableList<FoldingDescriptor>, | ||
root: PsiElement, | ||
document: Document, | ||
quick: Boolean | ||
) { | ||
if (root !is FeakinFile) return | ||
|
||
val visitor = FoldingVisitor(descriptors) | ||
PsiTreeUtil.processElements(root) { it.accept(visitor); true } | ||
} | ||
|
||
override fun buildFoldRegions(element: PsiElement, document: Document, quick: Boolean): Array<FoldingDescriptor> { | ||
val descriptors: MutableList<FoldingDescriptor> = ArrayList() | ||
if (element !is FeakinFile) { | ||
return FoldingDescriptor.EMPTY | ||
override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange): String { | ||
when (node.elementType) { | ||
LBRACE -> return " { " | ||
RBRACE -> return " }" | ||
} | ||
val structs = PsiTreeUtil.getChildrenOfType(element, FeakinContextMapDeclaration::class.java) | ||
?: return descriptors.toTypedArray() | ||
for (struct in structs) { | ||
val structNameDeclaration = struct.contextMapName | ||
val nameEnd = structNameDeclaration.node.textRange.startOffset | ||
val structEnd = struct.node.textRange.endOffset | ||
val foldingDescriptor = FoldingDescriptor( | ||
Objects.requireNonNull(struct), | ||
TextRange(nameEnd, structEnd) | ||
) | ||
descriptors.add(foldingDescriptor) | ||
return when (node.psi) { | ||
is PsiComment -> "/* ... */" | ||
else -> "{...}" | ||
} | ||
return descriptors.toTypedArray() | ||
} | ||
|
||
override fun isCollapsedByDefault(node: ASTNode): Boolean { | ||
return true | ||
override fun isRegionCollapsedByDefault(node: ASTNode): Boolean { | ||
return node.elementType in COLLAPSED_BY_DEFAULT | ||
} | ||
|
||
private companion object { | ||
val COLLAPSED_BY_DEFAULT = TokenSet.create(LBRACE, RBRACE) | ||
} | ||
|
||
private class FoldingVisitor(private val descriptors: MutableList<FoldingDescriptor>) : FeakinVisitor() { | ||
override fun visitContextBody(o: FeakinContextBody) = fold(o) | ||
|
||
override fun visitContextMapBody(o: FeakinContextMapBody) = fold(o) | ||
private fun fold(element: PsiElement) { | ||
descriptors += FoldingDescriptor(element.node, element.textRange) | ||
} | ||
} | ||
} |
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
13 changes: 7 additions & 6 deletions
13
src/main/kotlin/com/feakin/intellij/highlight/FeakinTokenTypeSets.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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package com.feakin.intellij.highlight | ||
|
||
import com.feakin.intellij.lexer.FeakinTypes | ||
import com.feakin.intellij.lexer.FeakinElementTypes | ||
import com.intellij.psi.tree.TokenSet | ||
|
||
object FeakinTokenTypeSets { | ||
var KEY_WORDS = TokenSet.create( | ||
FeakinTypes.CONTEXT_KEYWORD, | ||
FeakinTypes.CONTEXT_MAP_KEYWORD, | ||
FeakinTypes.ENTITY_KEYWORD, | ||
FeakinTypes.AGGREGATION_KEYWORD, | ||
FeakinTypes.VALUE_OBJECT_KEYWORD, | ||
FeakinElementTypes.CONTEXT_KEYWORD, | ||
FeakinElementTypes.CONTEXT_MAP_KEYWORD, | ||
FeakinElementTypes.ENTITY_KEYWORD, | ||
FeakinElementTypes.AGGREGATION_KEYWORD, | ||
FeakinElementTypes.VALUE_OBJECT_KEYWORD, | ||
FeakinElementTypes.STRUCT_KEYWORD, | ||
) | ||
} |
5 changes: 2 additions & 3 deletions
5
src/main/kotlin/com/feakin/intellij/lexer/FeakinLexerAdapter.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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package com.feakin.intellij | ||
package com.feakin.intellij.lexer | ||
|
||
import com.feakin.intellij.lexer._FeakinLexer | ||
import com.intellij.lexer.FlexAdapter | ||
|
||
class FeakinLexerAdapter : FlexAdapter(_FeakinLexer(null)) | ||
class FeakinLexerAdapter : FlexAdapter(com.feakin.intellij.lexer._FeakinLexer(null)) |
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
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
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
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