Skip to content

Commit

Permalink
Add more completion options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jana Chadt committed Oct 9, 2022
1 parent 2b5c0dd commit 97a0cf6
Showing 1 changed file with 85 additions and 94 deletions.
179 changes: 85 additions & 94 deletions plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

module Ide.Plugin.Cabal where
module Ide.Plugin.Cabal (descriptor, Log(..)) where

import Control.Concurrent.STM
import Control.DeepSeq (NFData)
Expand Down Expand Up @@ -233,7 +233,7 @@ getContext pos ls =
kwContext <- getKeyWordContext pos ls m
pure (Stanza s, kwContext)
where
lvlContext = findCurrentLevel (ls)
lvlContext = findCurrentLevel (getPreviousLines pos ls)

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

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

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

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


-- todo: we could add file path completion for file path fields
-- we could add descriptions of field values and then show them when inside the field's context
-- | Top level keywords of a cabal file
cabalKeywords :: Map T.Text [T.Text]
cabalKeywords =
Expand All @@ -310,98 +312,87 @@ cabalKeywords =
("license-file:", []),
("license-files:",[]),
("copyright:", []),
("author:", [])
-- "maintainer:",
-- "stability:",
-- "homepage:",
-- "bug-reports:",
-- "package-url:",
-- "synopsis:",
-- "description:",
-- "category:",
-- "tested-with:",
-- "data-files:",
-- "data-dir:",
-- "data-dir:",
-- "extra-doc-files:",
-- "extra-tmp-files:"
("author:", []),
("maintainer:",[]),
("stability:",[]),
("homepage:",[]),
("bug-reports:",[]),
("package-url:",[]),
("synopsis:",[]),
("description:",[]),
("category:",[]),
("tested-with:",["GHC"]),
("data-files:", []),
("data-dir:", []),
("data-dir:", []),
("extra-source-files:", []),
("extra-doc-files:", []),
("extra-tmp-files:", [])
]

-- | Map, containing all stanzas in a cabal file as keys and lists of their possible nested keywords as values
stanzaKeywordMap :: Map T.Text (Map T.Text [T.Text])
stanzaKeywordMap = Map.fromList [("library", Map.fromList[
("exposed-modules:", []),
("virtual-modules:", []),
("exposed:", ["True", "False"]),
("visibility:", ["private", "public"]),
("reexported-modules:", []),
("signatures:", [])
]),
("test-suite", Map.fromList[])
]


-- TODO move out toplevel commands i.e. test-suite
-- cabalTestKeywords :: [T.Text]
-- cabalTestKeywords =
-- [
-- "type:",
-- "main-is:",
-- "test-module:",
-- "benchmark",
-- "main-is:",
-- "foreign-library",
-- "type:",
-- "options:",
-- "mod-def-file:",
-- "lib-version-info:",
-- "lib-version-linux:",
-- "build-depends:",
-- "other-modules:",
-- "hs-source-dir:",
-- "hs-source-dirs:",
-- "default-extensions:",
-- "other-extensions:",
-- "default-language:",
-- "other-languages:",
-- "extensions:",
-- "build-tool-depends:",
-- "build-tools:",
-- "buildable:",
-- "ghc-options:",
-- "ghc-prof-options:",
-- "ghc-shared-options:",
-- "ghcjs-options:",
-- "ghcjs-prof-options:",
-- "ghcjs-shared-options:",
-- "includes:",
-- "install-includes:",
-- ("include-dirs:", "directory list"),
-- ("c-sources:", "filename list"),
-- ("cxx-sources:", "filename list"),
-- ("asm-sources:", "filename list"),
-- ("cmm-sources:", "filename list"),
-- ("js-sources:", "filename list"),
-- ("extra-libraries:", "token list"),
-- ("extra-libraries-static:", "token list"),
-- ("extra-ghci-libraries:", "token list"),
-- ("extra-bundled-libraries:", "token list"),
-- ("extra-lib-dirs:", "directory list")
-- ("extra-lib-dirs-static:", "directory list"),
-- ("extra-library-flavours:", "notsure"),
-- ("extra-dynamic-library-flavours:", "notsure"),
-- ("cc-options:", "token list"),
-- ("cpp-options:", "token list"),
-- ("cxx-options:", "token list"),
-- ("cmm-options:", "token list"),
-- ("asm-options:", "token list"),
-- ("ld-options:", "token list"),
-- ("hsc2hs-options:", "token list"),
-- ("pkgconfig-depends:", "package list"),
-- ("frameworks:", "token list"),
-- ("extra-framework-dirs:", "directory list"),
-- ("mixins:", "mixin list")
-- ]
stanzaKeywordMap =
Map.fromList
[ ( "library",
Map.fromList $
[ ("exposed-modules:", []),
("virtual-modules:", []),
("exposed:", ["True", "False"]),
("visibility:", ["private", "public"]),
("reexported-modules:", []),
("signatures:", [])
]
++ libExecTestBenchCommons
),
( "executable",
Map.fromList $
[ ("main-is:", []),
("scope:", ["public", "private"])
]
++ libExecTestBenchCommons
),
( "test-suite",
Map.fromList $
[ ("type:", ["exitcode-stdio-1.0"]),
("main-is:", [])
]
++ libExecTestBenchCommons
),
( "benchmark",
Map.fromList $
[ ("type:", []),
("main-is:", [])
]
++ libExecTestBenchCommons
),
( "foreign-library",
Map.fromList
[ ("type:", []),
("options:", []),
("mod-def-file:", []),
("lib-def-file:", []),
("lib-version-info:", []),
("lib-version-linux:", [])
]
)
]
where
libExecTestBenchCommons =
[ ("build-depends:", []),
("other-modules:", []),
("hs-source-dir:", ["."]),
("hs-source-dirs:", ["."]),
("default-extensions:", []),
("other-extensions:", []),
("default-language:", []),
("build-tool-depends:", []),
("buildable:", ["True", "False"]),
-- todo maybe there is a list of possible ghc options somewhere
("ghc-options:", []),
("ghc-prof-options:", []),
("ghc-shared-options:", [])
]

-- cabalFlagKeywords :: [(T.Text, T.Text)]
-- cabalFlagKeywords =
Expand Down

0 comments on commit 97a0cf6

Please sign in to comment.