stylish-haskell icon indicating copy to clipboard operation
stylish-haskell copied to clipboard

feature: marker to ignore the following block

Open imuli opened this issue 1 year ago • 2 comments

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.

imuli avatar Aug 30 '22 10:08 imuli

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'

andys8 avatar Sep 19 '22 11:09 andys8

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

imuli avatar Oct 21 '22 14:10 imuli