8
8
{-# LANGUAGE OverloadedStrings #-}
9
9
{-# LANGUAGE TypeFamilies #-}
10
10
11
- module Ide.Plugin.Cabal where
11
+ module Ide.Plugin.Cabal ( descriptor , Log ( .. )) where
12
12
13
13
import Control.Concurrent.STM
14
14
import Control.DeepSeq (NFData )
@@ -233,7 +233,7 @@ getContext pos ls =
233
233
kwContext <- getKeyWordContext pos ls m
234
234
pure (Stanza s, kwContext)
235
235
where
236
- lvlContext = findCurrentLevel (ls)
236
+ lvlContext = findCurrentLevel (getPreviousLines pos ls)
237
237
238
238
-- | Takes a position, a list of lines (representing a file) and a map of keywords as keys
239
239
-- and returns a keyword context if there is a keyword from the map before the current position
@@ -268,10 +268,9 @@ findCurrentLevel (cur : xs)
268
268
269
269
-- | Get all lines before the given cursor position in the given file
270
270
-- and reverse them since we want to traverse starting from our current position
271
- getPreviousLines :: Position -> Rope. Rope -> [T. Text ]
272
- getPreviousLines pos rope = reverse $ take (fromIntegral currentLine) allLines
271
+ getPreviousLines :: Position -> [ T. Text ] -> [T. Text ]
272
+ getPreviousLines pos ls = reverse $ take (fromIntegral currentLine) ls
273
273
where
274
- allLines = Rope. lines rope
275
274
currentLine = pos ^. JL. line
276
275
277
276
-- | The context a cursor can be in within a cabal file,
@@ -297,8 +296,11 @@ data KeyWordContext
297
296
298
297
-- | Keyword for cabal version required to be the top line in a cabal file
299
298
cabalVersionKeyword :: (T. Text ,[T. Text ])
300
- cabalVersionKeyword = (" cabal-version:" , [] )
299
+ cabalVersionKeyword = (" cabal-version:" , [" 2.0 " , " 2.2 " , " 2.4 " , " 3.0 " ])
301
300
301
+
302
+ -- todo: we could add file path completion for file path fields
303
+ -- we could add descriptions of field values and then show them when inside the field's context
302
304
-- | Top level keywords of a cabal file
303
305
cabalKeywords :: Map T. Text [T. Text ]
304
306
cabalKeywords =
@@ -310,98 +312,92 @@ cabalKeywords =
310
312
(" license-file:" , [] ),
311
313
(" license-files:" ,[] ),
312
314
(" copyright:" , [] ),
313
- (" author:" , [] )
314
- -- "maintainer:",
315
- -- "stability:",
316
- -- "homepage:",
317
- -- "bug-reports:",
318
- -- "package-url:",
319
- -- "synopsis:",
320
- -- "description:",
321
- -- "category:",
322
- -- "tested-with:",
323
- -- "data-files:",
324
- -- "data-dir:",
325
- -- "data-dir:",
326
- -- "extra-doc-files:",
327
- -- "extra-tmp-files:"
315
+ (" author:" , [] ),
316
+ (" maintainer:" ,[] ),
317
+ (" stability:" ,[] ),
318
+ (" homepage:" ,[] ),
319
+ (" bug-reports:" ,[] ),
320
+ (" package-url:" ,[] ),
321
+ (" synopsis:" ,[] ),
322
+ (" description:" ,[] ),
323
+ (" category:" ,[] ),
324
+ (" tested-with:" ,[" GHC" ]),
325
+ (" data-files:" , [] ),
326
+ (" data-dir:" , [] ),
327
+ (" data-dir:" , [] ),
328
+ (" extra-source-files:" , [] ),
329
+ (" extra-doc-files:" , [] ),
330
+ (" extra-tmp-files:" , [] )
328
331
]
329
332
330
333
-- | Map, containing all stanzas in a cabal file as keys and lists of their possible nested keywords as values
331
334
stanzaKeywordMap :: Map T. Text (Map T. Text [T. Text ])
332
- stanzaKeywordMap = Map. fromList [(" library" , Map. fromList[
333
- (" exposed-modules:" , [] ),
334
- (" virtual-modules:" , [] ),
335
- (" exposed:" , [" True" , " False" ]),
336
- (" visibility:" , [" private" , " public" ]),
337
- (" reexported-modules:" , [] ),
338
- (" signatures:" , [] )
339
- ]),
340
- (" test-suite" , Map. fromList[] )
341
- ]
342
-
343
-
344
- -- TODO move out toplevel commands i.e. test-suite
345
- -- cabalTestKeywords :: [T.Text]
346
- -- cabalTestKeywords =
347
- -- [
348
- -- "type:",
349
- -- "main-is:",
350
- -- "test-module:",
351
- -- "benchmark",
352
- -- "main-is:",
353
- -- "foreign-library",
354
- -- "type:",
355
- -- "options:",
356
- -- "mod-def-file:",
357
- -- "lib-version-info:",
358
- -- "lib-version-linux:",
359
- -- "build-depends:",
360
- -- "other-modules:",
361
- -- "hs-source-dir:",
362
- -- "hs-source-dirs:",
363
- -- "default-extensions:",
364
- -- "other-extensions:",
365
- -- "default-language:",
366
- -- "other-languages:",
367
- -- "extensions:",
368
- -- "build-tool-depends:",
369
- -- "build-tools:",
370
- -- "buildable:",
371
- -- "ghc-options:",
372
- -- "ghc-prof-options:",
373
- -- "ghc-shared-options:",
374
- -- "ghcjs-options:",
375
- -- "ghcjs-prof-options:",
376
- -- "ghcjs-shared-options:",
377
- -- "includes:",
378
- -- "install-includes:",
379
- -- ("include-dirs:", "directory list"),
380
- -- ("c-sources:", "filename list"),
381
- -- ("cxx-sources:", "filename list"),
382
- -- ("asm-sources:", "filename list"),
383
- -- ("cmm-sources:", "filename list"),
384
- -- ("js-sources:", "filename list"),
385
- -- ("extra-libraries:", "token list"),
386
- -- ("extra-libraries-static:", "token list"),
387
- -- ("extra-ghci-libraries:", "token list"),
388
- -- ("extra-bundled-libraries:", "token list"),
389
- -- ("extra-lib-dirs:", "directory list")
390
- -- ("extra-lib-dirs-static:", "directory list"),
391
- -- ("extra-library-flavours:", "notsure"),
392
- -- ("extra-dynamic-library-flavours:", "notsure"),
393
- -- ("cc-options:", "token list"),
394
- -- ("cpp-options:", "token list"),
395
- -- ("cxx-options:", "token list"),
396
- -- ("cmm-options:", "token list"),
397
- -- ("asm-options:", "token list"),
398
- -- ("ld-options:", "token list"),
399
- -- ("hsc2hs-options:", "token list"),
400
- -- ("pkgconfig-depends:", "package list"),
401
- -- ("frameworks:", "token list"),
402
- -- ("extra-framework-dirs:", "directory list"),
403
- -- ("mixins:", "mixin list")
404
- -- ]
335
+ stanzaKeywordMap =
336
+ Map. fromList
337
+ [ ( " library" ,
338
+ Map. fromList $
339
+ [ (" exposed-modules:" , [] ),
340
+ (" virtual-modules:" , [] ),
341
+ (" exposed:" , [" True" , " False" ]),
342
+ (" visibility:" , [" private" , " public" ]),
343
+ (" reexported-modules:" , [] ),
344
+ (" signatures:" , [] )
345
+ ]
346
+ ++ libExecTestBenchCommons
347
+ ),
348
+ ( " executable" ,
349
+ Map. fromList $
350
+ [ (" main-is:" , [] ),
351
+ (" scope:" , [" public" , " private" ])
352
+ ]
353
+ ++ libExecTestBenchCommons
354
+ ),
355
+ ( " test-suite" ,
356
+ Map. fromList $
357
+ [ (" type:" , [" exitcode-stdio-1.0" ]),
358
+ (" main-is:" , [] )
359
+ ]
360
+ ++ libExecTestBenchCommons
361
+ ),
362
+ ( " benchmark" ,
363
+ Map. fromList $
364
+ [ (" type:" , [] ),
365
+ (" main-is:" , [] )
366
+ ]
367
+ ++ libExecTestBenchCommons
368
+ ),
369
+ ( " foreign-library" ,
370
+ Map. fromList
371
+ [ (" type:" , [] ),
372
+ (" options:" , [] ),
373
+ (" mod-def-file:" , [] ),
374
+ (" lib-def-file:" , [] ),
375
+ (" lib-version-info:" , [] ),
376
+ (" lib-version-linux:" , [] )
377
+ ]
378
+ )
379
+ ]
380
+ where
381
+ libExecTestBenchCommons =
382
+ [ (" build-depends:" , [] ),
383
+ (" other-modules:" , [] ),
384
+ (" hs-source-dir:" , [" ." ]),
385
+ (" hs-source-dirs:" , [" ." ]),
386
+ (" default-extensions:" , [] ),
387
+ (" other-extensions:" , [] ),
388
+ (" default-language:" , [] ),
389
+ (" build-tool-depends:" , [] ),
390
+ (" buildable:" , [" True" , " False" ]),
391
+ -- todo maybe there is a list of possible ghc options somewhere
392
+ (" ghc-options:" , [] ),
393
+ (" ghc-prof-options:" , [] ),
394
+ (" ghc-shared-options:" , [] ),
395
+ (" ghcjs-options:" , [] ),
396
+ (" ghcjs-prof-options:" , [] ),
397
+ (" ghcjs-shared-options:" , [] ),
398
+ (" includes:" , [] ),
399
+ (" install-includes:" , [] )
400
+ ]
405
401
406
402
-- cabalFlagKeywords :: [(T.Text, T.Text)]
407
403
-- cabalFlagKeywords =
0 commit comments