ballerina-lang
ballerina-lang copied to clipboard
[Improvement]: Allow the user to rename the `targetType` in generated code
Description
In dependently-typed functions, there can be cases where the user may trigger a create variable code action without providing the expected type in the context. In this scenario, the code action will generate the variable with targetType as the placeholder. Preferably, the cursor should be placed to rename this value.
Describe your problem(s)
Consider the following example of Bal Persistent, in which the user attempts to create a variable for dependently-typed resource access.
import ballerina/persist;
import ballerina/http;
type EmployeeTask record {|
readonly int taskId;
string taskName;
string description;
|};
service /employees on new http:Listener(9090) {
private final Client dbClient;
function init() returns error? {
self.dbClient = check new();
}
isolated resource function get tasks(int id) returns EmployeeTask[]|error {
self.dbClient->/employees();
}
}
In this context, the user hasn't provided the expected type yet, so the code action will not replace the targetType as shown: stream<targetType, persist:Error?> streamResult = self.dbClient->/employees();. Ideally, the cursor should be positioned to rename the targetType in this scenario.
Describe your solution(s)
Ideally, the LS should allow the user to rename the targetType, so the user can enter the expected type after the generation.
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
Related to https://github.com/ballerina-platform/ballerina-lang/issues/39253