Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Extend symbol signature to work FnCall #24913

Merged
merged 3 commits into from
Apr 23, 2024
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
29 changes: 29 additions & 0 deletions tools/chpl-language-server/src/symbol_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def _get_symbol_signature(node: chapel.AstNode) -> List[Component]:
return _var_to_string(node)
elif isinstance(node, chapel.Function):
return _proc_to_string(node)
elif isinstance(node, chapel.TypeQuery):
return [_wrap_str(f"?{node.name()}")]

return [_wrap_str(node.name())]

Expand Down Expand Up @@ -171,6 +173,8 @@ def _node_to_string(node: chapel.AstNode) -> List[Component]:
return [_wrap_str('"' + node.value() + '"')]
elif isinstance(node, chapel.CStringLiteral):
return [_wrap_str('c"' + node.value() + '"')]
elif isinstance(node, chapel.FnCall):
return _fncall_to_string(node)
return [Component(ComponentTag.PLACEHOLDER, None)]


Expand Down Expand Up @@ -300,3 +304,28 @@ def _intent_to_string(intent: Optional[str]) -> str:
}
# use 'intent' as the default, so if no remap no work done
return remap.get(intent, intent) if intent else ""


def _fncall_to_string(call: chapel.FnCall) -> List[Component]:
"""
Convert a call to a string
"""
comps = []

comps.extend(_node_to_string(call.called_expression()))
openbr, closebr = ("[", "]") if call.used_square_brackets() else ("(", ")")
comps.append(_wrap_str(openbr))
sep = ""
for a in call.actuals():
comps.append(_wrap_str(sep))
sep = ", "
if isinstance(a, tuple):
comps.append(_wrap_str(a[0]))
comps.append(_wrap_str(" = "))
comps.extend(_node_to_string(a[1]))
else:
assert isinstance(a, chapel.AstNode)
comps.extend(_node_to_string(a))
comps.append(_wrap_str(closebr))

return comps
Loading