@@ -28,10 +28,7 @@ brittanyDescriptor plId = PluginDescriptor
2828 { pluginId = plId
2929 , pluginName = " Brittany"
3030 , pluginDesc = " Brittany is a tool to format source code."
31- , pluginCommands = [ PluginCommand " formatText"
32- " Format the given Text with Brittany"
33- formatCmd
34- ]
31+ , pluginCommands = [ ]
3532 , pluginCodeActionProvider = Nothing
3633 , pluginDiagnosticProvider = Nothing
3734 , pluginHoverProvider = Nothing
@@ -42,40 +39,29 @@ brittanyDescriptor plId = PluginDescriptor
4239-- | Formatter provider of Brittany.
4340-- Formats the given source in either a given Range or the whole Document.
4441-- If the provider fails an error is returned that can be displayed to the user.
45- provider :: FormattingProvider
46- provider = format
47-
48- -- | Formatter of Brittany.
49- -- Formats the given source in either a given Range or the whole Document.
50- -- If the provider fails an error is returned that can be displayed to the user.
51- format
52- :: (MonadIO m , MonadIde m )
53- => Uri
42+ provider
43+ :: MonadIO m
44+ => Text
45+ -> Uri
5446 -> FormattingType
5547 -> FormattingOptions
5648 -> m (IdeResult [TextEdit ])
57- format uri formatType opts = pluginGetFile " brittanyCmd: " uri $ \ fp -> do
49+ provider text uri formatType opts = pluginGetFile " brittanyCmd: " uri $ \ fp -> do
5850 confFile <- liftIO $ getConfFile fp
59- mtext <- readVFS uri
60- case mtext of
61- -- Uri could not be read from the virtual file system.
62- Nothing ->
63- return $ IdeResultFail (IdeError InternalError " File was not open" Null )
64- Just text -> do
65- let (range, selectedContents) = case formatType of
66- FormatDocument -> (fullRange text, text)
67- FormatRange r -> (normalize r, extractRange r text)
51+ let (range, selectedContents) = case formatType of
52+ FormatDocument -> (fullRange text, text)
53+ FormatRange r -> (normalize r, extractRange r text)
6854
69- res <- formatText confFile opts selectedContents
70- case res of
71- Left err -> return $ IdeResultFail
72- (IdeError PluginError
73- (T. pack $ " brittanyCmd: " ++ unlines (map showErr err))
74- Null
75- )
76- Right newText -> do
77- let textEdit = J. TextEdit range newText
78- return $ IdeResultOk [textEdit]
55+ res <- formatText confFile opts selectedContents
56+ case res of
57+ Left err -> return $ IdeResultFail
58+ (IdeError PluginError
59+ (T. pack $ " brittanyCmd: " ++ unlines (map showErr err))
60+ Null
61+ )
62+ Right newText -> do
63+ let textEdit = J. TextEdit range newText
64+ return $ IdeResultOk [textEdit]
7965
8066-- | Primitive to format text with the given option.
8167-- May not throw exceptions but return a Left value.
@@ -90,30 +76,6 @@ formatText confFile opts text =
9076 liftIO $ runBrittany tabSize confFile text
9177 where tabSize = opts ^. J. tabSize
9278
93- -- | Format a source with the given options.
94- -- Synchronized command.
95- -- Other plugins can use this Command it to execute formatters.
96- -- Command can be run by
97- -- ```
98- -- runPluginCommand
99- -- (pluginId plugin)
100- -- "formatText"
101- -- (dynToJSON $ toDynJSON $ FormatTextCmdParams t r (FormattingOptions 2 True))
102- -- ```
103- formatCmd :: CommandFunc FormatTextCmdParams [TextEdit ]
104- formatCmd = CmdSync $ \ (FormatTextCmdParams text fmtRange fmtOpts) -> do
105- rootPath <- getRootPath
106- textEdit <- formatText rootPath fmtOpts text
107- case textEdit of
108- Left err -> return $ IdeResultFail
109- (IdeError PluginError
110- (T. pack $ " brittanyCmd: " ++ unlines (map showErr err))
111- Null
112- )
113- Right newText -> do
114- let edit = J. TextEdit fmtRange newText
115- return $ IdeResultOk [edit]
116-
11779-- | Extend to the line below to replace newline character, as above.
11880normalize :: Range -> Range
11981normalize (Range (Position sl _) (Position el _)) =
0 commit comments