Skip to content

[relay-lsp] Suggestions from wrong context #4472

@tobias-tengler

Description

@tobias-tengler

Last week, while working on a rather large file, I noticed that the LSP would often not suggest any fields or fields from a different level in the selection set.

The issue is easily reproduced (more so in larger files) if you accept the completion item for a field returning an object type.

In response to that the LSP will insert a snippet like the following:

newObjectField {
    $cursor
}

Afterwards it triggers the editor.action.triggerSuggest command to reopen the completion menu at the new cursor position.

What's happening is that the textdocument/didchange and textdocument/completion commands from the client are not necessarily sent in that order and if they are, the LSP might still be processing the document update while completion items are already being calculated at the new cursor position. And of course, if the LSP is computing completion items for the new location, while still working with the old document, weird things can happen like no suggetions because the position is outside the GraphQL document or the position being in a different selection set.

I think there are two things at play here that both need to be addressed in order to correct the behavior:

  1. Relay should wait to calculate completion items until all sync operations are completed - this can be easily done and I will send a PR for it in a follow-up. EDIT: [relay-lsp] Ensure documents are synced before calculating completions #4473
    2. There seems to be a bug in the LSP client (VS Code in this case) where textdocument/didchange and textdocument/completion are not sent in this order if a completion item triggers editor.action.triggerSuggest - I will raise an issue for this in their repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions