Skip to content

Commit 87a265d

Browse files
committed
Add completion for cabal-version keyword
1 parent b1c81a1 commit 87a265d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import qualified Data.Map as Map
1414
import Data.Maybe (fromMaybe)
1515
import qualified Data.Text as T
1616
import Development.IDE as D
17-
import Distribution.CabalSpecVersion (CabalSpecVersion (CabalSpecV1_2),
17+
import Distribution.CabalSpecVersion (CabalSpecVersion (CabalSpecV2_2),
1818
showCabalSpecVersion)
1919
import Distribution.Compat.Lens ((^.))
2020
import Ide.Plugin.Cabal.LicenseSuggest (licenseNames)
@@ -92,11 +92,11 @@ contextToCompleter :: Context -> Completer
9292
-- if we are in the top level of the cabal file and not in a keyword context,
9393
-- we can write any top level keywords or a stanza declaration
9494
contextToCompleter (TopLevel, None) =
95-
constantCompleter $ Map.keys cabalKeywords ++ Map.keys stanzaKeywordMap
95+
constantCompleter $ Map.keys (cabalKeywords <> cabalVersionKeyword) ++ Map.keys stanzaKeywordMap
9696
-- if we are in a keyword context in the top level,
97-
-- we look up that keyword in the toplevel context and can complete its possible values
97+
-- we look up that keyword in the top level context and can complete its possible values
9898
contextToCompleter (TopLevel, KeyWord kw) =
99-
case Map.lookup kw cabalKeywords of
99+
case Map.lookup kw (cabalKeywords <> cabalVersionKeyword) of
100100
Nothing -> noopCompleter
101101
Just l -> l
102102
-- if we are in a stanza and not in a keyword context,
@@ -154,8 +154,8 @@ getKeyWordContext pos ls keywords = do
154154
case lastNonEmptyLineM of
155155
Nothing -> Just None
156156
Just lastLine' -> do
157-
let (whitespaces, lastLine) = T.span (== ' ') lastLine'
158-
let keywordIndentation = T.length whitespaces
157+
let (whiteSpaces, lastLine) = T.span (== ' ') lastLine'
158+
let keywordIndentation = T.length whiteSpaces
159159
let cursorIndentation = fromIntegral (pos ^. JL.character)
160160
-- in order to be in a keyword context the cursor needs to be indented more than the keyword
161161
if cursorIndentation > keywordIndentation
@@ -252,7 +252,7 @@ makeSimpleCabalCompletionItem :: Range -> T.Text -> CabalCompletionItem
252252
makeSimpleCabalCompletionItem r txt = CabalCompletionItem txt Nothing r
253253

254254
{- | Returns a CabalCompletionItem with the given starting position,
255-
text to be inserted and text to be displayed in completionsuggestion
255+
text to be inserted and text to be displayed in the completion suggestion
256256
-}
257257
makeCabalCompletionItem :: Range -> T.Text -> T.Text -> CabalCompletionItem
258258
makeCabalCompletionItem r insertTxt displayTxt = CabalCompletionItem insertTxt (Just displayTxt) r
@@ -364,7 +364,7 @@ cabalVersionKeyword :: Map T.Text Completer
364364
cabalVersionKeyword =
365365
Map.singleton "cabal-version:" $
366366
constantCompleter $
367-
map (T.pack . showCabalSpecVersion) [CabalSpecV1_2 .. maxBound]
367+
map (T.pack . showCabalSpecVersion) [CabalSpecV2_2 .. maxBound]
368368

369369
-- todo: we could add file path completion for file path fields
370370
-- we could add descriptions of field values and then show them when inside the field's context
@@ -408,7 +408,7 @@ stanzaKeywordMap =
408408
, ("virtual-modules:", noopCompleter)
409409
, ("exposed:", constantCompleter ["True", "False"])
410410
, ("visibility:", constantCompleter ["private", "public"])
411-
, ("reexported-modules:", noopCompleter) -- exportlist, i.e. "orig-okg:Name as NewName"
411+
, ("reexported-modules:", noopCompleter) -- export list, i.e. "orig-okg:Name as NewName"
412412
, ("signatures:", noopCompleter) -- list of signatures
413413
]
414414
++ libExecTestBenchCommons

0 commit comments

Comments
 (0)