Skip to content
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

Dart port of syntax highlighting #3612

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/vscode-graphql-syntax/grammars/graphql.dart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"scopeName": "inline.graphql.dart",
"injectionSelector": "L:(meta.embedded.block.dart | source.dart -string -comment)",
"patterns": [
{
"begin": "(''')(#graphql)",
"beginCaptures": {
"1": {
"name": "string.interpolated.triple.single.dart"
},
"2": {
"name": "comment.line.graphql.js"
}
},
"end": "(''')",
"endCaptures": {
"1": {
"name": "string.interpolated.triple.single.dart"
}
},
"patterns": [
{
"include": "source.graphql"
}
]
},
{
"begin": "(\"\"\")(#graphql)",
"beginCaptures": {
"1": {
"name": "string.interpolated.triple.double.dart"
},
"2": {
"name": "comment.line.graphql.js"
}
},
"end": "(\"\"\")",
"endCaptures": {
"1": {
"name": "string.interpolated.triple.double.dart"
}
},
"patterns": [
{
"include": "source.graphql"
}
]
}
]
}
6 changes: 6 additions & 0 deletions packages/vscode-graphql-syntax/grammars/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const test = """#graphql
""";

const tet = '''#graphql
''';
11 changes: 11 additions & 0 deletions packages/vscode-graphql-syntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
},
{
"injectTo": [
"source.dart",
"text.html.markdown"
],
"scopeName": "inline.graphql.dart",
"path": "./grammars/graphql.dart.json",
"embeddedLanguages": {
"meta.embedded.block.graphql": "graphql"
}
}
]
},
Expand Down
11 changes: 11 additions & 0 deletions packages/vscode-graphql-syntax/tests/__fixtures__/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const query1 = '''#graphql
query {
id
}
''';

const query2 = """#graphql
query {
id
}
""";
1 change: 1 addition & 0 deletions packages/vscode-graphql-syntax/tests/__fixtures__/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@
name
}
}"""

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`inline.graphql.dart grammar > should tokenize a simple dart file 1`] = `
const query1 = |
''' | string.interpolated.triple.single.dart
#graphql | comment.line.graphql.js
|
query | keyword.operation.graphql
| meta.selectionset.graphql
{ | meta.selectionset.graphql punctuation.operation.graphql
| meta.selectionset.graphql
id | meta.selectionset.graphql variable.graphql
| meta.selectionset.graphql
} | meta.selectionset.graphql punctuation.operation.graphql
''' | string.interpolated.triple.single.dart
; |
|
const query2 = |
""" | string.interpolated.triple.double.dart
#graphql | comment.line.graphql.js
|
query | keyword.operation.graphql
| meta.selectionset.graphql
{ | meta.selectionset.graphql punctuation.operation.graphql
| meta.selectionset.graphql
id | meta.selectionset.graphql variable.graphql
| meta.selectionset.graphql
} | meta.selectionset.graphql punctuation.operation.graphql
""" | string.interpolated.triple.double.dart
; |
|
`;
10 changes: 10 additions & 0 deletions packages/vscode-graphql-syntax/tests/dart-grammar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { tokenizeFile } from './__utilities__/utilities';

describe('inline.graphql.dart grammar', () => {
const scope = 'inline.graphql.dart';

it('should tokenize a simple dart file', async () => {
const result = await tokenizeFile('__fixtures__/test.dart', scope);
expect(result).toMatchSnapshot();
});
});