Skip to content

Cabal autogen-modules and autogen-includes completion #4534

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -183,6 +183,8 @@ libExecTestBenchCommons =
("includes:", filePathCompleter),
("install-includes:", filePathCompleter),
("include-dirs:", directoryCompleter),
("autogen-includes:", filePathCompleter),
("autogen-modules:", modulesCompleter sourceDirsExtractionLibrary),
("c-sources:", filePathCompleter),
("cxx-sources:", filePathCompleter),
("asm-sources:", filePathCompleter),
Expand Down
24 changes: 23 additions & 1 deletion plugins/hls-cabal-plugin/test/Completer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Completer where

import Control.Lens ((^.), (^?))
import Control.Lens.Prism
import Control.Monad (forM_)
import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Char8 as BS8
import Data.Maybe (mapMaybe)
Expand Down Expand Up @@ -40,7 +41,8 @@ completerTests =
completionHelperTests,
filePathExposedModulesTests,
exposedModuleCompleterTests,
importCompleterTests
importCompleterTests,
autogenFieldCompletionTests
]

basicCompleterTests :: TestTree
Expand Down Expand Up @@ -336,6 +338,26 @@ importCompleterTests =
[Syntax.SecArgName (Syntax.Position row (col + 7)) (BS8.pack name)]
[]

autogenFieldCompletionTests :: TestTree
autogenFieldCompletionTests =
testGroup "Autogen Field Completer Tests"
[ testAutogenField "library" "completion/autogen-completion.cabal" (Position 6 9) ["autogen-modules:", "autogen-includes:"]
, testAutogenField "executable" "completion/autogen-completion.cabal" (Position 11 9) ["autogen-modules:", "autogen-includes:"]
, testAutogenField "test-suite" "completion/autogen-completion.cabal" (Position 16 9) ["autogen-modules:", "autogen-includes:"]
, testAutogenField "benchmark" "completion/autogen-completion.cabal" (Position 21 9) ["autogen-modules:", "autogen-includes:"]
, testAutogenField "common" "completion/autogen-completion.cabal" (Position 24 9) ["autogen-modules:", "autogen-includes:"]
]

where
testAutogenField :: String -> FilePath -> Position -> [T.Text] -> TestTree
testAutogenField section file pos expected = runCabalTestCaseSession ("autogen-modules completion in " <> section) "" $ do
doc <- openDoc file "cabal"
items <- getCompletions doc pos
let labels = map (^. L.label) items
liftIO $ forM_ expected $ \expect ->
assertBool (T.unpack expect <> " not found in " <> section) $
any (expect `T.isInfixOf`) labels

simpleCompleterData :: Maybe StanzaName -> FilePath -> T.Text -> CompleterData
simpleCompleterData sName dir pref = do
CompleterData
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cabal-version: 3.0
name: autogen-completion
version: 0.1.0.0

library
hs-source-dirs: src
autogen-

executable autoexe
main-is: Main.hs
hs-source-dirs: src
autogen-

test-suite autotest
type: exitcode-stdio-1.0
hs-source-dirs: src
autogen-

benchmark autobench
type: exitcode-stdio-1.0
hs-source-dirs: src
autogen-

common defaults
autogen-
Loading