graphql / vscode-graphql

MIGRATED: VSCode GraphQL extension (autocompletion, go-to definition, syntax highlighting)
https://marketplace.visualstudio.com/items?itemName=Prisma.vscode-graphql
MIT License
557 stars 71 forks source link

Add support for autocomplete from javascript files #119

Closed ganemone closed 5 years ago

ganemone commented 5 years ago

This enables the graphql language server extension when in javascript files which will enable autocomplete when using tagged templates. This combined with https://github.com/graphql/graphiql/pull/883 will fix autocomplete with the gql tagged template.

Fixes #61 Fixes #21 Fixes #53 Fixes #96

divyenduz commented 5 years ago

Thanks for the PR @ganemone

Can you confirm that this does what the PR intends it to do? To the best of my understanding, we support gql tags by augmenting the TS language service with a plugin.

The docs of how to write such a plugin exist here: https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin

Concretely, our implementation of the plugin is here: https://github.com/divyenduz/ts-graphql-plugin

And this is where we use the plugin in this extension: https://github.com/prisma/vscode-graphql/blob/master/package.json#L113

We shouldn't have to add js for watcher/document selector. But I would love to know your reasoning for this PR. If this is needed at all, this would also be required for .ts files I think?

ganemone commented 5 years ago

@divyenduz the typescript server approach won't work for projects that use flow and disable the builtin typescript language features. To be honest, as far as I can tell the typescript language server approach doesn't work at all, even with typescript features enabled.

I'm happy to expand this PR to replace the ts plugin so the completion support works the same way for both ts and non ts users. I think all the issues I linked in this PR are people who can corroborate that the autocomplete currently does not work.

divyenduz commented 5 years ago

Thanks, I understand, this PR is relatively safe to merge, so I will do that and release it. But I think that JS/TS auto completion should work in gql tag anyways.

There are several reasons (mainly around developer experience) that in my understanding cause the above listed issues:

  1. graphql-config: This extension relies on the existence of that file to kick in.
  2. Changes in the watchman API (was required before but not anymore)

Generally, feel free to open issues and tag me to push things forward wrt this project. I am really happy that you raised this PR :)

divyenduz commented 5 years ago

This is released in 0.2.1, thanks for your work on this 🙌

A lot of work is happening in the language service arena, they are moving it to a mono repo with GraphiQL, so, I anticipate good things for this plugin in future :)