Skip to content

Commit 1f30952

Browse files
committed
Add completions for autogen-modules and autogen-includes in cabal file stanzas (#4526)
1 parent 32f7800 commit 1f30952

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

plugins/hls-cabal-plugin/test/Completer.hs

+43-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,51 @@ completerTests =
4040
completionHelperTests,
4141
filePathExposedModulesTests,
4242
exposedModuleCompleterTests,
43-
importCompleterTests
43+
importCompleterTests,
44+
autogenModulesCompletionTests
4445
]
4546

47+
autogenModulesCompletionTests :: TestTree
48+
autogenModulesCompletionTests =
49+
testGroup
50+
"Autogen modules completion"
51+
[ runCabalTestCaseSession "Completes autogen-modules in library stanza" "" $ do
52+
doc <- openDoc "cabal-files/autogen-completion.cabal" "cabal"
53+
completions <- getCompletions doc (Position 5 4)
54+
liftIO $ do
55+
print (map (^. L.label) completions)
56+
assertBool "autogen-modules: should be in completions" $
57+
any (\c -> T.isInfixOf "autogen-modules:" (c ^. L.label)) completions
58+
assertBool "autogen-includes: should be in completions" $
59+
any (\c -> T.isInfixOf "autogen-includes:" (c ^. L.label)) completions
60+
61+
, runCabalTestCaseSession "Completes autogen-modules in executable stanza" "" $ do
62+
doc <- openDoc "cabal-files/autogen-completion-exe.cabal" "cabal"
63+
completions <- getCompletions doc (Position 5 4)
64+
liftIO $ do
65+
assertBool "autogen-modules: should be in completions" $
66+
any (\c -> T.isInfixOf "autogen-modules:" (c ^. L.label)) completions
67+
68+
, runCabalTestCaseSession "Completes autogen fields in test-suite stanza" "" $ do
69+
doc <- openDoc "cabal-files/autogen-completion-test.cabal" "cabal"
70+
completions <- getCompletions doc (Position 6 4)
71+
liftIO $ do
72+
assertBool "autogen-modules: should be in completions" $
73+
any (\c -> T.isInfixOf "autogen-modules:" (c ^. L.label)) completions
74+
assertBool "autogen-includes: should be in completions" $
75+
any (\c -> T.isInfixOf "autogen-includes:" (c ^. L.label)) completions
76+
77+
, runCabalTestCaseSession "Completes autogen fields in benchmark stanza" "" $ do
78+
doc <- openDoc "cabal-files/autogen-completion-bench.cabal" "cabal"
79+
completions <- getCompletions doc (Position 6 4)
80+
liftIO $ do
81+
assertBool "autogen-modules: should be in completions" $
82+
any (\c -> T.isInfixOf "autogen-modules:" (c ^. L.label)) completions
83+
assertBool "autogen-includes: should be in completions" $
84+
any (\c -> T.isInfixOf "autogen-includes:" (c ^. L.label)) completions
85+
]
86+
87+
4688
basicCompleterTests :: TestTree
4789
basicCompleterTests =
4890
testGroup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cabal-version: 3.2
2+
name: test-project
3+
4+
benchmark bench
5+
type: exitcode-stdio-1.0
6+
main-is: BenchMain.hs
7+
autogen
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cabal-version: 3.2
2+
name: test-project
3+
4+
executable main
5+
main-is: Main.hs
6+
autogen
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cabal-version: 3.2
2+
name: test-project
3+
4+
test-suite test
5+
type: exitcode-stdio-1.0
6+
main-is: TestMain.hs
7+
autogen
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cabal-version: 3.2
2+
name: test-project
3+
4+
library
5+
exposed-modules: SomeModule
6+
autogen

0 commit comments

Comments
 (0)