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

More aggressive type/contract deduplication on hover #1984

Merged
merged 4 commits into from
Jul 3, 2024
Merged

Conversation

jneem
Copy link
Member

@jneem jneem commented Jul 2, 2024

Fixes #1972.

While testing this, I noticed that some field documentation was missed when hovering over the exact field that was annotated, so I fixed that too.

jneem added 2 commits July 2, 2024 17:46
Deduplicate not just the type annotations, but also the contract
annotations. Also, try to report Dyn less often.
@jneem jneem requested a review from yannham July 2, 2024 22:53
@github-actions github-actions bot temporarily deployed to pull request July 2, 2024 22:55 Inactive
lsp/nls/src/requests/hover.rs Outdated Show resolved Hide resolved
Comment on lines +193 to +196
// There's no point in repeating the static type in the annotations.
if let Some(idx) = annotations.iter().position(|a| a == &ty) {
annotations.remove(idx);
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we remove the static type from the annotations. annotations is just the list of the type, followed by all contracts, sorted and deduped, right? So, I would expect to find the static type in it, and that it's intentional. Why remove it?

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I get it. You include the static type in the annotations so that it's deduped (if there is the same as a contract), but you still keep the distinction static type/contracts, so you display the static type separately, and don't want to repeat it in the annotations.

Which I think is the right behavior (the static type is special in that it's the one selected e.g. by the typechecker). Maybe you could add a short mention explaining this (we don't distinguish between types and contracts for the dedup but we will in the LSP answer) to the comment attached to annotations ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, exactly. I've added a comment so hopefully it's less mysterious now

Comment on lines 184 to 185
annotations.sort();
annotations.dedup();
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 entirely sure it's ok to sort the annotations. The order of contracts is meaningful in Nickel (different order of application might give a different result). Additionally, if there's no static type, the first contract of the list is taken to be the static type, which also makes a difference statically, and not only at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'm deduping them without sorting now.

@github-actions github-actions bot temporarily deployed to pull request July 3, 2024 17:49 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 3, 2024 18:01 Inactive
@jneem jneem enabled auto-merge July 3, 2024 18:36
@jneem jneem added this pull request to the merge queue Jul 3, 2024
Merged via the queue into master with commit 935519f Jul 3, 2024
5 checks passed
@jneem jneem deleted the hover-doc branch July 3, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter out the contract annotations on hover/completion when they don't add anything
2 participants