Skip to content

Commit

Permalink
Move generated files to main/gen
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jul 4, 2024
1 parent 1fa6002 commit ec4b804
Show file tree
Hide file tree
Showing 135 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/modules/vyper-plugin.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/modules/vyper-plugin.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/vyper-plugin.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To generate the files, you should have the plugin installed.
- Run the `Generate Parser Code` task in the `Vyper.bnf` file.
That generates `VyperParser.java` and `psi` files.
- When grammar elements are removed, old `psi` files are not deleted automatically.
Just delete the whole [`psi` folder](./org/vyperlang/plugin/psi) and regenerate it.
Just delete the whole [`psi` folder](./src/main/gen/org/vyperlang/plugin/psi) and regenerate it.
- Run the `Generate JFlex Lexer` task in the `Vyper.bnf` file.
That generates `_VyperLexer.flex` file.
- Run the `Run JFlex Generator` task in the `_VyperLexer.flex` file.
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ compileJava {
targetCompatibility = JavaVersion.VERSION_17
}

// Include the generated files in the source set
sourceSets.main.java.srcDirs 'src/main/gen'

// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
kover {
reports {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/vyperlang/plugin/Highligther.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class VyperHighlighter : SyntaxHighlighterBase() {
)

private fun modificators() = setOf<IElementType>(
PUBLIC, NONREENTRANT, EXTERNAL, INTERNAL, VIEW, PURE, IMMUTABLE, CONSTANT,
PUBLIC, NONREENTRANT, EXTERNAL, INTERNAL, IMMUTABLE, CONSTANT,
// todo: the following are (also) for interfaces
PAYABLE, NONPAYABLE, VIEW, PURE,
)
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/org/vyperlang/plugin/psi/Mixins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ package org.vyperlang.plugin.psi
import com.intellij.lang.ASTNode
import com.intellij.openapi.util.IconLoader
import com.intellij.psi.PsiElement
import com.intellij.psi.util.childrenOfType
import com.intellij.psi.util.parentOfType
import org.mozilla.javascript.ast.FunctionCall
import org.vyperlang.plugin.psi.VyperTypes.*
import org.vyperlang.plugin.psi.impl.VyperCallExpressionImpl
import org.vyperlang.plugin.references.VyperCallReference
Expand All @@ -18,7 +21,17 @@ abstract class VyperVarLiteralMixin(node: ASTNode) : VyperNamedElementImpl(node)
override fun getReference(): VyperReference {
val parent = node.psi.parent
val grandparent = parent.parent
val greatGrandparent = grandparent.parent
return when {
greatGrandparent is VyperFunctionCallArgument && parent.firstChild == node.psi -> {
val structName = greatGrandparent.parentOfType<VyperCallExpression>()?.childOfType<VyperVarLiteral>()?.text
val structPsi =
node.psi.file.childrenOfType<VyperStructDefinition>()
.first { it.localVariableDefinition?.identifier?.text == structName }
?.childOfType<VyperIdentifier>()
.first { it.text == this.text }
VyperVarLiteralReference(structPsi)
}
grandparent is VyperCallExpressionImpl && parent is VyperMemberAccessExpression ->
VyperMemberAccessReference(this, parent)
parent is VyperMemberAccessExpression && parent.varLiteral == node.psi ->
Expand Down
11 changes: 3 additions & 8 deletions src/main/kotlin/org/vyperlang/plugin/references/Resolver.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.vyperlang.plugin.references

import com.intellij.psi.PsiElement
import com.intellij.psi.util.childrenOfType
import com.intellij.psi.util.isAncestor
import net.sf.cglib.core.Local
import org.vyperlang.plugin.psi.*
import org.vyperlang.plugin.psi.VyperTypes.VAR_LITERAL

Expand All @@ -26,16 +24,13 @@ object VyperResolver {
// return newList
// }

private fun lexicalDeclRec(place: PsiElement, stop: (PsiElement) -> Boolean): List<VyperNamedElement> {
val found = place.ancestors
private fun lexicalDeclRec(place: PsiElement, stop: (PsiElement) -> Boolean): List<VyperNamedElement> =
place.ancestors
.drop(1) // current element might not be a VyperElement
.takeWhile { (it is VyperElement || it is VyperFile) && !stop(it) }
.flatMap { lexicalDeclarations(it, place) }
.filter { !it.isAncestor(place) } // don't suggest the element being defined
.toList()
val filtered = found
.filter { !it.isAncestor(place) } // don't suggest the element being defined
return filtered
}

private fun lexicalDeclarations(scope: PsiElement, place: PsiElement): List<VyperNamedElement> = when (scope) {
is VyperLocalVariableDefinition -> listOf(scope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,14 @@ class VyperCallReference(element: VyperCallElement) : VyperReferenceBase<VyperCa
return resolveFunctionCall().map { it.psiElement }
}
}

class VyperStructMemberReference(element: VyperCallElement) : VyperReferenceBase<VyperCallElement>(element), VyperReference {

private fun resolveFunctionCall(): Collection<FunctionResolveResult> {
return VyperResolver.resolveFunction(element)
}

override fun multiResolve(): Collection<PsiElement> {
return resolveFunctionCall().map { it.psiElement }
}
}

0 comments on commit ec4b804

Please sign in to comment.