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

Make sure limited label candidates are sorted #86

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Aug 23, 2021

This was caught by a flaky test on main after merging #85

=== RUN   TestDecoder_CandidateAtPos_incompleteLabels
    label_candidates_test.go:102: unexpected candidates:   lang.Candidates{
          	List: []lang.Candidate{
          		{
        - 			Label:        "first",
        + 			Label:        "second",
          			Description:  {},
          			Detail:       "",
          			IsDeprecated: false,
          			TextEdit: lang.TextEdit{
          				Range:   {Filename: "test.tf", Start: {Line: 1, Column: 14, Byte: 13}, End: {Line: 1, Column: 14, Byte: 13}},
        - 				NewText: "first",
        + 				NewText: "second",
        - 				Snippet: "first",
        + 				Snippet: "second",
          			},
          			AdditionalTextEdits: nil,
          			Kind:                s"LabelCandidateKind",
          			TriggerSuggest:      false,
          		},
          	},
          	IsComplete: false,
          }
--- FAIL: TestDecoder_CandidateAtPos_incompleteLabels (0.00s)

Prior to this patch we were ranging over a map which doesn't have a guaranteed order. The solution reflects what we already do for attributes and blocks - i.e. iterate over sorted keys instead of a map:

attrNames := sortedAttributeNames(schema.Attributes)
for _, name := range attrNames {

blockTypes := sortedBlockTypes(schema.Blocks)
for _, bType := range blockTypes {

@radeksimko radeksimko added the bug Something isn't working label Aug 23, 2021
@radeksimko radeksimko requested a review from a team August 23, 2021 08:26
@jpogran jpogran merged commit 8fcbc27 into main Aug 23, 2021
@jpogran jpogran deleted the b-sort-label-candidates branch August 23, 2021 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants