never executed always true always false
    1 module Conjure.LSP.Handlers.Format (formatHandler) where
    2 import Language.LSP.Server (requestHandler, LspM, Handlers)
    3 import Language.LSP.Types 
    4 import Control.Lens
    5 import Conjure.Prelude
    6 import Conjure.LSP.Util (withFile,  sendErrorMessage)
    7 import Conjure.Language.Parser (prettyPrintWithChecks)
    8 import qualified Language.LSP.Types as Ty 
    9 import qualified Prettyprinter as Pr
   10 import Prettyprinter.Render.Text (renderStrict)
   11 import Language.LSP.Types.Lens (params, textDocument)
   12 import Language.LSP.VFS (virtualFileText)
   13 import qualified Data.Text as T
   14 
   15 
   16 formatHandler :: Handlers (LspM ())
   17 formatHandler = requestHandler STextDocumentFormatting $ \ req res -> do
   18     let ps = req^.params.textDocument
   19     withFile ps $ \vf -> do
   20         let txt = virtualFileText vf
   21         case prettyPrintWithChecks txt of
   22                         Left err -> do
   23                             sendErrorMessage $ T.pack $ show err
   24                             pure ()
   25                         Right d-> do 
   26                             let  rendered = renderStrict $ Pr.layoutSmart (Pr.LayoutOptions $ Pr.AvailablePerLine 80 0.8) d
   27                             res $ Right $ fullEdit (fromInteger $ toInteger $ Conjure.Prelude.length $ T.lines txt) rendered
   28 
   29     
   30 
   31 fullEdit :: UInt -> Text -> List TextEdit
   32 fullEdit t d = Ty.List [
   33     TextEdit (Range (Position 0 0) (Position t 0)) (d)
   34     ]
   35 
   36 
   37