Skip to content

hlint fixity issues #2418

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
ivan-m opened this issue Nov 30, 2021 · 3 comments · Fixed by #2464
Closed

hlint fixity issues #2418

ivan-m opened this issue Nov 30, 2021 · 3 comments · Fixed by #2464
Labels
component: hls-hlint-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@ivan-m
Copy link

ivan-m commented Nov 30, 2021

Your environment

Which OS do you use: Red Hat 7 VM
Which lsp-client do you use: Emacs
Describe your project (alternative: link to the project): Shake + Stack; internal project so can't be shared

Steps to reproduce

# .hlint.yaml
- fixity: "infixl 3 <!>"

Haskell source file:

-- https://hackage.haskell.org/package/semigroupoids-5.3.6/docs/Data-Functor-Alt.html
import Data.Functor.Alt ((<!>))

-- Simplified function matching behaviour of actual functions
foo :: Char -> Maybe Int -> Maybe String
foo c mInt =
      show <$> mInt
  <!> pure <$> Just c

-- Note the relative fixities here: this is equivalent to: (...) <!> (...)

Load this in $EDITOR, list all suggestions from hls.

Expected behaviour

No warnings related to foo.

Actual behaviour

Functor law
 Found:
   show <$> mInt <!> pure <$> Just c
 Why not:
   show . (mInt <!> pure) <$> Just c

Include debug information

Running hlint explicitly does not have any problems.

The .hlint.yaml file is indeed being picked up by the hls hlint plugin as other suggestions are appearing based upon the configuration (custom linting rules, etc.). As such, this might be due to ndmitchell/hlint#1232

haskell-language-server-wrapper --debug . output only partially shown as it's quite large:

haskell-language-server version: 1.5.1.0 (GHC: 8.10.7) (PATH: /home/<elided>/haskell-language-server) (GIT hash: 1d82c8ec31628fc84f0ffe55ff572602212e07a2)
 ghcide setup tester in /home/<elided>
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/<elided>
Found 16145 files

Logs from LSP client:

Command "~/<elided>/haskell-language-server --lsp" is present on the path.
Command "~/<elided>/haskell-language-server --lsp" is present on the path.
Found the following clients for /path/to/Module.hs: (server-id lsp-haskell, priority 0)
The following clients were selected based on priority: (server-id lsp-haskell, priority 0)
@ivan-m ivan-m added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Nov 30, 2021
@jneira
Copy link
Member

jneira commented Nov 30, 2021

Thanks for the bug report, i wonder what happens if you set the rule via file pragma f.e.

@ivan-m
Copy link
Author

ivan-m commented Nov 30, 2021

AFAICT, the fixity information can only be specified in .hlint.yaml.

I did try adding {-# ANN module ("HLint: fixity: infixl 3 <!>" :: String) #-} but it had no effect.

@eddiemundo
Copy link
Collaborator

eddiemundo commented Dec 10, 2021

I looked into this and it seems to be that the hlint plugin in the end gets the HLINT_ON_GHC_LIB flag not set, and because of some cpp, flags (specifically fixities) from the .hlint.yaml are ignored:

where moduleEx :: ParseFlags -> Action (Maybe (Either ParseError ModuleEx))
#ifndef HLINT_ON_GHC_LIB
moduleEx _flags = do
mbpm <- getParsedModuleWithComments nfp
return $ createModule <$> mbpm
where createModule pm = Right (createModuleEx anns modu)
where anns = pm_annotations pm
modu = pm_parsed_source pm
#else

I think applying fixities in the flags to modu before passing it to createModuleEx would do the trick.

eddiemundo added a commit to eddiemundo/haskell-language-server that referenced this issue Dec 10, 2021
@mergify mergify bot closed this as completed in #2464 Dec 11, 2021
mergify bot pushed a commit that referenced this issue Dec 11, 2021
…ined (#2464)

* fix #2418 until upstream hlint change

* remove debug import

* add comment about when ghc-lib-parser-ex dependency can be removed

Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-hlint-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
3 participants