@@ -46,7 +46,7 @@ import qualified Text.Fuzzy.Parallel as Fuzzy
46
46
-- ----------------------------------------------------------------
47
47
48
48
{- | Takes information about the completion status within the file
49
- and finds the correct completer to be applied
49
+ and finds the correct completer to be applied.
50
50
-}
51
51
contextToCompleter :: Context -> Completer
52
52
-- if we are in the top level of the cabal file and not in a keyword context,
@@ -169,6 +169,9 @@ currentLevel (cur : xs)
169
169
| otherwise -> Just (t, Just $ T. strip n)
170
170
Nothing -> Nothing
171
171
172
+ {- | Creates a CompletionItem with the given text as the label
173
+ where the completion item kind is keyword.
174
+ -}
172
175
mkDefaultCompletionItem :: T. Text -> LSP. CompletionItem
173
176
mkDefaultCompletionItem label = LSP. CompletionItem
174
177
{ Compls. _label = label
@@ -223,7 +226,7 @@ splitAtPosition pos ls = do
223
226
}
224
227
225
228
{- | Takes a line of text and removes the last partially
226
- written word to be completed
229
+ written word to be completed.
227
230
-}
228
231
stripPartiallyWritten :: T. Text -> T. Text
229
232
stripPartiallyWritten = T. dropWhileEnd (\ y -> (y /= ' ' ) && (y /= ' :' ))
@@ -267,6 +270,7 @@ getCabalPrefixInfo fp prefixInfo =
267
270
-- otherwise we parse until a space occurs
268
271
stopConditionChars = apostropheOrSpaceSeparator : [' ,' , ' :' ]
269
272
273
+ -- | Calculates how many spaces the currently completed item is indented.
270
274
completionIndentation :: CabalPrefixInfo -> Int
271
275
completionIndentation prefInfo = fromIntegral (pos ^. JL. character) - (T. length $ completionPrefix prefInfo)
272
276
where
@@ -293,14 +297,15 @@ constantCompleter completions _ cData = do
293
297
range = completionRange prefInfo
294
298
pure $ map (mkSimpleCompletionItem range . Fuzzy. original) scored
295
299
300
+ -- | Completer to be used for the name field's value
296
301
nameCompleter :: Completer
297
302
nameCompleter _ cData = do
298
303
let scored = Fuzzy. simpleFilter 1000 10 (completionPrefix prefInfo) [completionFileName prefInfo]
299
304
prefInfo = cabalPrefixInfo cData
300
305
range = completionRange prefInfo
301
306
pure $ map (mkSimpleCompletionItem range . Fuzzy. original) scored
302
307
303
- -- maps snippet triggerwords to match on with their completers
308
+ -- | Maps snippet triggerwords with their completers
304
309
snippetCompleter :: Completer
305
310
snippetCompleter _ cData = do
306
311
let scored = Fuzzy. simpleFilter 1000 10 (completionPrefix prefInfo) $ Map. keys snippetMap
@@ -408,6 +413,9 @@ filePathCompleter recorder cData = do
408
413
)
409
414
410
415
{- | Completer to be used when module paths can be completed for the field.
416
+
417
+ Takes an extraction function which extracts the source directories
418
+ to be used by the completer.
411
419
-}
412
420
modulesCompleter :: (GenericPackageDescription -> [FilePath ]) -> Completer
413
421
modulesCompleter extractionFunction recorder cData = do
@@ -425,8 +433,10 @@ modulesCompleter extractionFunction recorder cData = do
425
433
extras = shakeExtras (ideState cData)
426
434
prefInfo = cabalPrefixInfo cData
427
435
428
- exposedModuleExtraction :: GenericPackageDescription -> [FilePath ]
429
- exposedModuleExtraction gpd =
436
+ {- | Extracts the source directories of the library stanza.
437
+ -}
438
+ sourceDirsExtractionLibrary :: GenericPackageDescription -> [FilePath ]
439
+ sourceDirsExtractionLibrary gpd =
430
440
-- we use condLibrary to get the information contained in the library stanza
431
441
-- since the library in PackageDescription is not populated by us
432
442
case libM of
@@ -436,9 +446,11 @@ exposedModuleExtraction gpd =
436
446
where
437
447
libM = condLibrary gpd
438
448
439
- otherModulesExtractionExecutable :: Maybe T. Text -> GenericPackageDescription -> [FilePath ]
440
- otherModulesExtractionExecutable Nothing _ = []
441
- otherModulesExtractionExecutable (Just name) gpd
449
+ {- | Extracts the source directories of the executable stanza with the given name.
450
+ -}
451
+ sourceDirsExtractionExecutable :: Maybe T. Text -> GenericPackageDescription -> [FilePath ]
452
+ sourceDirsExtractionExecutable Nothing _ = []
453
+ sourceDirsExtractionExecutable (Just name) gpd
442
454
| exeName executable == (mkUnqualComponentName $ T. unpack name) = map getSymbolicPath $ hsSourceDirs $ buildInfo executable
443
455
| otherwise = []
444
456
where
@@ -452,9 +464,11 @@ otherModulesExtractionExecutable (Just name) gpd
452
464
)
453
465
execsM
454
466
455
- otherModulesExtractionTestSuite :: Maybe T. Text -> GenericPackageDescription -> [FilePath ]
456
- otherModulesExtractionTestSuite Nothing _ = []
457
- otherModulesExtractionTestSuite (Just name) gpd
467
+ {- | Extracts the source directories of the test suite stanza with the given name.
468
+ -}
469
+ sourceDirsExtractionTestSuite :: Maybe T. Text -> GenericPackageDescription -> [FilePath ]
470
+ sourceDirsExtractionTestSuite Nothing _ = []
471
+ sourceDirsExtractionTestSuite (Just name) gpd
458
472
| testName testSuite == (mkUnqualComponentName $ T. unpack name) = map getSymbolicPath $ hsSourceDirs $ testBuildInfo testSuite
459
473
| otherwise = []
460
474
where
@@ -468,9 +482,11 @@ otherModulesExtractionTestSuite (Just name) gpd
468
482
)
469
483
testSuitesM
470
484
471
- otherModulesExtractionBenchmark :: Maybe T. Text -> GenericPackageDescription -> [FilePath ]
472
- otherModulesExtractionBenchmark Nothing _ = []
473
- otherModulesExtractionBenchmark (Just name) gpd
485
+ {- | Extracts the source directories of benchmark stanza with the given name.
486
+ -}
487
+ sourceDirsExtractionBenchmark :: Maybe T. Text -> GenericPackageDescription -> [FilePath ]
488
+ sourceDirsExtractionBenchmark Nothing _ = []
489
+ sourceDirsExtractionBenchmark (Just name) gpd
474
490
| benchmarkName bMark == (mkUnqualComponentName $ T. unpack name) = map getSymbolicPath $ hsSourceDirs $ benchmarkBuildInfo bMark
475
491
| otherwise = []
476
492
where
@@ -526,7 +542,7 @@ cabalVersionKeyword =
526
542
cabalKeywords :: Map KeyWordName Completer
527
543
cabalKeywords =
528
544
Map. fromList
529
- [ (" name:" , nameCompleter) -- TODO: should complete to filename, needs meta info
545
+ [ (" name:" , nameCompleter)
530
546
, (" version:" , noopCompleter)
531
547
, (" build-type:" , constantCompleter [" Simple" , " Custom" , " Configure" , " Make" ])
532
548
, (" license:" , weightedConstantCompleter licenseNames weightedLicenseNames)
@@ -557,13 +573,13 @@ stanzaKeywordMap =
557
573
[
558
574
( " library"
559
575
, \ _ -> Map. fromList $
560
- [ (" exposed-modules:" , modulesCompleter exposedModuleExtraction ) -- identifier list
576
+ [ (" exposed-modules:" , modulesCompleter sourceDirsExtractionLibrary ) -- identifier list
561
577
, (" virtual-modules:" , noopCompleter)
562
578
, (" exposed:" , constantCompleter [" True" , " False" ])
563
579
, (" visibility:" , constantCompleter [" private" , " public" ])
564
580
, (" reexported-modules:" , noopCompleter) -- export list, i.e. "orig-okg:Name as NewName"
565
581
, (" signatures:" , noopCompleter) -- list of signatures
566
- , (" other-modules:" , modulesCompleter exposedModuleExtraction )
582
+ , (" other-modules:" , modulesCompleter sourceDirsExtractionLibrary )
567
583
]
568
584
++ libExecTestBenchCommons
569
585
)
@@ -572,7 +588,7 @@ stanzaKeywordMap =
572
588
, \ n -> Map. fromList $
573
589
[ (" main-is:" , filePathCompleter)
574
590
, (" scope:" , constantCompleter [" public" , " private" ])
575
- , (" other-modules:" , modulesCompleter (otherModulesExtractionExecutable n))
591
+ , (" other-modules:" , modulesCompleter (sourceDirsExtractionExecutable n))
576
592
]
577
593
++ libExecTestBenchCommons
578
594
)
@@ -581,7 +597,7 @@ stanzaKeywordMap =
581
597
, \ n -> Map. fromList $
582
598
[ (" type:" , constantCompleter [" exitcode-stdio-1.0" , " detailed-0.9" ])
583
599
, (" main-is:" , filePathCompleter)
584
- , (" other-modules:" , modulesCompleter (otherModulesExtractionTestSuite n))
600
+ , (" other-modules:" , modulesCompleter (sourceDirsExtractionTestSuite n))
585
601
]
586
602
++ libExecTestBenchCommons
587
603
)
@@ -590,7 +606,7 @@ stanzaKeywordMap =
590
606
, \ n -> Map. fromList $
591
607
[ (" type:" , noopCompleter)
592
608
, (" main-is:" , filePathCompleter)
593
- , (" other-modules:" , modulesCompleter (otherModulesExtractionBenchmark n))
609
+ , (" other-modules:" , modulesCompleter (sourceDirsExtractionBenchmark n))
594
610
]
595
611
++ libExecTestBenchCommons
596
612
)
0 commit comments