1
1
{-# LANGUAGE OverloadedStrings #-}
2
- {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
3
-
4
- {-# HLINT ignore "Redundant bracket" #-}
5
2
6
3
module Ide.Plugin.Cabal.Completion.Data where
7
4
@@ -19,6 +16,17 @@ import Ide.Plugin.Cabal.Completion.Completer.Types (Completer)
19
16
import Ide.Plugin.Cabal.Completion.Types
20
17
import Ide.Plugin.Cabal.LicenseSuggest (licenseNames )
21
18
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
+
22
30
-- ----------------------------------------------------------------
23
31
-- Completion Data
24
32
-- ----------------------------------------------------------------
@@ -71,12 +79,13 @@ cabalKeywords =
71
79
stanzaKeywordMap :: Map StanzaType (Map KeyWordName Completer )
72
80
stanzaKeywordMap =
73
81
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 ),
80
89
(" flag" , flagFields),
81
90
(" source-repository" , sourceRepositoryFields)
82
91
]
@@ -162,8 +171,8 @@ flagFields =
162
171
(" lib-version-linux:" , noopCompleter)
163
172
]
164
173
165
- libExecTestBenchCommons :: Map KeyWordName Completer
166
- libExecTestBenchCommons =
174
+ libExecTestBenchCommons :: TopLevelStanza -> Map KeyWordName Completer
175
+ libExecTestBenchCommons st =
167
176
Map. fromList
168
177
[ (" import:" , importCompleter),
169
178
(" build-depends:" , noopCompleter),
@@ -183,6 +192,8 @@ libExecTestBenchCommons =
183
192
(" includes:" , filePathCompleter),
184
193
(" install-includes:" , filePathCompleter),
185
194
(" include-dirs:" , directoryCompleter),
195
+ (" autogen-includes:" , filePathCompleter),
196
+ (" autogen-modules:" , moduleCompleterByTopLevelStanza),
186
197
(" c-sources:" , filePathCompleter),
187
198
(" cxx-sources:" , filePathCompleter),
188
199
(" asm-sources:" , filePathCompleter),
@@ -203,6 +214,26 @@ libExecTestBenchCommons =
203
214
(" extra-framework-dirs:" , directoryCompleter),
204
215
(" mixins:" , noopCompleter)
205
216
]
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
206
237
207
238
-- | Contains a map of the most commonly used licenses, weighted by their popularity.
208
239
--
0 commit comments