@@ -357,105 +357,108 @@ contextTests =
357
357
[ testCase " Empty File - Start" $ do
358
358
-- for a completely empty file, the context needs to
359
359
-- be top level without a specified keyword
360
- ctx <- callGetContext (Position 0 0 ) [" " ]
360
+ ctx <- callGetContext (Position 0 0 ) " " [" " ]
361
361
ctx @?= (TopLevel , None )
362
362
, testCase " Cabal version keyword - no value, no space after :" $ do
363
363
-- on a file, where the keyword is already written
364
364
-- the context should still be toplevel but the keyword should be recognized
365
- ctx <- callGetContext (Position 0 14 ) [" cabal-version:" ]
365
+ ctx <- callGetContext (Position 0 14 ) " " [" cabal-version:" ]
366
366
ctx @?= (TopLevel , KeyWord " cabal-version:" )
367
367
, testCase " Cabal version keyword - cursor in keyword" $ do
368
368
-- on a file, where the keyword is already written
369
369
-- but the cursor is in the middle of the keyword,
370
370
-- we are not in a keyword context
371
- ctx <- callGetContext (Position 0 5 ) [" cabal-version:" ]
371
+ ctx <- callGetContext (Position 0 5 ) " cabal " [" cabal-version:" ]
372
372
ctx @?= (TopLevel , None )
373
373
, testCase " Cabal version keyword - no value, many spaces" $ do
374
374
-- on a file, where the "cabal-version:" keyword is already written
375
375
-- the context should still be top level but the keyword should be recognized
376
- ctx <- callGetContext (Position 0 45 ) [" cabal-version:" <> T. replicate 50 " " ]
376
+ ctx <- callGetContext (Position 0 45 ) ( " " ) [" cabal-version:" <> T. replicate 50 " " ]
377
377
ctx @?= (TopLevel , KeyWord " cabal-version:" )
378
378
, testCase " Cabal version keyword - keyword partly written" $ do
379
379
-- in the first line of the file, if the keyword
380
380
-- has not been written completely, the keyword context
381
381
-- should still be None
382
- ctx <- callGetContext (Position 0 5 ) [" cabal" ]
382
+ ctx <- callGetContext (Position 0 5 ) " cabal " [" cabal" ]
383
383
ctx @?= (TopLevel , None )
384
384
, testCase " Cabal version keyword - value partly written" $ do
385
385
-- in the first line of the file, if the keyword
386
386
-- has not been written completely, the keyword context
387
387
-- should still be None
388
- ctx <- callGetContext (Position 0 17 ) [" cabal-version: 1." ]
388
+ ctx <- callGetContext (Position 0 17 ) " 1. " [" cabal-version: 1." ]
389
389
ctx @?= (TopLevel , KeyWord " cabal-version:" )
390
390
, testCase " Inside Stanza - no keyword" $ do
391
391
-- on a file, where the library stanza has been defined
392
392
-- but no keyword is defined afterwards, the stanza context should be recognized
393
- ctx <- callGetContext (Position 3 2 ) libraryStanzaData
393
+ ctx <- callGetContext (Position 3 2 ) " " libraryStanzaData
394
394
ctx @?= (Stanza " library" , None )
395
395
, testCase " Inside Stanza - keyword, no value" $ do
396
396
-- on a file, where the library stanza and a keyword
397
397
-- has been defined, the keyword and stanza should be recognized
398
- ctx <- callGetContext (Position 4 21 ) libraryStanzaData
398
+ ctx <- callGetContext (Position 4 21 ) " " libraryStanzaData
399
399
ctx @?= (Stanza " library" , KeyWord " build-depends:" )
400
400
, expectFailBecause " While not valid, it is not that important to make the code more complicated for this" $
401
401
testCase " Cabal version keyword - no value, next line" $ do
402
402
-- if the cabal version keyword has been written but without a value,
403
403
-- in the next line we still should be in top level context with no keyword
404
404
-- since the cabal version keyword and value pair need to be in the same line
405
- ctx <- callGetContext (Position 1 2 ) [" cabal-version:" , " " ]
405
+ ctx <- callGetContext (Position 1 2 ) " " [" cabal-version:" , " " ]
406
406
ctx @?= (TopLevel , None )
407
407
, testCase " Non-cabal-version keyword - no value, next line indentented position" $ do
408
408
-- if a keyword, other than the cabal version keyword has been written
409
409
-- with no value, in the next line we still should be in top level keyword context
410
410
-- of the keyword with no value, since its value may be written in the next line
411
- ctx <- callGetContext (Position 2 4 ) topLevelData
411
+ ctx <- callGetContext (Position 2 4 ) " " topLevelData
412
412
ctx @?= (TopLevel , KeyWord " name:" )
413
413
, testCase " Non-cabal-version keyword - no value, next line at start" $ do
414
414
-- if a keyword, other than the cabal version keyword has been written
415
415
-- with no value, in the next line we still should be in top level context
416
416
-- but not the keyword's, since it is not viable to write a value for a
417
417
-- keyword a the start of the next line
418
- ctx <- callGetContext (Position 2 0 ) topLevelData
418
+ ctx <- callGetContext (Position 2 0 ) " " topLevelData
419
+ ctx @?= (TopLevel , None )
420
+ , testCase " Toplevel after stanza partially written" $ do
421
+ ctx <- callGetContext (Position 6 2 ) " ma" libraryStanzaData
419
422
ctx @?= (TopLevel , None )
420
423
, testCase " Non-cabal-version keyword - no value, multiple lines between" $ do
421
424
-- if a keyword, other than the cabal version keyword has been written
422
425
-- with no value, even with multiple lines in between we can still write the
423
426
-- value corresponding to the keyword
424
- ctx <- callGetContext (Position 5 4 ) topLevelData
427
+ ctx <- callGetContext (Position 5 4 ) " " topLevelData
425
428
ctx @?= (TopLevel , KeyWord " name:" )
426
429
, testCase " Keyword inside stanza - cursor indented more than keyword in next line" $ do
427
430
-- if a keyword, other than the cabal version keyword has been written
428
431
-- in a stanza context with no value, then the value may be written in the next line,
429
432
-- when the cursor is indented more than the keyword
430
- ctx <- callGetContext (Position 5 8 ) libraryStanzaData
433
+ ctx <- callGetContext (Position 5 8 ) " " libraryStanzaData
431
434
ctx @?= (Stanza " library" , KeyWord " build-depends:" )
432
435
, testCase " Keyword inside stanza - cursor indented less than keyword in next line" $ do
433
436
-- if a keyword, other than the cabal version keyword has been written
434
437
-- in a stanza context with no value, then the value may not be written in the next line,
435
438
-- when the cursor is indented less than the keyword
436
- ctx <- callGetContext (Position 5 2 ) libraryStanzaData
439
+ ctx <- callGetContext (Position 5 2 ) " " libraryStanzaData
437
440
ctx @?= (Stanza " library" , None )
438
441
, testCase " Keyword inside stanza - cursor at start of next line" $ do
439
442
-- in a stanza context with no value the value may not be written in the next line,
440
443
-- when the cursor is not indented and we are in the top level context
441
- ctx <- callGetContext (Position 5 0 ) libraryStanzaData
444
+ ctx <- callGetContext (Position 5 0 ) " " libraryStanzaData
442
445
ctx @?= (TopLevel , None )
443
446
, testCase " Top level - cursor in later line with partially written value" $ do
444
- ctx <- callGetContext (Position 5 13 ) topLevelData
447
+ ctx <- callGetContext (Position 5 13 ) " eee " topLevelData
445
448
ctx @?= (TopLevel , KeyWord " name:" )
446
449
]
447
450
where
448
- callGetContext :: Position -> [T. Text ] -> IO Context
449
- callGetContext pos ls = do
450
- runMaybeT (getContext mempty (simpleCabalPrefixInfo pos) (Rope. fromText $ T. unlines ls))
451
+ callGetContext :: Position -> T. Text -> [T. Text ] -> IO Context
452
+ callGetContext pos pref ls = do
453
+ runMaybeT (getContext mempty (simpleCabalPrefixInfo pos pref ) (Rope. fromText $ T. unlines ls))
451
454
>>= \ case
452
455
Nothing -> assertFailure " Context must be found"
453
456
Just ctx -> pure ctx
454
457
455
- simpleCabalPrefixInfo :: Position -> CabalPrefixInfo
456
- simpleCabalPrefixInfo pos =
458
+ simpleCabalPrefixInfo :: Position -> T. Text -> CabalPrefixInfo
459
+ simpleCabalPrefixInfo pos prefix =
457
460
CabalPrefixInfo
458
- { completionPrefix = " "
461
+ { completionPrefix = prefix
459
462
, completionSuffix = Nothing
460
463
, completionCursorPosition = pos
461
464
, completionRange = Range pos (Position 0 0 )
@@ -606,6 +609,7 @@ libraryStanzaData =
606
609
, " default-language: Haskell98"
607
610
, " build-depends: "
608
611
, " "
612
+ , " ma "
609
613
]
610
614
611
615
topLevelData :: [T. Text ]
0 commit comments