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

Fix LSP server not giving completion when a non-contract meta-information is present in a declaration #991

Merged
merged 7 commits into from
Dec 21, 2022

Conversation

ebresafegaga
Copy link
Contributor

Closes #989

@ebresafegaga ebresafegaga self-assigned this Dec 13, 2022
@github-actions github-actions bot temporarily deployed to pull request December 13, 2022 13:31 Inactive
Copy link
Contributor

@matthew-healy matthew-healy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix itself looks good. Does it make sense to add a regression test for this somewhere?

Comment on lines 71 to 74
Some(meta_value) => {
let result = find_fields_from_meta_value(meta_value, path);
(!result.is_empty()).then_some(result)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand why this fixes the issue, but I imagine you tested the result. Is it because find_fields_from_contracts is called somewhere in a chain, and if it returns something, we keep the result, otherwise we try to find a completion by other means?

If this is case, why don't we aggregate all source of information (types, contracts, literal definition)? For example, if the contract is {foo, ..} but we know that the record is equal to {foo = 1, bar = 2}, does this mean that even after this PR, completion won't show bar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because find_fields_from_contracts is called somewhere in a chain, and if it returns something, we keep the result, otherwise we try to find a completion by other means?

Yes.

I think aggregation is better. Thanks!

@github-actions github-actions bot temporarily deployed to pull request December 15, 2022 13:06 Inactive
Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want a hashet when aggregating. Or is there something else preventing duplicate elsewhere ? Otherwise, there is a high change than a record literal definition and the associated contracts will have the same fields defined 🙂

@ebresafegaga
Copy link
Contributor Author

Yes, we have a function that removes duplicates. But we can also avoid that entirely by collecting the completion items with a HashSet.

Currently writing some tests will merge once that is completed.

@github-actions github-actions bot temporarily deployed to pull request December 16, 2022 15:26 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 19, 2022 11:16 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 19, 2022 11:20 Inactive
Comment on lines 334 to 337
let mut fst = find_fields_from_contract(linearization, *body_id, path)
.unwrap_or_default();
let snd =
find_fields_from_term_kind(linearization, id, &mut p).unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, does it make sense anymore to have an option returned by find_fields_from if we're aggregating? Would an empty collection be enough and make sense? (getting wrap of the unwrap_or_default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be much better. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But on a second thought, most of these functions use the monadic ? operator on Options to make error propagation or early return much cleaner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But do they need that at all? Couldn't you just return an empty collection instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, returning an option should be decided first and foremost by the semantics of the function and the callers though

@github-actions github-actions bot temporarily deployed to pull request December 20, 2022 15:33 Inactive
@yannham
Copy link
Member

yannham commented Dec 21, 2022

The CI is failing because the order of completion suggestions is not the same between the expected value and the actual value in some of the tests. I guess you want to sort your vectors inside your tests (or in the LSP directly)?

@ebresafegaga ebresafegaga merged commit 3c02bed into master Dec 21, 2022
@ebresafegaga ebresafegaga deleted the fix/lsp-contract branch December 21, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSP server doesn't give completion when only non-contract meta-information are present
3 participants