Skip to content

Commit 485b573

Browse files
committed
Add common stanza to completion data
This allows fields and values to be completed correctly inside common stanzas
1 parent 7563439 commit 485b573

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Diff for: plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Data.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cabalKeywords =
6363
("extra-tmp-files:", filePathCompleter)
6464
]
6565

66-
-- | Map, containing all stanzas in a cabal file as keys
66+
-- | Map, containing all stanzas in a cabal file as keys,
6767
-- and lists of their possible nested keywords as values.
6868
stanzaKeywordMap :: Map StanzaType (Map KeyWordName Completer)
6969
stanzaKeywordMap =
@@ -73,6 +73,7 @@ stanzaKeywordMap =
7373
("test-suite", testSuiteFields <> libExecTestBenchCommons),
7474
("benchmark", benchmarkFields <> libExecTestBenchCommons),
7575
("foreign-library", foreignLibraryFields <> libExecTestBenchCommons),
76+
("common", libExecTestBenchCommons),
7677
("flag", flagFields),
7778
("source-repository", sourceRepositoryFields)
7879
]

Diff for: plugins/hls-cabal-plugin/test/Completer.hs

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ basicCompleterTests =
5151
compls <- getCompletions doc (Position 8 2)
5252
let complTexts = getTextEditTexts compls
5353
liftIO $ assertBool "suggests benchmark" $ "benchmark" `elem` complTexts
54+
, runCabalTestCaseSession "In top level context - stanza should be suggested" "" $ do
55+
doc <- openDoc "completer.cabal" "cabal"
56+
compls <- getCompletions doc (Position 13 2)
57+
let complTexts = getTextEditTexts compls
58+
liftIO $ assertBool "suggests common" $ "common" `elem` complTexts
5459
, runCabalTestCaseSession "Main-is completions should be relative to hs-source-dirs of same stanza" "filepath-completions" $ do
5560
doc <- openDoc "main-is.cabal" "cabal"
5661
compls <- getCompletions doc (Position 10 12)

Diff for: plugins/hls-cabal-plugin/test/Context.hs

+9
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ getContextTests =
188188
, (Stanza "source-repository" (Just "head"), KeyWord "type:")
189189
, (Stanza "source-repository" (Just "head"), KeyWord "type:")
190190
, (Stanza "source-repository" (Just "head"), None)
191+
, (Stanza "common" (Just "cabalfmt"), None)
192+
, (Stanza "common" (Just "cabalfmt"), None)
193+
, (Stanza "common" (Just "cabalfmt"), KeyWord "build-depends:")
191194
]
192195
$ \fileContent posPrefInfo ->
193196
callGetContext (cursorPos posPrefInfo) (prefixText posPrefInfo) fileContent
@@ -276,4 +279,10 @@ source-repository head
276279
location: https://github.com/haskell/haskell-language-server
277280

278281
^
282+
common cabalfmt
283+
284+
^
285+
build-depends: haskell-language-server:hls-cabal-fmt-plugin
286+
^ ^
287+
cpp-options: -Dhls_cabalfmt
279288
|]

Diff for: plugins/hls-cabal-plugin/test/testdata/completer.cabal

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ be
1010

1111
library
1212
lib
13+
14+
co

0 commit comments

Comments
 (0)