Skip to content

Commit

Permalink
Add common stanza to completion data (#4286)
Browse files Browse the repository at this point in the history
This allows fields and values to be completed correctly inside common
stanzas

Co-authored-by: Michael Peyton Jones <[email protected]>
  • Loading branch information
VeryMilkyJoe and michaelpj authored Jun 9, 2024
1 parent c3236eb commit efe8913
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cabalKeywords =
("extra-tmp-files:", filePathCompleter)
]

-- | Map, containing all stanzas in a cabal file as keys
-- | Map, containing all stanzas in a cabal file as keys,
-- and lists of their possible nested keywords as values.
stanzaKeywordMap :: Map StanzaType (Map KeyWordName Completer)
stanzaKeywordMap =
Expand All @@ -73,6 +73,7 @@ stanzaKeywordMap =
("test-suite", testSuiteFields <> libExecTestBenchCommons),
("benchmark", benchmarkFields <> libExecTestBenchCommons),
("foreign-library", foreignLibraryFields <> libExecTestBenchCommons),
("common", libExecTestBenchCommons),
("flag", flagFields),
("source-repository", sourceRepositoryFields)
]
Expand Down
5 changes: 5 additions & 0 deletions plugins/hls-cabal-plugin/test/Completer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ basicCompleterTests =
compls <- getCompletions doc (Position 8 2)
let complTexts = getTextEditTexts compls
liftIO $ assertBool "suggests benchmark" $ "benchmark" `elem` complTexts
, runCabalTestCaseSession "In top level context - stanza should be suggested" "" $ do
doc <- openDoc "completer.cabal" "cabal"
compls <- getCompletions doc (Position 13 2)
let complTexts = getTextEditTexts compls
liftIO $ assertBool "suggests common" $ "common" `elem` complTexts
, runCabalTestCaseSession "Main-is completions should be relative to hs-source-dirs of same stanza" "filepath-completions" $ do
doc <- openDoc "main-is.cabal" "cabal"
compls <- getCompletions doc (Position 10 12)
Expand Down
9 changes: 9 additions & 0 deletions plugins/hls-cabal-plugin/test/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ getContextTests =
, (Stanza "source-repository" (Just "head"), KeyWord "type:")
, (Stanza "source-repository" (Just "head"), KeyWord "type:")
, (Stanza "source-repository" (Just "head"), None)
, (Stanza "common" (Just "cabalfmt"), None)
, (Stanza "common" (Just "cabalfmt"), None)
, (Stanza "common" (Just "cabalfmt"), KeyWord "build-depends:")
]
$ \fileContent posPrefInfo ->
callGetContext (cursorPos posPrefInfo) (prefixText posPrefInfo) fileContent
Expand Down Expand Up @@ -276,4 +279,10 @@ source-repository head
location: https://github.com/haskell/haskell-language-server

^
common cabalfmt

^
build-depends: haskell-language-server:hls-cabal-fmt-plugin
^ ^
cpp-options: -Dhls_cabalfmt
|]
2 changes: 2 additions & 0 deletions plugins/hls-cabal-plugin/test/testdata/completer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ be

library
lib

co

0 comments on commit efe8913

Please sign in to comment.