Problem
Some spx APIs accept a zero-argument callback because they need to evaluate an expression repeatedly. For example, waitUntil expects a condition of type func() bool.
XGo allows users to pass an expression directly:
The compiler implicitly converts the expression into a closure, approximately equivalent to:
waitUntil => v.IsMature()
This conversion is not visible in the source code. XBuilder currently shows only the parameter-name inlay hint:
waitUntil condition: v.IsMature()
The condition: hint identifies the parameter, but it does not explain that the expression becomes a callback and may be evaluated multiple times.
A particularly confusing case is:
A user may write this accidentally after omitting (), but the code still compiles because v.IsMature is already a method value of type func() bool. It does not use the implicit expression-to-closure conversion.
Both forms are valid, but they rely on different language behavior. The editor currently provides no guidance about this distinction.
Possible improvement
Could xgolsw provide a dedicated inlay hint when XGo performs an implicit expression-to-closure conversion?
For example:
waitUntil condition: => v.IsMature()
Both condition: and => would be virtual editor hints.
The => hint could provide a tooltip such as:
XGo implicitly converts this expression to func() bool. waitUntil evaluates it each time it checks the condition.
The standard LSP textDocument/inlayHint capability appears suitable for this. An optional text edit could also allow users to make the conversion explicit by inserting => .
The hint should be based on resolved types rather than hard-coded API names.
Expected behavior:
waitUntil v.IsMature() shows the implicit-conversion hint
waitUntil ready shows the implicit-conversion hint
waitUntil => v.IsMature() does not show a redundant hint
waitUntil v.IsMature does not show the hint because it is already a method value
- Existing function values do not show the hint
- Valid method values are not reported as missing-parentheses errors
XBuilder may need to preserve and render the additional inlay hint and its tooltip when returned by xgolsw.
The waitUntil API documentation and teaching examples could also prefer the explicit form when introducing this behavior:
waitUntil => v.IsMature()
The goal is to make this non-obvious XGo conversion discoverable without treating valid code as an error or warning.
Problem
Some spx APIs accept a zero-argument callback because they need to evaluate an expression repeatedly. For example,
waitUntilexpects a condition of typefunc() bool.XGo allows users to pass an expression directly:
The compiler implicitly converts the expression into a closure, approximately equivalent to:
This conversion is not visible in the source code. XBuilder currently shows only the parameter-name inlay hint:
The
condition:hint identifies the parameter, but it does not explain that the expression becomes a callback and may be evaluated multiple times.A particularly confusing case is:
A user may write this accidentally after omitting
(), but the code still compiles becausev.IsMatureis already a method value of typefunc() bool. It does not use the implicit expression-to-closure conversion.Both forms are valid, but they rely on different language behavior. The editor currently provides no guidance about this distinction.
Possible improvement
Could xgolsw provide a dedicated inlay hint when XGo performs an implicit expression-to-closure conversion?
For example:
Both
condition:and=>would be virtual editor hints.The
=>hint could provide a tooltip such as:The standard LSP
textDocument/inlayHintcapability appears suitable for this. An optional text edit could also allow users to make the conversion explicit by inserting=>.The hint should be based on resolved types rather than hard-coded API names.
Expected behavior:
waitUntil v.IsMature()shows the implicit-conversion hintwaitUntil readyshows the implicit-conversion hintwaitUntil => v.IsMature()does not show a redundant hintwaitUntil v.IsMaturedoes not show the hint because it is already a method valueXBuilder may need to preserve and render the additional inlay hint and its tooltip when returned by xgolsw.
The
waitUntilAPI documentation and teaching examples could also prefer the explicit form when introducing this behavior:The goal is to make this non-obvious XGo conversion discoverable without treating valid code as an error or warning.