Skip to content

Only complete to cabal-version at first line - #5119

Open
StillerHarpo wants to merge 5 commits into
haskell:masterfrom
StillerHarpo:first-line-cabal-version-completion
Open

StillerHarpo wants to merge 5 commits into
haskell:masterfrom
StillerHarpo:first-line-cabal-version-completion

Conversation

@StillerHarpo

@StillerHarpo StillerHarpo commented Oct 10, 2026 •

Copy link
Copy Markdown

The field cabal-version has to be in the first line. So any other
field completion doesn't make sense.

#5115

@dyniec

dyniec commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Looks good

@VeryMilkyJoe VeryMilkyJoe left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!
I think I would like a test case for the first line, where a different keyword is already there, so the completer for that field should be triggered instead of the cabal-version one.

@StillerHarpo
StillerHarpo force-pushed the first-line-cabal-version-completion branch from 3602e17 to b076316 Compare October 11, 2026 09:23

@fendor fendor left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea is right, I think we want to add the special case for cabal-version in StanzaContext rather than KeyWordContext.

Have you tried your changes, do you feel this behaves better now?

Comment on lines +146 to +147
Just section@(Syntax.Section _ args sectionFields)
| cursorRow == 1 -> (TopLevel, CabalVersion)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this case is impossible, no?

I guess it can only happen if you have library { cabal-version: ... }, but we don't want to offer the completion in this case any way, so the context should likely not use the special case any way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if I remove this cabal-version is only suggested in empty files

   only suggest cabal-version at start of file with some input:                            FAIL (0.03s)
        plugins/hls-cabal-plugin/test/Completer.hs:94:
        expected: ["cabal-version:"]
         but got: ["category:","package-url:","benchmark","executable"]
        Use -p '$0=="Cabal Plugin Tests.Completer Tests.Basic Completer Tests.only suggest cabal-version at start of file with some input"' to rerun this test only.

Comment on lines +106 to +107
| -- | Point is in the first line of the file and cabal version is missing
CabalVersion

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether we rather want to say the StanzaContext is FirstLine, so we don't need the special key the for cabal-version. Then cabal-version is just a normal FieldContext, might work out a little better?

@StillerHarpo StillerHarpo Oct 18, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FirstLine is not quite right, because if the cursor is after a key word in the first line we don't want to complete to cabal-version. Should I put it in the StanzaContext and call it CabalVersion I now don't handle all FirstLine contexts as cabal-version

Just l -> l
contextToCompleter (TopLevel, CabalVersion) = constantCompleter ["cabal-version:"]
-- If we are at the start of a file, we should be in the toplevel stanza
contextToCompleter (Stanza _ _, CabalVersion) = errorNoopCompleter LogNotInTopLevelStanzaAtStartOfFirstLine

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, this case should be impossible (and is). If we made the special case in StanzaContext, this case goes away.

@VeryMilkyJoe
VeryMilkyJoe force-pushed the first-line-cabal-version-completion branch from b076316 to 0bb56d6 Compare October 11, 2026 13:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants