Skip to content

Commit

Permalink
move vscode grammars, basic language support to standalone syntax ext…
Browse files Browse the repository at this point in the history
…ension (#2573)

* move vscode grammars, basic language support and snippets to graphql syntax extension.

`vscode-graphql` now depends on this extension, and provides language server support in addition. this allows alternative LSP servers and non-LSP graphql extensions to use our highlighting only, or allows users to just install the syntax highlighting extension if they don't need LSP server features.

* Add license

Ope!

* move snippets back

* more work on the readme, bump version
  • Loading branch information
acao authored Aug 1, 2022
1 parent 6ab6168 commit a358ac1
Show file tree
Hide file tree
Showing 21 changed files with 382 additions and 96 deletions.
6 changes: 6 additions & 0 deletions .changeset/lovely-dancers-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'vscode-graphql': minor
'vscode-graphql-syntax': patch
---

move vscode grammars, basic language support and snippets to graphql syntax extension. `vscode-graphql` now depends on this extension, and provides language server support in addition. this allows alternative LSP servers and non-LSP graphql extensions to use our highlighting only, or allows users to just install the syntax highlighting extension if they don't need LSP server features.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ packages/graphiql/typedoc
dist
esm
bundle
*.vsix

cypress/screenshots
lerna-debug.log
**/tsconfig.tsbuildinfo
Expand Down
1 change: 1 addition & 0 deletions custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cshaver
dhanani
divy
divyenduz
Divyendu
dotan
dotansimha
gillam
Expand Down
21 changes: 21 additions & 0 deletions packages/graphiql-react/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 GraphQL Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions packages/graphiql-toolkit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 GraphQL Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions packages/vscode-graphql-syntax/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 GraphQL Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
159 changes: 159 additions & 0 deletions packages/vscode-graphql-syntax/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# GraphQL Syntax Support

Adds full GraphQL syntax highlighting and language support such as bracket matching.

- Supports `.graphql`/`.gql`/`.graphqls` highlighting
- [Javascript, Typescript & JSX/TSX](#ts) & Vue
- ReasonML/ReScript (`%graphql()` )
- Python
- PHP
- [Markdown](#markdown)

You'll want to install this if you do not use `graphql-config`, or want to use the highlighting with other extensions than `vscode-graphql`

## Embedded Language Usage

<span id="ts">
### Javascript & Typescript

The following delimiters are accepted for syntax highlighting. If you are using any of these patterns and they do not work, please open an issue!

#### Template Literal Expressions

```ts
const query = gql`
{
id
}
`;
```

you can use these template tag literal expressions anywhere you like of course

```ts
useFancyGraphQLClient(
graphql`
{
id
}
`, {
networkStrategy: 🚀
}
)
```

```ts
const query = gql.experimental`{ id }`;
```

and in typescript, template tag expressions with type arguments

```ts
const query = gql<MyType>`
{
id
}
`;
```

#### Function Expressions

as well as normal function expressions with template literals

```ts
gql(`{ id }`);
```

```ts
graphql(
`
{
id
}
`,
);
```

there is a bug with function expressions with type arguments like these that we need to fix:

```ts
gql<MyType>(`{ id }`);
```

Note, inline `""` and `''` string literals could also be delimited if needed, but we currently only delimit graphql template strings for obvious reasons

#### Comment-Delimited patterns

```ts
/* GraphiQL */
const query = `
{ id }
`;
```

```ts
const query = `#graphql
{ id }
`;
```

For full autocompletion, validation and other features, you can install `GraphQL.vscode-graphql`, which depends on this extension

<span id="markdown">

### Markdown

#### backtick code blocks

````markdown
# Hello Jan

```graphql
query MyQuery {}
```
````

#### embedded graphql in js & ts codeblocks

simple js/ts`gql` & `graphql` template tag expression support inside any backtick codeblocks.

````markdown
# Hello Jan

```js
string : X = gql`
{
its {
query
time
}
}
```
````

## Other languages

We actually support other languages than this! just need to extend this readme even further! 🥵

## Publishing Notes

Note: this extension has temporarily been published from [this PR](https://github.com/graphql/graphiql/pull/2573) until we are ready to re-release `vscode-graphql` with it as well.

## Contributing

Feel free to open a PR to fix, enhance any language support, or even add new languages 😍

see:

- [the grammars](grammars/)
- [the applicable vscode docs](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)

## Usage Note

We would love for the other graphql extension authors to freely use this syntax extension as well! Even if your extension is designed to replace `vscode-graphql`, or if it's designed for other other purposes. It uses an MIT license, but attribution is always a nice gesture to the original authors :)

## License

MIT License

Copyright 2022 GraphQL Contributors
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{
"name": "taggedTemplates",
"contentName": "meta.embedded.block.graphql",
"begin": "(`)(#graphql)",
"begin": "(`|')(#graphql)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.string.template.begin.js"
Expand All @@ -79,7 +79,7 @@
"name": "comment.line.graphql.js"
}
},
"end": "`",
"end": "(`|')",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.template.end.js"
Expand Down
128 changes: 128 additions & 0 deletions packages/vscode-graphql-syntax/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"name": "vscode-graphql-syntax",
"version": "1.0.3",
"displayName": "GraphQL: Syntax Highlighting",
"description": "Adds syntax highlighting support for .graphql & embedded support for javascript, typescript, vue, markdown, python, php, reason, ocaml and rescript",
"publisher": "GraphQL",
"license": "MIT",
"engines": {
"vscode": "^1.63.0"
},
"icon": "assets/images/logo.png",
"contributors": [
{
"name": "Divyendu Singh",
"url": "https://www.divyendusingh.com/"
}
],
"galleryBanner": {
"color": "#032539",
"theme": "dark"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [
{
"id": "graphql",
"extensions": [
".gql",
".graphql",
".graphqls"
],
"aliases": [
"GraphQL",
"graphql"
],
"configuration": "./language/language-configuration.json"
}
],
"grammars": [
{
"language": "graphql",
"path": "./grammars/graphql.json",
"scopeName": "source.graphql"
},
{
"injectTo": [
"source.js",
"source.ts",
"source.js.jsx",
"source.tsx",
"source.vue",
"source.svelte"
],
"scopeName": "inline.graphql",
"path": "./grammars/graphql.js.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
},
{
"injectTo": [
"source.reason",
"source.ocaml"
],
"scopeName": "inline.graphql.re",
"path": "./grammars/graphql.re.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
},
{
"injectTo": [
"source.rescript"
],
"scopeName": "inline.graphql.res",
"path": "./grammars/graphql.rescript.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
},
{
"injectTo": [
"text.html.markdown"
],
"scopeName": "markdown.graphql.codeblock",
"path": "./grammars/graphql.markdown.codeblock.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
},
{
"injectTo": [
"source.python"
],
"scopeName": "inline.graphql.python",
"path": "./grammars/graphql.python.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
},
{
"injectTo": [
"text.html.php"
],
"scopeName": "inline.graphql.php",
"path": "./grammars/graphql.php.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
}
]
},
"repository": {
"type": "git",
"url": "https://github.com/graphql/graphiql",
"directory": "packages/vscode-graphql-syntax"
},
"homepage": "https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/README.md",
"scripts": {
"vsce:package": "vsce package --yarn",
"vsce:prepublish": "npm run vsce:package",
"vsce:publish": "vsce publish --yarn",
"open-vsx:publish": "ovsx publish",
"release": "npm run vsce:publish && npm run open-vsx:publish"
}
}
Loading

0 comments on commit a358ac1

Please sign in to comment.