]> git.lizzy.rs Git - rust.git/commitdiff
Merge #8008
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Mon, 15 Mar 2021 12:59:47 +0000 (12:59 +0000)
committerGitHub <noreply@github.com>
Mon, 15 Mar 2021 12:59:47 +0000 (12:59 +0000)
8008: Completion context expected type r=matklad a=JoshMcguigan

Currently there are two ways completions use to determine the expected type. There is the `expected_type` field on the `CompletionContext`, as well as the `expected_name_and_type` method on the `RenderContext`. These two things returned slightly different results, and their results were only valid if you had pre-checked some (undocumented) invariants. A simple combination of the two approaches doesn't work because they are both too willing to go far up the syntax tree to find something that fits what they are looking for.

This PR makes the following changes:

1. Updates the algorithm that sets `expected_type` on `CompletionContext`
2. Adds `expected_name` field to `CompletionContext`
3. Re-writes the `expected_name_and_type` method to simply return the underlying fields from `CompletionContext` (I'd like to save actually removing this method for a follow up PR just to keep the scope of the changes down)
4. Adds unit tests for the `expected_type`/`expected_name` fields

All the existing unit tests still pass (unmodified), but this new algorithm certainly has some gaps (although I believe all the `FIXME` introduced in this PR are also flaws in the current code). I wanted to stop here and get some feedback though - is this approach fundamentally sound?

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>

Trivial merge