@@ -65,6 +65,23 @@ Response notOnRequest(RequestContext context) {
6565
6666` ;
6767
68+ /**
69+ * A very long dynamic route with multiple arguments.
70+ */
71+ const longDynamicRouteContent = `
72+ import 'package:dart_frog/dart_frog.dart';
73+
74+ Response onRequest(
75+ RequestContext context,
76+ String id1,
77+ String id2,
78+ String id3,
79+ ) {
80+ return Response(body: 'Welcome to Dart Frog!');
81+ }
82+
83+ ` ;
84+
6885suite ( "RunOnRequestCodeLensProvider" , ( ) => {
6986 let vscodeStub : any ;
7087 let utilsStub : any ;
@@ -246,6 +263,33 @@ suite("RunOnRequestCodeLensProvider", () => {
246263 sinon . assert . match ( codeLens , new CodeLens ( range ) ) ;
247264 } ) ;
248265
266+ test ( "returns the correct CodeLenses on a long dynamic route" , async ( ) => {
267+ const content = longDynamicRouteContent ;
268+ const textDocument = await workspace . openTextDocument ( {
269+ language : "text" ,
270+ content,
271+ } ) ;
272+ document . getText = textDocument . getText . bind ( textDocument ) ;
273+ document . positionAt = textDocument . positionAt . bind ( textDocument ) ;
274+ document . lineAt = textDocument . lineAt . bind ( textDocument ) ;
275+ document . getWordRangeAtPosition =
276+ textDocument . getWordRangeAtPosition . bind ( textDocument ) ;
277+
278+ const provider = new RunOnRequestCodeLensProvider ( ) ;
279+ const result = await provider . provideCodeLenses ( document ) ;
280+
281+ assert . strictEqual ( result . length , 1 ) ;
282+
283+ const codeLens = result [ 0 ] ;
284+
285+ const range = document . getWordRangeAtPosition (
286+ new Position ( 3 , 0 ) ,
287+ provider . regex
288+ ) ! ;
289+
290+ sinon . assert . match ( codeLens , new CodeLens ( range ) ) ;
291+ } ) ;
292+
249293 test ( "returns the correct CodeLenses on an async route" , async ( ) => {
250294 const content = asyncRouteContent ;
251295 const textDocument = await workspace . openTextDocument ( {
@@ -555,6 +599,33 @@ suite("DebugOnRequestCodeLensProvider", () => {
555599 sinon . assert . match ( codeLens , new CodeLens ( range ) ) ;
556600 } ) ;
557601
602+ test ( "returns the correct CodeLenses on a long dynamic route" , async ( ) => {
603+ const content = longDynamicRouteContent ;
604+ const textDocument = await workspace . openTextDocument ( {
605+ language : "text" ,
606+ content,
607+ } ) ;
608+ document . getText = textDocument . getText . bind ( textDocument ) ;
609+ document . positionAt = textDocument . positionAt . bind ( textDocument ) ;
610+ document . lineAt = textDocument . lineAt . bind ( textDocument ) ;
611+ document . getWordRangeAtPosition =
612+ textDocument . getWordRangeAtPosition . bind ( textDocument ) ;
613+
614+ const provider = new DebugOnRequestCodeLensProvider ( ) ;
615+ const result = await provider . provideCodeLenses ( document ) ;
616+
617+ assert . strictEqual ( result . length , 1 ) ;
618+
619+ const codeLens = result [ 0 ] ;
620+
621+ const range = document . getWordRangeAtPosition (
622+ new Position ( 3 , 0 ) ,
623+ provider . regex
624+ ) ! ;
625+
626+ sinon . assert . match ( codeLens , new CodeLens ( range ) ) ;
627+ } ) ;
628+
558629 test ( "returns no CodeLenses on a non route file" , async ( ) => {
559630 const content = invalidRouteContent ;
560631 const textDocument = await workspace . openTextDocument ( {
0 commit comments