@@ -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 }
@@ -171,3 +173,46 @@ function maybeCommentedOut(content: string) {
171173 content . split ( "//" ) . length > 1
172174 ) ;
173175}
176+
177+ function extractGraphQLDocumentsFromDartStrings (
178+ document : TextDocument ,
179+ tagName : string
180+ ) : GraphQLDocument [ ] | null {
181+ const text = document . getText ( ) ;
182+
183+ const documents : GraphQLDocument [ ] = [ ] ;
184+
185+ const regExp = new RegExp (
186+ `\\b(${ tagName } \\(\\s*r?("""|'''))([\\s\\S]+?)\\2\\s*\\)` ,
187+ "gm"
188+ ) ;
189+
190+ let result ;
191+ while ( ( result = regExp . exec ( text ) ) !== null ) {
192+ const contents = replacePlaceholdersWithWhiteSpace ( result [ 3 ] ) ;
193+ const position = document . positionAt ( result . index + result [ 1 ] . length ) ;
194+ const locationOffset : SourceLocation = {
195+ line : position . line + 1 ,
196+ column : position . character + 1
197+ } ;
198+ const source = new Source ( contents , document . uri , locationOffset ) ;
199+ documents . push ( new GraphQLDocument ( source ) ) ;
200+ }
201+
202+ if ( documents . length < 1 ) return null ;
203+
204+ return documents ;
205+ }
206+
207+ function replacePlaceholdersWithWhiteSpace ( content : string ) {
208+ return content . replace ( / \$ \{ ( [ \s \S ] + ?) \} / gm, match => {
209+ return Array ( match . length ) . join ( " " ) ;
210+ } ) ;
211+ }
212+
213+ function maybeCommentedOut ( content : string ) {
214+ return (
215+ ( content . indexOf ( "/*" ) > - 1 && content . indexOf ( "*/" ) > - 1 ) ||
216+ content . split ( "//" ) . length > 1
217+ ) ;
218+ }
0 commit comments