haskell / stylish-haskell

Haskell code prettifier
Other
986 stars 150 forks source link

feature: marker to ignore the following block #409

Open imuli opened 2 years ago

imuli commented 2 years ago

I occasionally run into situations where I want to manually format a block, e.g. with servant-openapi3:

-- | The Work API
-- ...
data WorkAPI n mode = WorkAPI
   { workCreate :: mode
      :- Summary "Create a work from a design."
      :> Description "..."
      :> NamedRoutes (RunAPI (Design n) (WorkId n))
   , workIdDesignGet :: mode
      :- Summary "Fetch the most recent design on a work."
      :> Description "..."
      :> WorkId n :> "design" :> NamedRoutes (GetAPI (Design n))
   }
  deriving (Generic)

stylish-haskell, of course, will reformat that so each type definition is on a single line, which is what I want in most cases. This would also provide a workaround while waiting on a bug fix (or for me in the case of record GADTs with docs, bug filing!).

{- STYLISH ignore -} -- no special highlighting.
{-# STYLISH ignore #-} -- special highlighting, but makes ghc noisy without `-Wno-unrecognized-pragmas`
{-# ANN myDef ("STYLISH ignore" :: String) #-} -- extra special highlighting, but not usable for imports, verbose.
andys8 commented 2 years ago

Would help with the haskell-language-server project where stylish-haskell is in use but fails to parse some files. Skipping these sections would format the rest of the file and help with failing pre-commit tasks.

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs: <string>:442:26: error: parse error on input `='
ghcide/src/Development/IDE/Import/FindImports.hs: <string>:127:5: error:
    parse error (possibly incorrect indentation or mismatched brackets)
plugins/hls-refactor-plugin/src/Development/IDE/GHC/Compat/ExactPrint.hs: <string>:4:1: error: parse error on input `module'
ghcide/src/Development/IDE/Core/Compile.hs: <string>:372:7: error: parse error on input `go'
imuli commented 2 years ago

This https://github.com/imuli/stylish-haskell/commit/22fd02d515394b3509e687f1e23b767399a4c07c commit in my personal version is the minimal thing that meets (some) of my needs. It only handles the comment inside the data declaration though:

data {-STYLISH ignore-} WorkAPI n mode = WorkAPI