-
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
[Language Server] Support more languages #1147
Conversation
…port-more-languages
…port-more-languages
Codecov Report
@@ Coverage Diff @@
## master #1147 +/- ##
==========================================
+ Coverage 46.22% 46.64% +0.42%
==========================================
Files 64 65 +1
Lines 3003 2995 -8
Branches 650 640 -10
==========================================
+ Hits 1388 1397 +9
+ Misses 1363 1350 -13
+ Partials 252 248 -4
Continue to review full report at Codecov.
|
I'm a bit confused, we already have support for js and jsx? Did you add support via something other than babel? |
@acao Hmm, like I said in the PR comment, I added support via regex's instead of babel. Now there's no reason babel couldn't still be used for Re jsx support: I haven't been able to make that work locally, and I think it's because the current code treats any file that doesn't end in exactly graphiql/packages/graphql-language-service-server/src/MessageProcessor.js Lines 687 to 708 in e90f243
|
@zth would you be interested in replacing the babel parser as an experiment in how far you can take this new approach? |
@acao I believe that's what I've already done in this PR, or maybe I'm misunderstanding what you mean? This PR removes the use of the Babel parser to extract GraphQL operation from JS files and replaces it with using regex to extract the source instead. |
@zth I'm just confused because you didnt remove for the full on PR, we will do this in typescript and add a bunch more tests to ease out edgecases, for the many ways template tags can be done in javacsript or typescript for example. maybe add a couple more languages if it's not too difficult. and then in that or a later pass, the ability to provide your own regexes as we were discussing! so excited. now remember, we will be moving all of this to the client and removing watchman from the server completely. so all of this work will come in super handy for creating a language service client abstraction! https://code.visualstudio.com/api/references/vscode-api#workspace |
Doing it in TS and adding more tests sounds great! I guess we need #1138 to land before that can happen though, right? |
@zth why don't you introduce this to it's own module for now in the LSP utils? I might be doing the same for our own parsing logic, moving it to utils package so that monaco mode can re-use it. |
This PR introduces support for more source languages in the Language Server than
js
and rawgraphql
files. It does the following:jsx
,ts
,tsx
andre
(ReasonML)findGraphQLTags
that usedbabel
to parse and extract tags from thejs
documents.Adding support for other languages should be fairly trivial as long as extracting sources from that language's files lends itself well to using regex's. For example, the Apollo Language Server (which started out as a fork from this LS), uses the regex-based approach, and supports Python, Dart and probably some more languages as well, in a rather straight forward way by using regex's.
Discussion points
Is using regex's a good idea?
The rationale for using regex's is that extracting GraphQL sources from tags in documents is pretty straight forward. While there's great support for parsing and extracting sources from JavaScript and TypeScript using an AST-based approach, this probably won't be the case for other languages (think Python, ReasonML etc).
Extracting sources feel straight forward and easy enough that a regex based approach can make sense. But this is just my opinion, what do you feel?
Should we default to including all languages or should it be opt in?
Currently with this PR, all supported files/languages are included when traversing the project and extracting GraphQL operations, but one could make the case supporting other things than
js
andgraphql
should be opt in. I've added a file filter for each language to ensure we can bail early on files that don't contain any operations, but I'm interested in hearing what you think about including all supported languages by default.