Skip to content

Commit ed130d0

Browse files
authored
2.2.1 (#175)
* fix * fix #173
1 parent 24ed2f5 commit ed130d0

10 files changed

+202
-49
lines changed

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.gradle.configurationcache.extensions.capitalized
2+
import org.jetbrains.changelog.Changelog
23
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
34
import org.jetbrains.grammarkit.tasks.GenerateParserTask
45
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -113,9 +114,9 @@ tasks {
113114
sinceBuild.set("231")
114115
untilBuild.set("")
115116
changeNotes.set(provider {
116-
changelog.run {
117+
changelog.renderItem(changelog.run {
117118
getLatest()
118-
}.toHTML()
119+
}, Changelog.OutputType.HTML)
119120
})
120121
}
121122
buildSearchableOptions {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.gradle.jvmargs=-Xmx4096m
22
pluginGroup=org.ton
3-
pluginVersion=2.2.0
3+
pluginVersion=2.2.1
44
publishChannel=release
55
publishToken=token
66
enableBuildSearchableOptions=false

src/main/kotlin/org/ton/intellij/tact/ide/completion/TactDotCompletionProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TactDotCompletionProvider : TactCompletionProvider() {
6161
if (function != null) {
6262
result.addElement(
6363
LookupElementBuilder.createWithIcon(function)
64-
.withTypeText(function.selfType?.toString() ?: "")
64+
.withTypeText(function.type?.ty?.toString() ?: "")
6565
.withInsertHandler { context, item ->
6666
context.editor.document.insertString(context.editor.caretModel.offset, "()")
6767
context.editor.caretModel.moveToOffset(context.editor.caretModel.offset + 2)

src/main/kotlin/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.ton.intellij.tact.psi.TactReferenceExpression
1010
import org.ton.intellij.tact.psi.impl.isGet
1111
import org.ton.intellij.tact.stub.index.TactFunctionIndex
1212
import org.ton.intellij.tact.type.TactLookup
13+
import org.ton.intellij.tact.type.ty
1314
import org.ton.intellij.util.ancestorStrict
1415
import org.ton.intellij.util.processAllKeys
1516

@@ -34,8 +35,12 @@ class TactReferenceCompletionProvider : TactCompletionProvider() {
3435
TactFunctionIndex.findElementsByName(project, key).asSequence()
3536
.filter { !it.isGet }
3637
.distinctBy { it.name }
37-
.forEach {
38-
result.addElement(LookupElementBuilder.createWithIcon(it))
38+
.forEach { function ->
39+
result.addElement(
40+
LookupElementBuilder
41+
.createWithIcon(function)
42+
.withTypeText(function.type?.ty?.toString() ?: "")
43+
)
3944
}
4045
true
4146
}

src/main/kotlin/org/ton/intellij/tact/inspections/TactUnresolvedReferenceInspection.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import org.ton.intellij.tact.psi.TactVisitor
1111
class TactUnresolvedReferenceInspection : TactLocalInspectionTool() {
1212
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : TactVisitor() {
1313
override fun visitReferenceExpression(o: TactReferenceExpression) {
14-
val reference = o.reference ?: return holder.registerProblem(o)
14+
val reference = o.reference ?: return
1515
reference.resolve() ?: return holder.registerProblem(o)
1616
}
1717

1818
override fun visitCallExpression(o: TactCallExpression) {
19-
val reference = o.reference ?: return holder.registerProblem(o)
19+
val reference = o.reference ?: return
2020
reference.resolve() ?: return holder.registerProblem(o)
2121
}
2222
}

src/main/kotlin/org/ton/intellij/tact/psi/impl/TactCallExpressionImplMixin.kt

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,66 @@ package org.ton.intellij.tact.psi.impl
33
import com.intellij.extapi.psi.ASTWrapperPsiElement
44
import com.intellij.lang.ASTNode
55
import com.intellij.psi.PsiReference
6-
import org.ton.intellij.tact.psi.TactCallExpression
6+
import org.ton.intellij.tact.psi.*
77
import org.ton.intellij.tact.resolve.TactFieldReference
8+
import org.ton.intellij.tact.type.TactTyMap
9+
import org.ton.intellij.tact.type.TactTyRef
10+
import org.ton.intellij.tact.type.selfInferenceResult
11+
import org.ton.intellij.util.ancestorStrict
812

913
abstract class TactCallExpressionImplMixin(node: ASTNode) : ASTWrapperPsiElement(node), TactCallExpression {
10-
override fun getReference(): PsiReference {
11-
return TactFieldReference(this, identifier.textRangeInParent)
14+
override fun getReference(): PsiReference? {
15+
val identifier = identifier
16+
val ref = TactFieldReference(this, identifier.textRangeInParent)
17+
when (identifier.text) {
18+
"ton",
19+
"pow",
20+
"require",
21+
"address",
22+
"cell",
23+
"dump",
24+
"emptyMap",
25+
"sha256" -> {
26+
if (isStaticCall()) {
27+
return null
28+
}
29+
}
30+
31+
"get",
32+
"set",
33+
"asCell" -> {
34+
val parent = parent
35+
if (parent is TactDotExpression) {
36+
val leftTy = parent.expressionList.firstOrNull()?.let { left ->
37+
parent.ancestorStrict<TactInferenceContextOwner>()?.selfInferenceResult?.getExprTy(left)
38+
}
39+
if (leftTy is TactTyMap) {
40+
return null
41+
}
42+
}
43+
}
44+
45+
"toCell" -> {
46+
val parent = parent
47+
if (parent is TactDotExpression) {
48+
val leftTy = parent.expressionList.firstOrNull()?.let { left ->
49+
parent.ancestorStrict<TactInferenceContextOwner>()?.selfInferenceResult?.getExprTy(left)
50+
}
51+
if (leftTy is TactTyRef && (leftTy.item is TactStruct || leftTy.item is TactMessage)) {
52+
return null
53+
}
54+
}
55+
}
56+
}
57+
return ref
58+
}
59+
}
60+
61+
fun TactCallExpression.isStaticCall(): Boolean {
62+
val parent = parent
63+
return if (parent is TactDotExpression) {
64+
parent.expressionList.firstOrNull() == this
65+
} else {
66+
true
1267
}
1368
}

src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReferencedTypeImplMixin.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package org.ton.intellij.tact.psi.impl
22

33
import com.intellij.lang.ASTNode
44
import com.intellij.psi.PsiReference
5+
import org.ton.intellij.tact.psi.TactMapType
56
import org.ton.intellij.tact.psi.TactReferencedType
67
import org.ton.intellij.tact.psi.TactType
78
import org.ton.intellij.tact.psi.TactTypeDeclarationElement
89
import org.ton.intellij.tact.resolve.TactTypeReference
910
import org.ton.intellij.tact.type.TactTy
11+
import org.ton.intellij.tact.type.TactTyMap
1012
import org.ton.intellij.tact.type.TactTyNullable
13+
import org.ton.intellij.tact.type.TactTyUnknown
1114

1215
abstract class TactReferencedTypeImplMixin(
1316
node: ASTNode
@@ -16,10 +19,18 @@ abstract class TactReferencedTypeImplMixin(
1619
}
1720

1821
val TactType.ty: TactTy?
19-
get() {
20-
val reference = reference ?: return null
21-
val typeDeclaration = reference.resolve() as? TactTypeDeclarationElement ?: return null
22-
val declaredTy = typeDeclaration.declaredTy
23-
if (this is TactReferencedType && q != null) return TactTyNullable(declaredTy)
24-
return declaredTy
22+
get() = getType(this)
23+
24+
private fun getType(tactType: TactType): TactTy? {
25+
if (tactType is TactMapType) {
26+
val mapTypeItemList = tactType.mapTypeItemList
27+
val keyType = mapTypeItemList.getOrNull(0)?.referencedType?.ty ?: TactTyUnknown
28+
val valueType = mapTypeItemList.getOrNull(1)?.referencedType?.ty ?: TactTyUnknown
29+
return TactTyMap(keyType, valueType)
2530
}
31+
val reference = tactType.reference ?: return null
32+
val typeDeclaration = reference.resolve() as? TactTypeDeclarationElement ?: return null
33+
val declaredTy = typeDeclaration.declaredTy
34+
if (tactType is TactReferencedType && tactType.q != null) return TactTyNullable(declaredTy)
35+
return declaredTy
36+
}

src/main/kotlin/org/ton/intellij/tact/resolve/TactTypeReference.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ class TactTypeReference<T : TactElement>(element: T, range: TextRange) : TactRef
1111
override fun multiResolve(): Collection<TactTypeDeclarationElement> {
1212
val currentFile = element.containingFile
1313
val result = TactTypesIndex.findElementsByName(element.project, value)
14-
val localType = result.asSequence()
15-
.filterIsInstance<TactTypeDeclarationElement>()
16-
.find { it.containingFile == currentFile }
14+
val localType = result.find { it.containingFile == currentFile }
1715
if (localType != null) {
1816
return listOf(localType)
1917
}
20-
return listOf(result.firstOrNull() as? TactTypeDeclarationElement ?: return emptyList())
18+
return listOf(result.firstOrNull() ?: return emptyList())
2119
}
2220
}

src/main/kotlin/org/ton/intellij/tact/type/TactTy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ data class TactTyMap(
6969
override fun toString(): String = "map<$key, $value>"
7070

7171
override fun isAssignable(other: TactTy): Boolean {
72-
return other is TactTyMap && key.isAssignable(other.key) && value.isAssignable(other.value)
72+
return other is TactTyNull || (other is TactTyMap && key.isAssignable(other.key) && value.isAssignable(other.value))
7373
}
7474
}
7575

0 commit comments

Comments
 (0)