Skip to content

Commit a48a937

Browse files
Jana ChadtVeryMilkyJoe
Jana Chadt
authored andcommitted
Add more completion options
1 parent 3eec5ed commit a48a937

File tree

1 file changed

+89
-93
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin

1 file changed

+89
-93
lines changed

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

Lines changed: 89 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ getContext pos ls =
338338
kwContext <- getKeyWordContext pos ls m
339339
pure (Stanza s, kwContext)
340340
where
341-
lvlContext = findCurrentLevel (ls)
341+
lvlContext = findCurrentLevel (getPreviousLines pos ls)
342342

343343
-- | Takes a position, a list of lines (representing a file) and a map of keywords as keys
344344
-- and returns a keyword context if there is a keyword from the map before the current position
@@ -373,10 +373,9 @@ findCurrentLevel (cur : xs)
373373

374374
-- | Get all lines before the given cursor position in the given file
375375
-- and reverse them since we want to traverse starting from our current position
376-
getPreviousLines :: Position -> Rope.Rope -> [T.Text]
377-
getPreviousLines pos rope = reverse $ take (fromIntegral currentLine) allLines
376+
getPreviousLines :: Position -> [T.Text] -> [T.Text]
377+
getPreviousLines pos ls = reverse $ take (fromIntegral currentLine) ls
378378
where
379-
allLines = Rope.lines rope
380379
currentLine = pos ^. JL.line
381380

382381
-- | The context a cursor can be in within a cabal file,
@@ -402,8 +401,11 @@ data KeyWordContext
402401

403402
-- | Keyword for cabal version required to be the top line in a cabal file
404403
cabalVersionKeyword :: (T.Text,[T.Text])
405-
cabalVersionKeyword = ("cabal-version:", [])
404+
cabalVersionKeyword = ("cabal-version:", ["2.0", "2.2", "2.4", "3.0"])
406405

406+
407+
-- todo: we could add file path completion for file path fields
408+
-- we could add descriptions of field values and then show them when inside the field's context
407409
-- | Top level keywords of a cabal file
408410
cabalKeywords :: Map T.Text [T.Text]
409411
cabalKeywords =
@@ -415,98 +417,92 @@ cabalKeywords =
415417
("license-file:", []),
416418
("license-files:",[]),
417419
("copyright:", []),
418-
("author:", [])
419-
-- "maintainer:",
420-
-- "stability:",
421-
-- "homepage:",
422-
-- "bug-reports:",
423-
-- "package-url:",
424-
-- "synopsis:",
425-
-- "description:",
426-
-- "category:",
427-
-- "tested-with:",
428-
-- "data-files:",
429-
-- "data-dir:",
430-
-- "data-dir:",
431-
-- "extra-doc-files:",
432-
-- "extra-tmp-files:"
420+
("author:", []),
421+
("maintainer:",[]),
422+
("stability:",[]),
423+
("homepage:",[]),
424+
("bug-reports:",[]),
425+
("package-url:",[]),
426+
("synopsis:",[]),
427+
("description:",[]),
428+
("category:",[]),
429+
("tested-with:",["GHC"]),
430+
("data-files:", []),
431+
("data-dir:", []),
432+
("data-dir:", []),
433+
("extra-source-files:", []),
434+
("extra-doc-files:", []),
435+
("extra-tmp-files:", [])
433436
]
434437

