11{-# LANGUAGE OverloadedStrings #-}
2- {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
3-
4- {-# HLINT ignore "Redundant bracket" #-}
52
63module Ide.Plugin.Cabal.Completion.Data where
74
@@ -19,6 +16,17 @@ import Ide.Plugin.Cabal.Completion.Completer.Types (Completer)
1916import Ide.Plugin.Cabal.Completion.Types
2017import Ide.Plugin.Cabal.LicenseSuggest (licenseNames )
2118
19+ -- | Ad-hoc data type for modelling the available top-level stanzas.
20+ -- Not intended right now for anything else but to avoid string
21+ -- comparisons in 'stanzaKeywordMap' and 'libExecTestBenchCommons'.
22+ data TopLevelStanza
23+ = Library
24+ | Executable
25+ | TestSuite
26+ | Benchmark
27+ | ForeignLib
28+ | Common
29+
2230-- ----------------------------------------------------------------
2331-- Completion Data
2432-- ----------------------------------------------------------------
@@ -71,12 +79,13 @@ cabalKeywords =
7179stanzaKeywordMap :: Map StanzaType (Map KeyWordName Completer )
7280stanzaKeywordMap =
7381 Map. fromList
74- [ (" library" , libraryFields <> libExecTestBenchCommons),
75- (" executable" , executableFields <> libExecTestBenchCommons),
76- (" test-suite" , testSuiteFields <> libExecTestBenchCommons),
77- (" benchmark" , benchmarkFields <> libExecTestBenchCommons),
78- (" foreign-library" , foreignLibraryFields <> libExecTestBenchCommons),
79- (" common" , libExecTestBenchCommons),
82+ [ (" library" , libraryFields <> libExecTestBenchCommons Library ),
83+ (" executable" , executableFields <> libExecTestBenchCommons Executable ),
84+ (" test-suite" , testSuiteFields <> libExecTestBenchCommons TestSuite ),
85+ (" benchmark" , benchmarkFields <> libExecTestBenchCommons Benchmark ),
86+ (" foreign-library" , foreignLibraryFields <> libExecTestBenchCommons ForeignLib ),
87+ (" common" , libExecTestBenchCommons Library ),
88+ (" common" , libExecTestBenchCommons Common ),
8089 (" flag" , flagFields),
8190 (" source-repository" , sourceRepositoryFields)
8291 ]
@@ -162,8 +171,8 @@ flagFields =
162171 (" lib-version-linux:" , noopCompleter)
163172 ]
164173
165- libExecTestBenchCommons :: Map KeyWordName Completer
166- libExecTestBenchCommons =
174+ libExecTestBenchCommons :: TopLevelStanza -> Map KeyWordName Completer
175+ libExecTestBenchCommons st =
167176 Map. fromList
168177 [ (" import:" , importCompleter),
169178 (" build-depends:" , noopCompleter),
@@ -183,6 +192,8 @@ libExecTestBenchCommons =
183192 (" includes:" , filePathCompleter),
184193 (" install-includes:" , filePathCompleter),
185194 (" include-dirs:" , directoryCompleter),
195+ (" autogen-includes:" , filePathCompleter),
196+ (" autogen-modules:" , moduleCompleterByTopLevelStanza),
186197 (" c-sources:" , filePathCompleter),
187198 (" cxx-sources:" , filePathCompleter),
188199 (" asm-sources:" , filePathCompleter),
@@ -203,6 +214,26 @@ libExecTestBenchCommons =
203214 (" extra-framework-dirs:" , directoryCompleter),
204215 (" mixins:" , noopCompleter)
205216 ]
217+ where
218+ --
219+ moduleCompleterByTopLevelStanza = case st of
220+ Library -> modulesCompleter sourceDirsExtractionLibrary
221+ Executable -> modulesCompleter sourceDirsExtractionExecutable
222+ TestSuite -> modulesCompleter sourceDirsExtractionTestSuite
223+ Benchmark -> modulesCompleter sourceDirsExtractionBenchmark
224+ ForeignLib -> modulesCompleter sourceDirsExtractionForeignLib
225+ Common ->
226+ -- TODO: We can't provide a module completer because we provide
227+ -- module completions based on the "hs-source-dirs" after parsing the file,
228+ -- i.e. based on the 'PackageDescription'.
229+ -- "common" stanzas are erased in the 'PackageDescription' representation,
230+ -- thus we can't provide accurate module completers right now, as we don't
231+ -- know what the 'hs-source-dirs' in the "common" stanza are.
232+ --
233+ -- A potential fix would be to introduce an intermediate representation that
234+ -- parses the '.cabal' file s.t. that we have access to the 'hs-source-dirs',
235+ -- but not have erased the "common" stanza.
236+ noopCompleter
206237
207238-- | Contains a map of the most commonly used licenses, weighted by their popularity.
208239--
0 commit comments