-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
idea: significant enhancements to ide experience
- Loading branch information
Showing
46 changed files
with
450 additions
and
131 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
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
23 changes: 23 additions & 0 deletions
23
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkElementManipulator.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,23 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.AbstractElementManipulator | ||
import com.intellij.psi.PsiFileFactory | ||
import com.intellij.psi.impl.PsiFileFactoryImpl | ||
import com.intellij.psi.util.elementType | ||
import gay.pizza.pork.idea.psi.gen.PorkElement | ||
|
||
class PorkElementManipulator : AbstractElementManipulator<PorkElement>() { | ||
override fun handleContentChange(element: PorkElement, range: TextRange, newContent: String): PorkElement? { | ||
val sourceText = element.text | ||
val beforeText = sourceText.substring(0, range.startOffset) | ||
val afterText = sourceText.substring(range.endOffset) | ||
val changedText = beforeText + newContent + afterText | ||
return element.replace(produce(element, changedText)) as PorkElement? | ||
} | ||
|
||
fun produce(element: PorkElement, changed: String): PorkElement { | ||
val factory = PsiFileFactory.getInstance(element.project) as PsiFileFactoryImpl | ||
return factory.createElementFromText(changed, PorkLanguage, element.elementType!!, element.context) as PorkElement | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkFunctionSymbol.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkNodeKey.kt
This file was deleted.
Oops, something went wrong.
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
27 changes: 0 additions & 27 deletions
27
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkSymbolDeclaration.kt
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkSymbolDeclarationProvider.kt
This file was deleted.
Oops, something went wrong.
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
59 changes: 51 additions & 8 deletions
59
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/psi/PorkElementHelpers.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,31 +1,74 @@ | ||
package gay.pizza.pork.idea.psi | ||
|
||
import com.intellij.lang.ASTNode | ||
import com.intellij.navigation.ItemPresentation | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFileFactory | ||
import com.intellij.psi.PsiReference | ||
import com.intellij.psi.impl.PsiFileFactoryImpl | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import com.intellij.psi.util.childrenOfType | ||
import com.intellij.util.PlatformIcons | ||
import gay.pizza.pork.ast.NodeType | ||
import gay.pizza.pork.idea.PorkElementTypes | ||
import gay.pizza.pork.idea.psi.gen.PorkElement | ||
import gay.pizza.pork.idea.psi.gen.PorkNamedElement | ||
import gay.pizza.pork.idea.psi.gen.SymbolElement | ||
import gay.pizza.pork.idea.PorkLanguage | ||
import gay.pizza.pork.idea.psi.gen.* | ||
import javax.swing.Icon | ||
|
||
object PorkElementHelpers { | ||
private val symbolElementType = PorkElementTypes.elementTypeFor(NodeType.Symbol) | ||
|
||
fun nameOfNamedElement(element: PorkNamedElement): String? { | ||
val child = element.node.findChildByType(symbolElementType) | ||
return child?.text | ||
val child = symbolOf(element) ?: return null | ||
return child.text | ||
} | ||
|
||
fun setNameOfNamedElement(element: PorkNamedElement, name: String): PsiElement = element | ||
fun setNameOfNamedElement(element: PorkNamedElement, name: String): PsiElement { | ||
val child = symbolOf(element) ?: return element | ||
val factory = PsiFileFactory.getInstance(element.project) as PsiFileFactoryImpl | ||
val created = factory.createElementFromText(name, PorkLanguage, child.elementType, element.context) as PorkElement | ||
element.node.replaceChild(child, created.node) | ||
return element | ||
} | ||
|
||
fun symbolOf(element: PorkElement): ASTNode? { | ||
var child = element.node.findChildByType(symbolElementType) | ||
if (child == null) { | ||
child = PsiTreeUtil.collectElementsOfType(element, SymbolElement::class.java).firstOrNull()?.node | ||
} | ||
return child | ||
} | ||
|
||
fun nameIdentifierOfNamedElement(element: PorkNamedElement): PsiElement? { | ||
val child = element.node.findChildByType(symbolElementType) | ||
return child?.psi | ||
return symbolOf(element)?.psi | ||
} | ||
|
||
fun referenceOfElement(element: PorkElement, type: NodeType): PsiReference? { | ||
val textRangeOfSymbolInElement = element.childrenOfType<SymbolElement>().firstOrNull()?.textRangeInParent ?: return null | ||
return PorkIdentifierReference(element, textRangeOfSymbolInElement) | ||
} | ||
|
||
fun iconOf(element: PorkElement): Icon? { | ||
return when (element) { | ||
is LetDefinitionElement -> PlatformIcons.FIELD_ICON | ||
is FunctionDefinitionElement -> PlatformIcons.FUNCTION_ICON | ||
is LetAssignmentElement -> PlatformIcons.VARIABLE_READ_ACCESS | ||
is VarAssignmentElement -> PlatformIcons.VARIABLE_RW_ACCESS | ||
is ArgumentSpecElement -> PlatformIcons.VARIABLE_READ_ACCESS | ||
else -> null | ||
} | ||
} | ||
|
||
fun presentationOf(element: PorkElement): ItemPresentation? { | ||
val icon = iconOf(element) | ||
if (element is FunctionDefinitionElement || element is LetDefinitionElement) { | ||
return PorkPresentable(element.name, icon, element.containingFile.virtualFile?.name) | ||
} | ||
|
||
if (element is LetAssignmentElement || element is VarAssignmentElement) { | ||
return PorkPresentable(element.name, icon) | ||
} | ||
|
||
return 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
10 changes: 10 additions & 0 deletions
10
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/psi/PorkPresentable.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,10 @@ | ||
package gay.pizza.pork.idea.psi | ||
|
||
import com.intellij.navigation.ItemPresentation | ||
import javax.swing.Icon | ||
|
||
class PorkPresentable(val porkText: String?, val porkIcon: Icon? = null, val porkLocation: String? = null) : ItemPresentation { | ||
override fun getPresentableText(): String? = porkText | ||
override fun getIcon(unused: Boolean): Icon? = porkIcon | ||
override fun getLocationString(): String? = porkLocation | ||
} |
Oops, something went wrong.