Skip to content

Cabal Plugin is too strict for the newest cabal versions #4401

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

Closed
fendor opened this issue Sep 12, 2024 · 5 comments
Closed

Cabal Plugin is too strict for the newest cabal versions #4401

fendor opened this issue Sep 12, 2024 · 5 comments
Labels
component: hls-cabal-plugin Issues related to the hls-cabal-plugin Hackathon This issue is suitable for hackathon sessions type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@fendor
Copy link
Collaborator

fendor commented Sep 12, 2024

Generating a new package with cabal 3.12 via

$ mkdir test-hls-cabal
$ cd test-hls-cabal
$ cabal init --lib -n

Generates a .cabal file with cabal-version: 3.12, which haskell-language-server-2.9.0.1 built with ghc-9.6.5, which is linked against Cabal-3.10.3.0. Consequentially, HLS highlights the whole .cabal file as incorrect, as it doesn't recognise 3.12 as a valid cabal-version.

image

This is bad user-experience.

I am not sure whether we can fix that for good, as older HLS versions will never get linked against a newer Cabal version.
However, what we could do is to be more lenient when it comes to parsing .cabal files.
We can scan the .cabal file for the line cabal-version: (scanSpecVersion) and if the version is not known to us, we parse the cabal file with the newest CabalSpecVersion available to the HLS binary.
The cabal features may still break if users actually need new cabal-the-spec-features, but for many future changes, we likely only display warnings and many other IDE features keep working.

The only real disadvantage is that we can't reliably report incorrect cabal-version numbers any more. Also, the proposed behaviour might be unexpected to users.

The last resort I can think of, is to simply not provide any IDE features if the cabal-version is seemingly too new for the Cabal version linked into HLS.

@fendor fendor added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. status: needs triage component: hls-cabal-plugin Issues related to the hls-cabal-plugin and removed status: needs triage labels Sep 12, 2024
@fendor
Copy link
Collaborator Author

fendor commented Sep 12, 2024

It seems to be more difficult than hoped to parse a .cabal file with a newer cabal-version in a lenient way. The cabal-version is parsed in the FieldGrammar, so we would have to basically copy-paste major parts of Cabal-syntax to not verify the provided CabalSpecVersion is not equal to the actual parsed ones.

Thus, the only way I can think of now is to basically overwrite the cabal-version field in-memory.

Ignoring .cabal files with a too new version seems to be the less hacky approach.

@fendor fendor added the Hackathon This issue is suitable for hackathon sessions label Oct 2, 2024
@michaelpj
Copy link
Collaborator

Yeah, I think just emitting a diagnostic saying that we don't know how to parse it is best? So pretty much the current behaviour, but with a nicer diagnostic that doesn't cover the whole file 😅

@fridewald
Copy link
Contributor

I'll give it a try

@fridewald
Copy link
Contributor

There was an issue with handling errors in the cabal file if the error is in the first line. Cabal normally uses 1-based line numbering, but for the first line it can also return the line 0. Created a PR to safely fix this.

@fendor fendor closed this as completed Oct 20, 2024
@fendor
Copy link
Collaborator Author

fendor commented Oct 20, 2024

Fixed by #4425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-cabal-plugin Issues related to the hls-cabal-plugin Hackathon This issue is suitable for hackathon sessions type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants