Skip to content

Commit

Permalink
Merge pull request #3560 from Hannah-Sten/3547-go-to-definition-view
Browse files Browse the repository at this point in the history
#3547 go to definition view
  • Loading branch information
PHPirates committed May 25, 2024
2 parents d611cea + 94aae11 commit 11aeebd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.hannahsten.texifyidea.psi.impl

import com.intellij.extapi.psi.StubBasedPsiElementBase
import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiNameIdentifierOwner
Expand All @@ -14,6 +15,7 @@ import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexPsiHelper
import nl.hannahsten.texifyidea.psi.LatexVisitor
import nl.hannahsten.texifyidea.reference.CommandDefinitionReference
import nl.hannahsten.texifyidea.structure.latex.LatexPresentationFactory
import nl.hannahsten.texifyidea.util.labels.getLabelReferenceCommands
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.parser.*
Expand Down Expand Up @@ -117,6 +119,10 @@ abstract class LatexCommandsImplMixin : StubBasedPsiElementBase<LatexCommandsStu
return this.references.firstOrNull()
}

override fun getPresentation(): ItemPresentation? {
return LatexPresentationFactory.getPresentation(this)
}

override fun getOptionalParameterMap() = getOptionalParameterMapFromParameters(this.parameterList)

override fun getRequiredParameters() = getRequiredParameters(this.parameterList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class LatexNewCommandPresentation(newCommand: LatexCommands) : ItemPresentation

// Get the definition to show in place of the location string.
locationString = when {
newCommand.commandToken.text == "\\" + LatexNewDefinitionCommand.NEWCOMMAND.command && required.size >= 2 -> required[1]
newCommand.commandToken.text == "\\" + LatexXparseCommand.NEWDOCUMENTCOMMAND.command && required.size >= 3 -> required[2]
newCommand.name == LatexNewDefinitionCommand.NEWCOMMAND.commandWithSlash && required.size >= 2 -> required[1]
newCommand.name == LatexNewDefinitionCommand.RENEWCOMMAND.commandWithSlash && required.size >= 2 -> required[1]
newCommand.name == LatexXparseCommand.NEWDOCUMENTCOMMAND.commandWithSlash && required.size >= 3 -> required[2]
else -> ""
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@ package nl.hannahsten.texifyidea.structure.latex

import com.intellij.navigation.ItemPresentation
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.util.parser.nextCommand
import nl.hannahsten.texifyidea.util.parser.lineNumber
import javax.swing.Icon

/**
* @author Hannah Schellekens
*/
class LatexOtherCommandPresentation(command: LatexCommands, private val icon: Icon) : ItemPresentation {
class LatexOtherCommandPresentation(val command: LatexCommands, private val icon: Icon) : ItemPresentation {

private val commandName = command.name
private var locationString: String
override fun getPresentableText() = command.name

init {
val firstNext = command.nextCommand()
if (firstNext != null) {
val lookup = firstNext.commandToken.text
this.locationString = lookup ?: ""
}

locationString = ""
}

override fun getPresentableText() = commandName

override fun getLocationString() = locationString
override fun getLocationString() = command.containingFile.name + ":" + command.lineNumber().toString()

override fun getIcon(b: Boolean) = icon
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import nl.hannahsten.texifyidea.TexifyIcons
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand.*
import nl.hannahsten.texifyidea.lang.commands.LatexMathtoolsRegularCommand.*
import nl.hannahsten.texifyidea.lang.commands.LatexNewDefinitionCommand.NEWCOMMAND
import nl.hannahsten.texifyidea.lang.commands.LatexNewDefinitionCommand.RENEWCOMMAND
import nl.hannahsten.texifyidea.lang.commands.LatexXparseCommand
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.util.getIncludeCommands
Expand All @@ -30,7 +31,7 @@ object LatexPresentationFactory {
SUBSUBSECTION.cmd -> LatexSubSubSectionPresentation(commands)
PARAGRAPH.cmd -> LatexParagraphPresentation(commands)
SUBPARAGRAPH.cmd -> LatexSubParagraphPresentation(commands)
NEWCOMMAND.cmd, DECLARE_MATH_OPERATOR.cmd, LatexXparseCommand.NEWDOCUMENTCOMMAND.cmd -> LatexNewCommandPresentation(commands)
NEWCOMMAND.cmd, RENEWCOMMAND.cmd, DECLARE_MATH_OPERATOR.cmd, LatexXparseCommand.NEWDOCUMENTCOMMAND.cmd -> LatexNewCommandPresentation(commands)
DECLARE_PAIRED_DELIMITER.cmd, DECLARE_PAIRED_DELIMITER_X.cmd, DECLARE_PAIRED_DELIMITER_XPP.cmd -> LatexPairedDelimiterPresentation(
commands
)
Expand Down
3 changes: 3 additions & 0 deletions src/nl/hannahsten/texifyidea/util/parser/Psi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import nl.hannahsten.texifyidea.lang.DefaultEnvironment
import nl.hannahsten.texifyidea.lang.Environment
import nl.hannahsten.texifyidea.lang.magic.TextBasedMagicCommentParser
import nl.hannahsten.texifyidea.psi.*
import nl.hannahsten.texifyidea.util.files.document
import nl.hannahsten.texifyidea.util.magic.EnvironmentMagic
import kotlin.reflect.KClass

Expand All @@ -25,6 +26,8 @@ import kotlin.reflect.KClass
*/
fun PsiElement.endOffset(): Int = textOffset + textLength

fun PsiElement.lineNumber(): Int? = containingFile.document()?.getLineNumber(textOffset)

/**
* @see [PsiTreeUtil.getChildrenOfType]
*/
Expand Down

0 comments on commit 11aeebd

Please sign in to comment.