Skip to content

Commit e9ffcc2

Browse files
yndolgSamuelLess
andcommitted
Cabal ignore if for completions
If conditions were previously handled as normal sections, for which we don't have any completion information. Now, we ignore the if section and use the parent section for completion purposes. Co-authored-by: SamuelLess <[email protected]>
1 parent ed96358 commit e9ffcc2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Completions.hs

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ findCursorContext cursor parentHistory prefixText fields =
140140
Just field@(Syntax.Field _ _) -> classifyFieldContext parentHistory cursor field
141141
Just section@(Syntax.Section _ args sectionFields)
142142
| inSameLineAsSectionName section -> (stanzaCtx, None) -- TODO: test whether keyword in same line is parsed correctly
143+
| getFieldName section == "if" -> findCursorContext cursor parentHistory prefixText sectionFields -- Ignore if conditionals, they are not real sections
143144
| otherwise ->
144145
findCursorContext cursor
145146
(NE.cons (Syntax.positionCol (getAnnotation section) + 1, Stanza (getFieldName section) (getOptionalSectionName args)) parentHistory)

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

+11
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ getContextTests =
154154
, testCase "Top level - cursor in later line with partially written value" $ do
155155
ctx <- callGetContext (Position 5 13) "eee" topLevelData
156156
ctx @?= (TopLevel, KeyWord "name:")
157+
, testCase "If is ignored" $ do
158+
ctx <- callGetContext (Position 5 8) "" ifData
159+
ctx @?= (Stanza "library" Nothing, None)
157160
, testCase "Named Stanza" $ do
158161
ctx <- callGetContext (Position 2 18) "" executableStanzaData
159162
ctx @?= (TopLevel, None)
@@ -237,6 +240,14 @@ name:
237240
eee
238241
|]
239242

243+
ifData :: T.Text
244+
ifData = [trimming|
245+
cabal-version: 3.0
246+
name: simple-cabal
247+
library
248+
if os(windows)
249+
250+
|]
240251
multiLineOptsData :: T.Text
241252
multiLineOptsData = [trimming|
242253
cabal-version: 3.0

0 commit comments

Comments
 (0)