Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions server/src/e2e/tolk/testcases/completion/methods.test
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,31 @@ fun main() {
13 as
1 add(self)
1 add2(self)

========================================================================
T? instance method on T
========================================================================
struct Data {
data: Cell<int32>?
}

fun main() {
val data: Data;

if (data.data == null) {
return;
}

data.data.<caret>;
}
------------------------------------------------------------------------
9 tvmCell: cell of Cell
1 beginParse(self): slice
1 calculateSize(self, maxCells: int): (int, int, int, bool)
1 calculateSizeStrict(self, maxCells: int): (int, int, int)
1 depth(self): int
1 forceLoadLazyObject(self): slice
1 hash(self): uint256
1 load(self, options: UnpackOptions = {}): T
1 stackMoveToTop(mutate self): void
1 toCell(self, options: PackOptions = {}): Cell<T>
36 changes: 27 additions & 9 deletions server/src/languages/tolk/psi/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
Ty,
FieldsOwnerTy,
InstantiationTy,
BuiltinTy,
UnionTy,
NullTy,
} from "@server/languages/tolk/types/ty"
import {TypeInferer} from "@server/languages/tolk/TypeInferer"
import {parentOfType} from "@server/psi/utils"
Expand Down Expand Up @@ -363,19 +366,19 @@ export class Reference {
// first process instantiation methods
if (!this.processTypeMethods(qualifierType, proc, state)) return false

// and then underlying type
const innerTy = qualifierType.unwrapInstantiation()

if (innerTy.name() === "Cell") {
const callTy = new BuiltinTy("cell", null)
const nullableCellTy = new UnionTy([callTy, NullTy.NULL])
if (!this.processType(qualifier, callTy, proc, state)) return false
if (!this.processType(qualifier, nullableCellTy, proc, state)) return false
}

// and then underlying type
return this.processType(qualifier, innerTy, proc, state)
}

// if (qualifierType instanceof OptionTy) {
// // first process type alias methods
// if (!this.processTypeMethods(qualifierType, proc, state)) return false
//
// // and then underlying type
// return this.processType(qualifier, qualifierType.innerTy, proc, state)
// }

return this.processTypeMethods(qualifierType, proc, state)
}

Expand Down Expand Up @@ -422,6 +425,21 @@ export class Reference {
}
}

if (receiver?.type === "nullable_type") {
const inner = receiver.childForFieldName("inner")
if (expected instanceof UnionTy) {
const asNullable = expected.asNullable()
if (asNullable !== undefined) {
return this.typeMatches(
file,
asNullable[0],
asNullable[0].name(),
inner,
)
}
}
}

return false
}
})(),
Expand Down
Loading