Skip to content

Commit

Permalink
Dart port of syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
woprandi committed May 26, 2024
1 parent 03ab3a6 commit aeecbbc
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 0 deletions.
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
''';
3 changes: 3 additions & 0 deletions packages/vscode-graphql-syntax/grammars/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test = """#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 @@ -136,6 +136,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
}
}"""

6 changes: 6 additions & 0 deletions packages/vscode-graphql-syntax/tests/__fixtures__/test2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const plop = """#graphql
query {
id
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();
});
});

0 comments on commit aeecbbc

Please sign in to comment.