Skip to content

Add common stanza to completion data #4286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading