Skip to content

Instantly share code, notes, and snippets.

@fendor
Created April 6, 2019 21:17
Show Gist options
  • Save fendor/55198b57fc1f4e9adbc5d116c72d8566 to your computer and use it in GitHub Desktop.
Save fendor/55198b57fc1f4e9adbc5d116c72d8566 to your computer and use it in GitHub Desktop.
provider :: FormattingProvider
provider uri formatType opts = pluginGetFile "brittanyCmd: " uri $ \file -> do
confFile <- liftIO $ getConfFile file
mtext <- readVFS uri
case mtext of
Nothing -> return $ IdeResultFail (IdeError InternalError "File was not open" Null)
Just text -> case formatType of
FormatRange r -> do
res <- liftIO $ runBrittany tabSize confFile $ extractRange r text
case res of
Left err -> return $ IdeResultFail (IdeError PluginError
(T.pack $ "brittanyCmd: " ++ unlines (map showErr err)) Null)
Right newText -> do
let textEdit = J.TextEdit (normalize r) newText
return $ IdeResultOk [textEdit]
FormatDocument -> do
res <- liftIO $ runBrittany tabSize confFile text
case res of
Left err -> return $ IdeResultFail (IdeError PluginError
(T.pack $ "brittanyCmd: " ++ unlines (map showErr err)) Null)
Right newText ->
return $ IdeResultOk [J.TextEdit (fullRange text) newText]
where tabSize = opts ^. J.tabSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment