Created
April 6, 2019 21:17
-
-
Save fendor/55198b57fc1f4e9adbc5d116c72d8566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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