Skip to content

Commit 0d9dd5e

Browse files
authored
feat(documentation/inlay-hints): show type for struct, messages and toCell() calls (#318)
Fixes #180 Fixes #167
1 parent 062c577 commit 0d9dd5e

File tree

14 files changed

+579
-17
lines changed

14 files changed

+579
-17
lines changed

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,15 @@
235235
"default": true,
236236
"description": "Show method ID hints for contract functions"
237237
},
238-
"tact.hints.showExplicitTLBIntType": {
238+
"tact.hints.showExplicitTLbIntType": {
239239
"type": "boolean",
240240
"default": true,
241241
"description": "Show explicit TL-B type hints (as int257) for Int fields"
242+
},
243+
"tact.hints.showToCellSize": {
244+
"type": "boolean",
245+
"default": true,
246+
"description": "Show size in bits for `toCell()` calls"
242247
}
243248
}
244249
},

server/src/completion/CompletionContext.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class CompletionContext {
263263
if (!type) return false
264264

265265
if (this.contextTy instanceof OptionTy && type instanceof OptionTy) {
266-
return this.contextTy.innerTy.name() === type.innerTy.name()
266+
return this.contextTy.innerTy.qualifiedName() === type.innerTy.qualifiedName()
267267
}
268268

269269
if (this.contextTy instanceof MapTy && type instanceof MapTy) {
@@ -276,15 +276,15 @@ export class CompletionContext {
276276

277277
if (type instanceof OptionTy) {
278278
// Int and Int?
279-
return type.innerTy.name() === this.contextTy.name()
279+
return type.innerTy.qualifiedName() === this.contextTy.qualifiedName()
280280
}
281281

282282
if (this.contextTy instanceof OptionTy) {
283283
// Int? and Int
284-
return this.contextTy.innerTy.name() === type.name()
284+
return this.contextTy.innerTy.qualifiedName() === type.qualifiedName()
285285
}
286286

287-
return this.contextTy.name() === type.name()
287+
return this.contextTy.qualifiedName() === type.qualifiedName()
288288
}
289289

290290
public expression(): boolean {

server/src/documentation/documentation.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {getDocumentSettings, TactSettings} from "@server/utils/settings"
1818
import {File} from "@server/psi/File"
1919
import {Position} from "vscode-languageclient"
2020
import {asLspPosition} from "@server/utils/position"
21+
import {FieldsOwnerTy, sizeOfPresentation} from "@server/types/BaseTy"
2122

2223
const CODE_FENCE = "```"
2324
const DOC_TMPL = `${CODE_FENCE}tact\n{signature}\n${CODE_FENCE}\n{documentation}\n`
@@ -148,14 +149,16 @@ export async function generateDocFor(node: NamedNode, place: SyntaxNode): Promis
148149
const doc = extractCommentsDoc(node)
149150
const struct = new Struct(node.node, node.file)
150151
const body = struct.body()?.text ?? ""
151-
return defaultResult(`struct ${node.name()} ${body}`, doc)
152+
const sizeDoc = documentationSizeOf(struct)
153+
return defaultResult(`struct ${node.name()} ${body}`, doc + sizeDoc)
152154
}
153155
case "message": {
154156
const doc = extractCommentsDoc(node)
155157
const message = new Message(node.node, node.file)
156158
const body = message.body()?.text ?? ""
157159
const value = message.value()
158-
return defaultResult(`message${value} ${node.name()} ${body}`, doc)
160+
const sizeDoc = documentationSizeOf(message)
161+
return defaultResult(`message${value} ${node.name()} ${body}`, doc + sizeDoc)
159162
}
160163
case "primitive": {
161164
const doc = extractCommentsDoc(node)
@@ -399,7 +402,14 @@ function requireFunctionDoc(place: SyntaxNode, file: File, settings: TactSetting
399402

400403
const exitCode = compiler.requireFunctionExitCode(callNode, file, settings.hints.exitCodeFormat)
401404
if (!exitCode) return ""
402-
return `Edit code: **${exitCode.value}**\n\n`
405+
return `Exit code: **${exitCode.value}**\n\n`
406+
}
407+
408+
function documentationSizeOf(struct: Struct): string {
409+
const ty = new FieldsOwnerTy(struct.name(), struct)
410+
const sizeOf = ty.sizeOf()
411+
const sizeOfPres = sizeOfPresentation(sizeOf)
412+
return `\n\n**Size**: ${sizeOfPres}`
403413
}
404414

405415
function defaultResult(signature: string, documentation: string = ""): string {

server/src/e2e/suite/testcases/completion/constants.test

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ contract Foo {
3939
const<caret>
4040
}
4141
------------------------------------------------------------------------
42+
13 state generate getter for all contract state
4243
13 bounced(msg: <type>) {}
4344
13 const Foo: <type> = <value>
4445
13 external(msg: <type>) {}

server/src/e2e/suite/testcases/completion/contracts.test

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ contract Foo {
55
<caret>
66
}
77
------------------------------------------------------------------------
8+
13 state generate getter for all contract state
89
13 bounced(msg: <type>) {}
910
13 const Foo: <type> = <value>
1011
13 external(msg: <type>) {}

server/src/e2e/suite/testcases/completion/traits.test

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ trait Child with Parent {
9999
<caret>
100100
}
101101
------------------------------------------------------------------------
102+
13 name generate getter for "name" field
102103
9 name: String; of Parent
103104
13 abstract fun name();
104105
13 bounced(msg: <type>) {}
@@ -133,7 +134,9 @@ trait Child with Parent {
133134
<caret>
134135
}
135136
------------------------------------------------------------------------
137+
13 age generate getter for "age" field
136138
9 age: Int; of Grand
139+
13 name generate getter for "name" field
137140
9 name: String; of Parent
138141
13 abstract fun name();
139142
13 bounced(msg: <type>) {}
@@ -166,7 +169,10 @@ trait Child with Parent {
166169
<caret>
167170
}
168171
------------------------------------------------------------------------
172+
13 age generate getter for "age" field
169173
9 age: Int; of Parent
174+
13 name generate getter for "name" field
175+
13 name generate getter for "name" field
170176
13 abstract fun name();
171177
13 bounced(msg: <type>) {}
172178
13 const Foo: <type> = <value>

server/src/e2e/suite/testcases/documentation/require.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ fun foo() {
1313
```tact
1414
fun require(that: Bool, msg: String)
1515
```
16-
Edit code: **44401**
16+
Exit code: **44401**

0 commit comments

Comments
 (0)