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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
"type": "boolean",
"default": true,
"description": "Show method ID hints for functions with method_id"
},
"ton.func.hints.implicitConstantType": {
"type": "boolean",
"default": true,
"description": "Show type hints for constants without explicit type"
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions server/src/languages/func/documentation/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {NamedNode} from "@server/languages/func/psi/FuncNode"
import {Constant, Func, GlobalVariable, TypeParameter} from "@server/languages/func/psi/Decls"
import {parentOfType} from "@server/psi/utils"
import type {Node as SyntaxNode} from "web-tree-sitter"
import {typeOf} from "@server/languages/func/types/infer"
import {UnknownTy} from "@server/languages/func/types/ty"

/**
* Returns the documentation for the given symbol in Markdown format, or null
Expand Down Expand Up @@ -36,8 +38,8 @@ export function generateFuncDocFor(node: NamedNode, _place: SyntaxNode): string
}
case "constant_declaration": {
const constant = new Constant(astNode, node.file)
const type = node.node.childForFieldName("type")
const typeName = type?.text ?? "unknown"
const type = typeOf(astNode, node.file) ?? UnknownTy.UNKNOWN
const typeName = type.name()

const value = constant.value()
if (!value) return null
Expand Down
34 changes: 34 additions & 0 deletions server/src/languages/func/inlays/implicit-constant-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
// Copyright © 2025 TON Core
import type {Node as SyntaxNode} from "web-tree-sitter"
import * as lsp from "vscode-languageserver-types"
import {FuncFile} from "@server/languages/func/psi/FuncFile"
import {typeOf} from "@server/languages/func/types/infer"

export function implicitConstantType(n: SyntaxNode, file: FuncFile, result: lsp.InlayHint[]): void {
const type = n.childForFieldName("type")
if (type) {
// const int FOO = 100;
// ^^^ no need for hint
return
}

const value = n.childForFieldName("value")
if (!value) return

const ty = typeOf(value, file)
if (!ty) return

const nameIdent = n.firstChild
if (!nameIdent) return

result.push({
kind: lsp.InlayHintKind.Type,
label: ty.name(),
paddingRight: true,
position: {
line: nameIdent.startPosition.row,
character: nameIdent.startPosition.column,
},
})
}
6 changes: 6 additions & 0 deletions server/src/languages/func/inlays/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import * as lsp from "vscode-languageserver-types"
import {RecursiveVisitor} from "@server/visitor/visitor"
import {getMethodId} from "@server/languages/func/inlays/get-method-id"
import {FuncFile} from "@server/languages/func/psi/FuncFile"
import {implicitConstantType} from "@server/languages/func/inlays/implicit-constant-type"

export function collectFuncInlays(
file: FuncFile,
hints: {
disable: boolean
showMethodId: boolean
showImplicitConstantType: boolean
},
): lsp.InlayHint[] | null {
if (hints.disable) return []
Expand All @@ -23,6 +25,10 @@ export function collectFuncInlays(
getMethodId(n, file, result)
}

if (type === "constant_declaration" && hints.showImplicitConstantType) {
implicitConstantType(n, file, result)
}

return true
})

Expand Down
4 changes: 2 additions & 2 deletions server/src/languages/func/tree-sitter-func/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ const FUNC_GRAMMAR = {
primitive_type: $ => choice("int", "cell", "slice", "builder", "cont", "tuple"),
// constant_type: $ => choice("int", "slice"),

tensor_type: $ => choice(seq("(", ")"), seq("(", commaSep2($._type_hint), ")")),
tensor_type: $ => choice(seq("(", ")"), seq("(", field("types", commaSep2($._type_hint)), ")")),

tuple_type: $ => seq("[", commaSep($._type_hint), "]"),
tuple_type: $ => seq("[", field("types", commaSep($._type_hint)), "]"),

var_type: _ => "var",
hole_type: $ => alias($.underscore, $.hole_type),
Expand Down
112 changes: 60 additions & 52 deletions server/src/languages/func/tree-sitter-func/src/grammar.json

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

Loading
Loading