Use adjusted completion position when at end of identifier #2495
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2483.
Context
When requesting completion off of something that's not a dotted name, we need to traverse the scopes. First we need to grab a node for which we will traverse upwards to aggregate scopes. We call this the
scopeNode
.The original idea was that the first node that we begin aggregating on needs to contain the position for which we are requesting completion. The original challenge was determining "containedness". Fundamentally, a node
n
contains a positionp
ifn.getStart() <= p && p < n.getEnd()
_or_ then.getStart() <= p
andn
is not "completed". See #2396 for details.However, when requesting completion at the end of an identifier, this is an issue because the identifier is completed. This surfaces in issues with arrow functions like in the following:
Here, the arrow function is considered completed, so we continue looking for a node that owns the position of the cursor.
Solution
In the same manner that we adjust the
contextToken
, we adjust the position for which we are requesting a completion if at the end of an identifier. For the previous example, we will find scopes as if the completion was requested in the following scenario: