Skip to content

Commit 9bf0eaf

Browse files
author
Jana Chadt
committed
Add more completion options
1 parent 2b5c0dd commit 9bf0eaf

File tree

1 file changed

+90
-94
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin

1 file changed

+90
-94
lines changed

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

+90-94
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{-# LANGUAGE OverloadedStrings #-}
99
{-# LANGUAGE TypeFamilies #-}
1010

11-
module Ide.Plugin.Cabal where
11+
module Ide.Plugin.Cabal (descriptor, Log(..)) where
1212

1313
import Control.Concurrent.STM
1414
import Control.DeepSeq (NFData)
@@ -233,7 +233,7 @@ getContext pos ls =
233233
kwContext <- getKeyWordContext pos ls m
234234
pure (Stanza s, kwContext)
235235
where
236-
lvlContext = findCurrentLevel (ls)
236+
lvlContext = findCurrentLevel (getPreviousLines pos ls)
237237

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

269269
-- | Get all lines before the given cursor position in the given file
270270
-- 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
273273
where
274-
allLines = Rope.lines rope
275274
currentLine = pos ^. JL.line
276275

277276
-- | The context a cursor can be in within a cabal file,
@@ -297,8 +296,11 @@ data KeyWordContext
297296

298297
-- | Keyword for cabal version required to be the top line in a cabal file
299298
cabalVersionKeyword :: (T.Text,[T.Text])
300-
cabalVersionKeyword = ("cabal-version:", [])
299+
cabalVersionKeyword = ("cabal-version:", ["2.0", "2.2", "2.4", "3.0"])
301300

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
302304
-- | Top level keywords of a cabal file
303305
cabalKeywords :: Map T.Text [T.Text]
304306
cabalKeywords =
@@ -310,98 +312,92 @@ cabalKeywords =
310312
("license-file:", []),
311313
("license-files:",[]),
312314
("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:", [])
328331
]
329332

330333
-- | Map, containing all stanzas in a cabal file as keys and lists of their possible nested keywords as values
331334
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+
]
405401

406402
-- cabalFlagKeywords :: [(T.Text, T.Text)]
407403
-- cabalFlagKeywords =

0 commit comments

Comments
 (0)