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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lsp/nls/src/requests/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,15 @@ fn collect_record_info(
// Get record fields from static type info
(_, Types(TypeF::Record(rrows))) => find_fields_from_type(&rrows, path),
(TermKind::Declaration(_, _, ValueState::Known(body_id)), _) => {
find_fields_from_contract(linearization, *body_id, path)
.or_else(|| find_fields_from_term_kind(linearization, id, path))
.unwrap_or_default()
// The path is mutable, so the first case would consume the path
// so we have to clone it so that it can be correctly used for the second case.
let mut p = path.clone();
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

fst.extend(snd);
fst
}
(
TermKind::RecordField {
Expand Down