Skip to content

Commit

Permalink
2.2.1 (#175)
Browse files Browse the repository at this point in the history
* fix

* fix #173
  • Loading branch information
andreypfau authored May 1, 2024
1 parent 24ed2f5 commit ed130d0
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 49 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.changelog.Changelog
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
import org.jetbrains.grammarkit.tasks.GenerateParserTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand Down Expand Up @@ -113,9 +114,9 @@ tasks {
sinceBuild.set("231")
untilBuild.set("")
changeNotes.set(provider {
changelog.run {
changelog.renderItem(changelog.run {
getLatest()
}.toHTML()
}, Changelog.OutputType.HTML)
})
}
buildSearchableOptions {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx4096m
pluginGroup=org.ton
pluginVersion=2.2.0
pluginVersion=2.2.1
publishChannel=release
publishToken=token
enableBuildSearchableOptions=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TactDotCompletionProvider : TactCompletionProvider() {
if (function != null) {
result.addElement(
LookupElementBuilder.createWithIcon(function)
.withTypeText(function.selfType?.toString() ?: "")
.withTypeText(function.type?.ty?.toString() ?: "")
.withInsertHandler { context, item ->
context.editor.document.insertString(context.editor.caretModel.offset, "()")
context.editor.caretModel.moveToOffset(context.editor.caretModel.offset + 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.ton.intellij.tact.psi.TactReferenceExpression
import org.ton.intellij.tact.psi.impl.isGet
import org.ton.intellij.tact.stub.index.TactFunctionIndex
import org.ton.intellij.tact.type.TactLookup
import org.ton.intellij.tact.type.ty
import org.ton.intellij.util.ancestorStrict
import org.ton.intellij.util.processAllKeys

Expand All @@ -34,8 +35,12 @@ class TactReferenceCompletionProvider : TactCompletionProvider() {
TactFunctionIndex.findElementsByName(project, key).asSequence()
.filter { !it.isGet }
.distinctBy { it.name }
.forEach {
result.addElement(LookupElementBuilder.createWithIcon(it))
.forEach { function ->
result.addElement(
LookupElementBuilder
.createWithIcon(function)
.withTypeText(function.type?.ty?.toString() ?: "")
)
}
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import org.ton.intellij.tact.psi.TactVisitor
class TactUnresolvedReferenceInspection : TactLocalInspectionTool() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : TactVisitor() {
override fun visitReferenceExpression(o: TactReferenceExpression) {
val reference = o.reference ?: return holder.registerProblem(o)
val reference = o.reference ?: return
reference.resolve() ?: return holder.registerProblem(o)
}

override fun visitCallExpression(o: TactCallExpression) {
val reference = o.reference ?: return holder.registerProblem(o)
val reference = o.reference ?: return
reference.resolve() ?: return holder.registerProblem(o)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,66 @@ package org.ton.intellij.tact.psi.impl
import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiReference
import org.ton.intellij.tact.psi.TactCallExpression
import org.ton.intellij.tact.psi.*
import org.ton.intellij.tact.resolve.TactFieldReference
import org.ton.intellij.tact.type.TactTyMap
import org.ton.intellij.tact.type.TactTyRef
import org.ton.intellij.tact.type.selfInferenceResult
import org.ton.intellij.util.ancestorStrict

abstract class TactCallExpressionImplMixin(node: ASTNode) : ASTWrapperPsiElement(node), TactCallExpression {
override fun getReference(): PsiReference {
return TactFieldReference(this, identifier.textRangeInParent)
override fun getReference(): PsiReference? {
val identifier = identifier
val ref = TactFieldReference(this, identifier.textRangeInParent)
when (identifier.text) {
"ton",
"pow",
"require",
"address",
"cell",
"dump",
"emptyMap",
"sha256" -> {
if (isStaticCall()) {
return null
}
}

"get",
"set",
"asCell" -> {
val parent = parent
if (parent is TactDotExpression) {
val leftTy = parent.expressionList.firstOrNull()?.let { left ->
parent.ancestorStrict<TactInferenceContextOwner>()?.selfInferenceResult?.getExprTy(left)
}
if (leftTy is TactTyMap) {
return null
}
}
}

"toCell" -> {
val parent = parent
if (parent is TactDotExpression) {
val leftTy = parent.expressionList.firstOrNull()?.let { left ->
parent.ancestorStrict<TactInferenceContextOwner>()?.selfInferenceResult?.getExprTy(left)
}
if (leftTy is TactTyRef && (leftTy.item is TactStruct || leftTy.item is TactMessage)) {
return null
}
}
}
}
return ref
}
}

fun TactCallExpression.isStaticCall(): Boolean {
val parent = parent
return if (parent is TactDotExpression) {
parent.expressionList.firstOrNull() == this
} else {
true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package org.ton.intellij.tact.psi.impl

import com.intellij.lang.ASTNode
import com.intellij.psi.PsiReference
import org.ton.intellij.tact.psi.TactMapType
import org.ton.intellij.tact.psi.TactReferencedType
import org.ton.intellij.tact.psi.TactType
import org.ton.intellij.tact.psi.TactTypeDeclarationElement
import org.ton.intellij.tact.resolve.TactTypeReference
import org.ton.intellij.tact.type.TactTy
import org.ton.intellij.tact.type.TactTyMap
import org.ton.intellij.tact.type.TactTyNullable
import org.ton.intellij.tact.type.TactTyUnknown

abstract class TactReferencedTypeImplMixin(
node: ASTNode
Expand All @@ -16,10 +19,18 @@ abstract class TactReferencedTypeImplMixin(
}

val TactType.ty: TactTy?
get() {
val reference = reference ?: return null
val typeDeclaration = reference.resolve() as? TactTypeDeclarationElement ?: return null
val declaredTy = typeDeclaration.declaredTy
if (this is TactReferencedType && q != null) return TactTyNullable(declaredTy)
return declaredTy
get() = getType(this)

private fun getType(tactType: TactType): TactTy? {
if (tactType is TactMapType) {
val mapTypeItemList = tactType.mapTypeItemList
val keyType = mapTypeItemList.getOrNull(0)?.referencedType?.ty ?: TactTyUnknown
val valueType = mapTypeItemList.getOrNull(1)?.referencedType?.ty ?: TactTyUnknown
return TactTyMap(keyType, valueType)
}
val reference = tactType.reference ?: return null
val typeDeclaration = reference.resolve() as? TactTypeDeclarationElement ?: return null
val declaredTy = typeDeclaration.declaredTy
if (tactType is TactReferencedType && tactType.q != null) return TactTyNullable(declaredTy)
return declaredTy
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ class TactTypeReference<T : TactElement>(element: T, range: TextRange) : TactRef
override fun multiResolve(): Collection<TactTypeDeclarationElement> {
val currentFile = element.containingFile
val result = TactTypesIndex.findElementsByName(element.project, value)
val localType = result.asSequence()
.filterIsInstance<TactTypeDeclarationElement>()
.find { it.containingFile == currentFile }
val localType = result.find { it.containingFile == currentFile }
if (localType != null) {
return listOf(localType)
}
return listOf(result.firstOrNull() as? TactTypeDeclarationElement ?: return emptyList())
return listOf(result.firstOrNull() ?: return emptyList())
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/org/ton/intellij/tact/type/TactTy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ data class TactTyMap(
override fun toString(): String = "map<$key, $value>"

override fun isAssignable(other: TactTy): Boolean {
return other is TactTyMap && key.isAssignable(other.key) && value.isAssignable(other.value)
return other is TactTyNull || (other is TactTyMap && key.isAssignable(other.key) && value.isAssignable(other.value))
}
}

Expand Down
Loading

0 comments on commit ed130d0

Please sign in to comment.