@@ -70,6 +70,8 @@ export function extractGraphQLDocuments(
7070 return extractGraphQLDocumentsFromPythonStrings ( document , tagName ) ;
7171 case "ruby" :
7272 return extractGraphQLDocumentsFromRubyStrings ( document , tagName ) ;
73+ case "dart" :
74+ return extractGraphQLDocumentsFromDartStrings ( document , tagName ) ;
7375 default :
7476 return null ;
7577 }
@@ -159,6 +161,36 @@ function extractGraphQLDocumentsFromRubyStrings(
159161 return documents ;
160162}
161163
164+ function extractGraphQLDocumentsFromDartStrings (
165+ document : TextDocument ,
166+ tagName : string
167+ ) : GraphQLDocument [ ] | null {
168+ const text = document . getText ( ) ;
169+
170+ const documents : GraphQLDocument [ ] = [ ] ;
171+
172+ const regExp = new RegExp (
173+ `\\b(${ tagName } \\(\\s*r?("""|'''))([\\s\\S]+?)\\2\\s*\\)` ,
174+ "gm"
175+ ) ;
176+
177+ let result ;
178+ while ( ( result = regExp . exec ( text ) ) !== null ) {
179+ const contents = replacePlaceholdersWithWhiteSpace ( result [ 3 ] ) ;
180+ const position = document . positionAt ( result . index + result [ 1 ] . length ) ;
181+ const locationOffset : SourceLocation = {
182+ line : position . line + 1 ,
183+ column : position . character + 1
184+ } ;
185+ const source = new Source ( contents , document . uri , locationOffset ) ;
186+ documents . push ( new GraphQLDocument ( source ) ) ;
187+ }
188+
189+ if ( documents . length < 1 ) return null ;
190+
191+ return documents ;
192+ }
193+
162194function replacePlaceholdersWithWhiteSpace ( content : string ) {
163195 return content . replace ( / \$ \{ ( [ \s \S ] + ?) \} / gm, match => {
164196 return Array ( match . length ) . join ( " " ) ;
0 commit comments