Skip to content

Commit d5db58a

Browse files
committed
Add support for other-module field of all viable stanzas
1 parent 093f2d5 commit d5db58a

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completions.hs

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import Distribution.PackageDescription (CondTree (..),
2525
GenericPackageDescription (..),
2626
Library (libBuildInfo),
2727
hsSourceDirs)
28+
import Distribution.Types.Benchmark (Benchmark (..))
2829
import Distribution.Types.Executable (Executable (..))
30+
import Distribution.Types.TestSuite (TestSuite (..))
2931
import Distribution.Types.UnqualComponentName
3032
import Distribution.Utils.Path (getSymbolicPath)
3133
import Ide.Plugin.Cabal.FilepathCompletions
@@ -434,9 +436,9 @@ exposedModuleExtraction gpd =
434436
where
435437
libM = condLibrary gpd
436438

437-
otherModulesExtraction :: Maybe T.Text -> GenericPackageDescription -> [FilePath]
438-
otherModulesExtraction Nothing _ = []
439-
otherModulesExtraction (Just name) gpd
439+
otherModulesExtractionExecutable :: Maybe T.Text -> GenericPackageDescription -> [FilePath]
440+
otherModulesExtractionExecutable Nothing _ = []
441+
otherModulesExtractionExecutable (Just name) gpd
440442
| exeName executable == (mkUnqualComponentName $ T.unpack name) = map getSymbolicPath $ hsSourceDirs $ buildInfo executable
441443
| otherwise = []
442444
where
@@ -450,6 +452,38 @@ otherModulesExtraction (Just name) gpd
450452
)
451453
execsM
452454

455+
otherModulesExtractionTestSuite :: Maybe T.Text -> GenericPackageDescription -> [FilePath]
456+
otherModulesExtractionTestSuite Nothing _ = []
457+
otherModulesExtractionTestSuite (Just name) gpd
458+
| testName testSuite == (mkUnqualComponentName $ T.unpack name) = map getSymbolicPath $ hsSourceDirs $ testBuildInfo testSuite
459+
| otherwise = []
460+
where
461+
testSuite = condTreeData $ snd $ fromJust res
462+
testSuitesM = condTestSuites gpd
463+
res =
464+
List.find
465+
(\(_, cTree) -> do
466+
let testsName = testName $ condTreeData cTree
467+
testsName == (mkUnqualComponentName $ T.unpack name)
468+
)
469+
testSuitesM
470+
471+
otherModulesExtractionBenchmark :: Maybe T.Text -> GenericPackageDescription -> [FilePath]
472+
otherModulesExtractionBenchmark Nothing _ = []
473+
otherModulesExtractionBenchmark (Just name) gpd
474+
| benchmarkName bMark == (mkUnqualComponentName $ T.unpack name) = map getSymbolicPath $ hsSourceDirs $ benchmarkBuildInfo bMark
475+
| otherwise = []
476+
where
477+
bMark = condTreeData $ snd $ fromJust res
478+
bMarksM = condBenchmarks gpd
479+
res =
480+
List.find
481+
(\(_, cTree) -> do
482+
let bMarkName = benchmarkName $ condTreeData cTree
483+
bMarkName == (mkUnqualComponentName $ T.unpack name)
484+
)
485+
bMarksM
486+
453487
{- | Completer to be used when a directory can be completed for the field,
454488
takes the file path of the directory to start from.
455489
Only completes directories.
@@ -522,39 +556,43 @@ stanzaKeywordMap =
522556
Map.fromList
523557
[
524558
( "library"
525-
, \n -> Map.fromList $
559+
, \_ -> Map.fromList $
526560
[ ("exposed-modules:", modulesCompleter exposedModuleExtraction) -- identifier list
527561
, ("virtual-modules:", noopCompleter)
528562
, ("exposed:", constantCompleter ["True", "False"])
529563
, ("visibility:", constantCompleter ["private", "public"])
530564
, ("reexported-modules:", noopCompleter) -- export list, i.e. "orig-okg:Name as NewName"
531565
, ("signatures:", noopCompleter) -- list of signatures
566+
, ("other-modules:", modulesCompleter exposedModuleExtraction)
532567
]
533-
++ libExecTestBenchCommons n
568+
++ libExecTestBenchCommons
534569
)
535570
,
536571
( "executable"
537572
, \n -> Map.fromList $
538573
[ ("main-is:", filePathCompleter)
539574
, ("scope:", constantCompleter ["public", "private"])
575+
, ("other-modules:", modulesCompleter (otherModulesExtractionExecutable n))
540576
]
541-
++ libExecTestBenchCommons n
577+
++ libExecTestBenchCommons
542578
)
543579
,
544580
( "test-suite"
545581
, \n -> Map.fromList $
546582
[ ("type:", constantCompleter ["exitcode-stdio-1.0", "detailed-0.9"])
547583
, ("main-is:", filePathCompleter)
584+
, ("other-modules:", modulesCompleter (otherModulesExtractionTestSuite n))
548585
]
549-
++ libExecTestBenchCommons n
586+
++ libExecTestBenchCommons
550587
)
551588
,
552589
( "benchmark"
553590
, \n -> Map.fromList $
554591
[ ("type:", noopCompleter)
555592
, ("main-is:", filePathCompleter)
593+
, ("other-modules:", modulesCompleter (otherModulesExtractionBenchmark n))
556594
]
557-
++ libExecTestBenchCommons n
595+
++ libExecTestBenchCommons
558596
)
559597
,
560598
( "foreign-library"
@@ -604,9 +642,8 @@ stanzaKeywordMap =
604642
)
605643
]
606644
where
607-
libExecTestBenchCommons n =
645+
libExecTestBenchCommons =
608646
[ ("build-depends:", noopCompleter)
609-
, ("other-modules:", modulesCompleter (otherModulesExtraction n))
610647
, ("hs-source-dirs:", directoryCompleter)
611648
, ("default-extensions:", noopCompleter)
612649
, ("other-extensions:", noopCompleter)

0 commit comments

Comments
 (0)