@@ -9,6 +9,7 @@ module Ext.ElmFormat where
9
9
import Data.Text (Text )
10
10
import qualified Data.Text as T
11
11
import qualified Data.Text as Text
12
+ import System.IO (FilePath )
12
13
13
14
import System.IO.Unsafe (unsafePerformIO )
14
15
import qualified System.Process
@@ -20,31 +21,35 @@ import qualified ElmFormat.Cli
20
21
-- import qualified ElmFormat.Render.Text as Render
21
22
import ElmVersion
22
23
import ElmFormat.Messages
24
+ import Reporting.Annotation (Located (.. ), Region (.. ), Position (.. ))
25
+ import CommandLine.InfoFormatter (ToConsole (.. ))
23
26
24
27
25
- formatWithEmbedded :: Text -> Either ElmFormat.Messages. InfoMessage Text
26
- formatWithEmbedded inputText = do
27
- ElmFormat.Cli. format ElmVersion. Elm_0_19 (" stdin:nofilepath " , inputText)
28
+ formatWithEmbedded :: FilePath -> Text -> Either ElmFormat.Messages. InfoMessage Text
29
+ formatWithEmbedded filePath inputText = do
30
+ ElmFormat.Cli. format ElmVersion. Elm_0_19 (filePath , inputText)
28
31
29
32
30
- format :: Text -> (Either Text Text )
31
- format text = do
32
- case formatWithEmbedded text of
33
- Left err ->
34
- Left $ Lamdera. show_ err
35
- Right formatted ->
36
- Right formatted
33
+ format :: FilePath -> Text -> (Either Text Text )
34
+ format filePath text = do
35
+ case formatWithEmbedded filePath text of
36
+ Left err -> Left $ toConsole err
37
+ Right formatted -> Right formatted
37
38
38
39
39
40
formatOrPassthrough :: Text -> Text
40
41
formatOrPassthrough text = do
41
- case format text of
42
+ case format " stdin " text of
42
43
Right formatted -> formatted
43
- Left err -> do
44
- -- let !_ = Lamdera.debug $ "🔥💅 warning: " <> show err
45
- text
44
+ Left _ -> text
46
45
47
46
47
+ formatOrPassthroughFile :: FilePath -> Text -> Text
48
+ formatOrPassthroughFile filePath text = do
49
+ case format filePath text of
50
+ Right formatted -> formatted
51
+ Left _ -> text
52
+
48
53
49
54
-- Old versions that rely on local elm-format binary
50
55
0 commit comments