[lsp-server] 🐞 Adding whitespaces\newlines causes autocompletion to move up a level
- Dominant language
- TypeScript
- Stars
- 16.9k
- Forks
- 1.9k
- Avg merge
- 22h 45m
- Merged PRs (30d)
- 70
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current Behavior
Consider the following code:
```dart
mutation createComment2 @auth(is: PUBLIC) {
comment_insert2(data: {
})
}
```
where `data` expects an `input` type.
In this scenario, adding whitespaces when trying to get autocompletion seems to change the result. Here's a video showcasing the issue:
https://github.com/graphql/graphiql/assets/20165741/50786f0c-faf1-4fac-8fdf-93805d8ada2e
### Expected Behavior
Adding whitespaces/newlines should not have any impact on the suggestion.
### Steps To Reproduce
_No response_
### Environment
* LSP Server Version: latest
* OS: macos
* LSP Client: vscode-graphql
### Anything else?
I've tried debugging this by adding logs on a fork of the repository, and the issue appears to be `getAutocompletionSuggestions.ts#getTokenAtPosition`.
I added a `console.log(token)` inside `getAutocompleteSuggestions` right before the call to `getTypeInfo` here
https://github.com/graphql/graphiql/blob/ece99f63f5d8d01057b735e90a6957edea3e42b9/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts#L181
Then compared the log outputs based on where the cursor is.
Given `comment_insert2(data: {| })`, the token returned is:
```
{
start: 0,
end: 0,
string: '{',
state: { ... },
style: 'punctuation'
}
```
But for `comment_insert2(data: { | })` it is:
```
{
start: 0,
end: 0,
string: '}',
state: { ... },
style: 'punctuation'
}
```
And lastly for `comment_insert2(data: { |})` it is:
```
{
start: 0,
end: 0,
string: ')',
state: { ... },
style: 'punctuation'
}
```
This doesn't make sense to me. I would expect all of them to return the token with `string: '{'`
Contributor guide
Assessment
This issue has not been assessed yet.