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

[Bug]: The code completion for annotation field is not working for some fields #40668

Closed
TharmiganK opened this issue Jun 13, 2023 · 5 comments · Fixed by #41809
Closed

[Bug]: The code completion for annotation field is not working for some fields #40668

TharmiganK opened this issue Jun 13, 2023 · 5 comments · Fixed by #41809
Assignees
Labels
Area/Completion Issues related to Language Server Auto Completions Points/1 Equivalent to one day effort Priority/High Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Status/Blocked Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Bug
Milestone

Comments

@TharmiganK
Copy link
Contributor

Description

When we have a union-typed field for an annotation (union of int and record) and when we try to give it as a record value, the code completions are not working properly.

Note: This tooling support is required for this new feature in the constraint package - ballerina-platform/module-ballerina-constraint#79

Steps to Reproduce

Check the following code in vscode:

annotation StringConstraints String on type, record field;

type ConstraintRecord record {|
    anydata value;
    string message;
|};

type StringConstraints record {|
    int|record{| *ConstraintRecord; int value; |} length?;
|};

@String {
    length : {} // enter the curly braces and try to type the field name it does not complete with the proper fields
}
type TestString string;

Affected Version(s)

Ballerina SwanLake 2201.6.0

OS, DB, other environment details and versions

Mac OS with Apple M1 chip

Related area

-> Editor

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@TharmiganK TharmiganK added Type/Bug Team/LanguageServer Language Server Implementation related issues. #Compiler Area/Completion Issues related to Language Server Auto Completions Priority/High labels Jun 13, 2023
@TharmiganK TharmiganK added this to the 2201.7.0 milestone Jun 13, 2023
@malinthar
Copy link
Contributor

When investigated, I figured out that the ExpectedTypeAPI returns an invalid expected type at the cursor position depicted above. The syntax tree node at the cursor is a SpecificFieldNode.

The expected type API uses the NodeFinder class to find the BLangNode node in a given range. In the above case the range given (specic field node in the annotation attachment) is not within the range of any of the topLevel nodes. Therefore, the node finder return null when the lookup() method in the NodeFinder is called.

BLangNode lookup(BLangCompilationUnit unit, LineRange range) {

image

@malinthar malinthar added Area/Compiler Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed Area/Compiler labels Jun 13, 2023
@KavinduZoysa
Copy link
Contributor

In the above example, we are trying to look up an annotAttachment by giving a pos inside it. First, we iterate over top-level nodes and the position of top-level nodes does not cover its' annotAttachment. That's why we are getting null here. We can,

  1. lookup for annotAttachment for each top-level node separately or
  2. extend the pos of the node to cover the annotAttachment.

For 2nd one, we need support from the parser and it is a change in the compiler front-end side. The 1st one can be done within NodeFinder.java and we have to check the other place that can have annotAttachements.

@hasithaa, @gimantha, @MaryamZi, @pcnfernando WDYT?

@hasithaa
Copy link
Contributor

We can't do the 2, it is a backward incompatible change. +1 for 1st one.

@malinthar malinthar removed this from the 2201.7.0 milestone Jun 14, 2023
@KavinduZoysa KavinduZoysa added the Points/1 Equivalent to one day effort label Jul 13, 2023
@anupama-pathirage anupama-pathirage moved this from BackLog to Planned for Sprint in Ballerina Team Main Board Jul 17, 2023
@anupama-pathirage anupama-pathirage moved this from Planned for Sprint to BackLog in Ballerina Team Main Board Jul 17, 2023
@anupama-pathirage anupama-pathirage removed the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Jul 17, 2023
@mindula mindula moved this from BackLog to In Progress in Ballerina Team Main Board Aug 9, 2023
@mindula
Copy link
Contributor

mindula commented Aug 10, 2023

Blocked by #41186

@mindula mindula moved this from In Progress to On Hold in Ballerina Team Main Board Aug 10, 2023
@github-project-automation github-project-automation bot moved this from On Hold to Done in Ballerina Team Main Board Dec 8, 2023
Copy link

github-actions bot commented Dec 8, 2023

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@KavinduZoysa KavinduZoysa added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Dec 8, 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 Points/1 Equivalent to one day effort Priority/High Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Status/Blocked Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants