Skip to content

fix: fix signature help for initOf for contracts with parameters #410

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
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
51 changes: 51 additions & 0 deletions server/src/e2e/suite/testcases/signatureHelp/initOf.test
Original file line number Diff line number Diff line change
@@ -57,3 +57,54 @@ contract ContractB {
------------------------------------------------------------------------
b: Int
init(a: Int, b: Int, c: Int)

========================================================================
initOf for contract with parameter
========================================================================
primitive Int;

contract ContractA(a: Int) {
}

contract ContractB {
init() {
initOf ContractA(<caret>)
}
}
------------------------------------------------------------------------
a: Int
init(a: Int)

========================================================================
initOf for contract with parameters
========================================================================
primitive Int;

contract ContractA(a: Int, other: Int) {
}

contract ContractB {
init() {
initOf ContractA(10, <caret>)
}
}
------------------------------------------------------------------------
other: Int
init(a: Int, other: Int)

========================================================================
initOf for contract without parameters
========================================================================
primitive Int;

contract ContractA {
}

contract ContractB {
init() {
initOf ContractA(<caret>)
}
}
------------------------------------------------------------------------

init()
32 changes: 18 additions & 14 deletions server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1138,12 +1138,22 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise<lsp.In
isStructField: boolean
structFieldIndex: number
} | null => {
const findParametersNode = (element: NamedNode): SyntaxNode | null => {
const findParameters = (element: NamedNode): Node[] => {
if (element instanceof Contract) {
return element.initFunction()?.node.childForFieldName("parameters") ?? null
const initFunction = element.initFunction()
if (initFunction) {
return initFunction.parameters()
}
return element.parameters()
}

return element.node.childForFieldName("parameters")
const parameters = element.node.childForFieldName("parameters")
if (!parameters) return []

return parameters.children
.filter(param => param?.type === "parameter")
.filter(param => param !== null)
.map(param => new Node(param, element.file))
}

const findSignatureHelpNode = (node: SyntaxNode): SyntaxNode | null => {
@@ -1238,20 +1248,14 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise<lsp.In
const res = Reference.resolve(call.nameNode())
if (res === null) return null

const parametersNode = findParametersNode(res)
if (!parametersNode) return null

const parameters = parametersNode.children
.filter(value => value?.type === "parameter")
.filter(value => value !== null)

const rawArguments = call.rawArguments()

const parametersInfo: lsp.ParameterInformation[] = parameters.map(value => ({
label: value.text,
const parameters = findParameters(res)
const parametersInfo: lsp.ParameterInformation[] = parameters.map(param => ({
label: param.node.text,
}))
const parametersString = parametersInfo.map(el => el.label).join(", ")

const rawArguments = call.rawArguments()

if (callNode.type === "initOf") {
return {
rawArguments,