-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[lsp-server] 🐞 Adding whitespaces\newlines causes autocompletion to move up a level #3553
Comments
there are some bugs I'm planning to fix in autocomplete that may be related to this, or it's an offset issue. Is the file you are editing named . graphql or .graphqls by chance, or something else? |
No it is named |
I think I've logged the Given the line:
|
Looks like disabling "eatWhitespace" fixes the whitespace issue (although likely an incorrect fix) export function runOnlineParser(
queryText: string,
callback: callbackFnType,
): ContextToken {
const lines = queryText.split('\n');
const parser = onlineParser({
+ // Preserve whitespaces for the sake of realistic offsets.
+ eatWhitespace: () => false,
+ // Keep default values, as TS requires those fields to be specified
+ lexRules: LexRules,
+ parseRules: ParseRules,
+ editorConfig: {},
}); Newlines are still a problem though. I'll look into it more |
I think for newlines the issue is this condition here: In the case of:
I assume we'd want to obtain With both changes considered, that seem to fix the issue for me. I'll open a PR |
Is there an existing issue for this?
Current Behavior
Consider the following code:
where
data
expects aninput
type.In this scenario, adding whitespaces when trying to get autocompletion seems to change the result. Here's a video showcasing the issue:
Screen.Recording.2024-03-06.at.13.06.38.mov
Expected Behavior
Adding whitespaces/newlines should not have any impact on the suggestion.
Steps To Reproduce
No response
Environment
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)
insidegetAutocompleteSuggestions
right before the call togetTypeInfo
heregraphiql/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts
Line 181 in ece99f6
Then compared the log outputs based on where the cursor is.
Given
comment_insert2(data: {| })
, the token returned is:But for
comment_insert2(data: { | })
it is:And lastly for
comment_insert2(data: { |})
it is:This doesn't make sense to me. I would expect all of them to return the token with
string: '{'
The text was updated successfully, but these errors were encountered: