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

[Improvement]: Provide a code action to break lines in a Ballerina string template #41499

Closed
nipunayf opened this issue Oct 10, 2023 · 2 comments
Assignees
Labels
Area/Completion Issues related to Language Server Auto Completions Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Improvement

Comments

@nipunayf
Copy link
Contributor

Description

String templates are designed to allow the user to input text as it is. Thus, unlike quoted strings, the code editor allows the user to write a string template for multiple lines. However, in some cases, the user may want to break the string template into multiple lines to restrict the character limit per line rather than having a new line in the string. It is better if the LS can provide a code action for this scenario.

Describe your problem(s)

No response

Describe your solution(s)

LS needs to provide a code action when the cursor-point is within the context of a string template as shown in the below code.

import ballerina/io;

public function main() {
    var name = "Name";
    io:println(
        string `Hello, ${name}! <cursor-point>Some text`);
}

After the execution of the code action, it can format the code above as shown below.

import ballerina/io;

public function main() {
    var name = "Name";
    io:println(
        string `Hello, ${name}! ` +
        string `Some text`);
}

Related area

-> Other Area

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@nipunayf nipunayf added Type/Improvement Team/LanguageServer Language Server Implementation related issues. #Compiler Area/Completion Issues related to Language Server Auto Completions labels Oct 10, 2023
@nipunayf nipunayf self-assigned this Oct 10, 2023
@nipunayf nipunayf moved this to In Progress in Ballerina Team Main Board Oct 10, 2023
@nadeeshaan
Copy link
Contributor

nadeeshaan commented Oct 10, 2023

Code actions are meant to be used for the refactorings which can alter the semantics as well as non-trivial syntax. In this scenario, we should first see whether we need to allow the user to make this decision. Refactorings such as these (especially syntax refactorings) should adhere to the coding best practices and formatting practices. This is a scenario which we can categorise as a formatting best practice. Hence, IMHO, we should not expose this as a part of the code action implementation, since it is not intuitive for the user, from where we are going to add the break of lines. yes, they can try and check, but code actions should be intuitive in the first look. If we really need to do this, we should expose this via our formatting implementation, based on the length of the template expression or based on other heuristics.

@nipunayf
Copy link
Contributor Author

Code actions are meant to be used for the refactorings which can alter the semantics as well as non-trivial syntax. In this scenario, we should first see whether we need to allow the user to make this decision. Refactorings such as these (especially syntax refactorings) should adhere to the coding best practices and formatting practices. This is a scenario which we can categorise as a formatting best practice. Hence, IMHO, we should not expose this as a part of the code action implementation, since it is not intuitive for the user, from where we are going to add the break of lines. yes, they can try and check, but code actions should be intuitive in the first look. If we really need to do this, we should expose this via our formatting implementation, based on the length of the template expression or based on other heuristics.

I agree with this comment as well since the initial requirement came as a formatting feature. However, the idea of a code action arose with the concern of how the user can select the precise point to break for better readability. After an offline discussion, we have decided to leave this as a formatting feature and let the user manually change it if required for readability. Hence, closing the issue and delegating it to the formatter: #41513.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Ballerina Team Main Board Oct 13, 2023
@nipunayf nipunayf added Reason/Invalid Issue is invalid. and removed Reason/Invalid Issue is invalid. labels Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Completion Issues related to Language Server Auto Completions Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Improvement
Projects
Archived in project
Development

No branches or pull requests

2 participants