ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.66k stars 750 forks source link

[New Feature]: Introduce on Type formating language feature to LS #38131

Open malinthar opened 2 years ago

malinthar commented 2 years ago

Description

Format code when typing. The format request textDocument/onTypeFormatting is trigger by special characters like {, }, ;

Refer https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_onTypeFormatting

IMS94 commented 2 years ago

+1

lochana-chathura commented 6 months ago

Sample use case,

function getJsonProperty(json|error data) returns json|error? => <cursor>

or

function getJsonProperty(json|error data) returns json|error? => <cursor> data is error ? data.message() : data.'worker;

When we press enter at the cursor position above,

In coding styles, we encourage using expression-bodied functions over block-function-body whenever possible. Therefore, I expect this to be a quite frequent scenario.