ballerina-platform / ballerina-lang

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

Invalid syntax tree given for configurable qualifier #36215

Open mindula opened 2 years ago

mindula commented 2 years ago

Description: Consider the following scenario,

configurable <cursor>             

public function main() {

}

The image below shows the syntax tree given for the above scenario,

Screenshot 2022-05-19 at 11 14 13
IMS94 commented 2 years ago

@lochana-chathura @rdulmina Can you check this scenario? Will it be possible to improve the parser's recovery logic here?

lochana-chathura commented 2 years ago

Sorry, we missed this issue. The thing is above is equivalent to the below when parsing,

configurable public function main() {   
}

So we are giving an error and marking the configurable as an invalid token when a function has a configurable qualifier.

To give the suggestions for the above cursor position I think we can use the leadingInvalidTokens() API. If the node at the cursor position is FunctionDefinitionNode, can't we use functionDefinitionNode.leadingInvalidTokens()?

We seem to have a similar usage in ClassDefinitionNodeContext. https://github.com/ballerina-platform/ballerina-lang/blob/de51ab86325aabd43053bce9a795974ff45dcc4b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ClassDefinitionNodeContext.java#L117

We are using leadingInvalidTokens() API underneath the CommonUtil.getQualifiersOfNode().