435438
-- | Map, containing all stanzas in a cabal file as keys and lists of their possible nested keywords as values
436439
stanzaKeywordMap :: Map T.Text (Map T.Text [T.Text])
437-
stanzaKeywordMap = Map.fromList [("library", Map.fromList[
438-
("exposed-modules:", []),
439-
("virtual-modules:", []),
440-
("exposed:", ["True", "False"]),
441-
("visibility:", ["private", "public"]),
442-
("reexported-modules:", []),
443-
("signatures:", [])
444-
]),
445-
("test-suite", Map.fromList[])
446-
]
447-
448-
449-
-- TODO move out toplevel commands i.e. test-suite
450-
-- cabalTestKeywords :: [T.Text]
451-
-- cabalTestKeywords =
452-
-- [
453-
-- "type:",
454-
-- "main-is:",
455-
-- "test-module:",
456-
-- "benchmark",
457-
-- "main-is:",
458-
-- "foreign-library",
459-
-- "type:",
460-
-- "options:",
461-
-- "mod-def-file:",
462-
-- "lib-version-info:",
463-
-- "lib-version-linux:",
464-
-- "build-depends:",
465-
-- "other-modules:",
466-
-- "hs-source-dir:",
467-
-- "hs-source-dirs:",
468-
-- "default-extensions:",
469-
-- "other-extensions:",
470-
-- "default-language:",
471-
-- "other-languages:",
472-
-- "extensions:",
473-
-- "build-tool-depends:",
474-
-- "build-tools:",
475-
-- "buildable:",
476-
-- "ghc-options:",
477-
-- "ghc-prof-options:",
478-
-- "ghc-shared-options:",
479-
-- "ghcjs-options:",
480-
-- "ghcjs-prof-options:",
481-
-- "ghcjs-shared-options:",
482-
-- "includes:",
483-
-- "install-includes:",
484-
-- ("include-dirs:", "directory list"),
485-
-- ("c-sources:", "filename list"),
486-
-- ("cxx-sources:", "filename list"),
487-
-- ("asm-sources:", "filename list"),
488-
-- ("cmm-sources:", "filename list"),
489-
-- ("js-sources:", "filename list"),
490-
-- ("extra-libraries:", "token list"),
491-
-- ("extra-libraries-static:", "token list"),
492-
-- ("extra-ghci-libraries:", "token list"),
493-
-- ("extra-bundled-libraries:", "token list"),
494-
-- ("extra-lib-dirs:", "directory list")
495-
-- ("extra-lib-dirs-static:", "directory list"),
496-
-- ("extra-library-flavours:", "notsure"),
497-
-- ("extra-dynamic-library-flavours:", "notsure"),
498-
-- ("cc-options:", "token list"),
499-
-- ("cpp-options:", "token list"),
500-
-- ("cxx-options:", "token list"),
501-
-- ("cmm-options:", "token list"),
502-
-- ("asm-options:", "token list"),
503-
-- ("ld-options:", "token list"),
504-
-- ("hsc2hs-options:", "token list"),
505-
-- ("pkgconfig-depends:", "package list"),
506-
-- ("frameworks:", "token list"),
507-
-- ("extra-framework-dirs:", "directory list"),
508-
-- ("mixins:", "mixin list")
509-
-- ]
440+
stanzaKeywordMap =
441+
Map.fromList
442+
[ ( "library",
443+
Map.fromList $
444+
[ ("exposed-modules:", []),
445+
("virtual-modules:", []),
446+
("exposed:", ["True", "False"]),
447+
("visibility:", ["private", "public"]),
448+
("reexported-modules:", []),
449+
("signatures:", [])
450+
]
451+
++ libExecTestBenchCommons
452+
),
453+
( "executable",
454+
Map.fromList $
455+
[ ("main-is:", []),
456+
("scope:", ["public", "private"])
457+
]
458+
++ libExecTestBenchCommons
459+
),
460+
( "test-suite",
461+
Map.fromList $
462+
[ ("type:", ["exitcode-stdio-1.0"]),
463+
("main-is:", [])
464+
]
465+
++ libExecTestBenchCommons
466+
),
467+
( "benchmark",
468+
Map.fromList $
469+
[ ("type:", []),
470+
("main-is:", [])
471+
]
472+
++ libExecTestBenchCommons
473+
),
474+
( "foreign-library",
475+
Map.fromList
476+
[ ("type:", []),
477+
("options:", []),
478+
("mod-def-file:", []),
479+
("lib-def-file:", []),
480+
("lib-version-info:", []),
481+
("lib-version-linux:", [])
482+
]
483+
)
484+
]
485+
where
486+
libExecTestBenchCommons =
487+
[ ("build-depends:", []),
488+
("other-modules:", []),
489+
("hs-source-dir:", ["."]),
490+
("hs-source-dirs:", ["."]),
491+
("default-extensions:", []),
492+
("other-extensions:", []),
493+
("default-language:", []),
494+
("build-tool-depends:", []),
495+
("buildable:", ["True", "False"]),
496+
-- todo maybe there is a list of possible ghc options somewhere
497+
("ghc-options:", []),
498+
("ghc-prof-options:", []),
499+
("ghc-shared-options:", []),
500+
("ghcjs-options:", []),
501+
("ghcjs-prof-options:", []),
502+
("ghcjs-shared-options:", []),
503+
("includes:", []),
504+
("install-includes:", [])
505+
]
510506

511507
-- cabalFlagKeywords :: [(T.Text, T.Text)]
512508
-- cabalFlagKeywords =

0 commit comments

Comments
 (0)