@@ -25,7 +25,8 @@ import Node.Path (FilePath)
25
25
import Node.WorkerBees as Worker
26
26
import Partial.Unsafe (unsafeCrashWith )
27
27
import PureScript.CST (RecoveredParserResult (..), parseModule )
28
- import PureScript.CST.Errors (ParseError , printParseError )
28
+ import PureScript.CST.Errors (printParseError )
29
+ import PureScript.CST.Parser.Monad (PositionedError )
29
30
import Tidy (defaultFormatOptions , formatModule , toDoc )
30
31
import Tidy.Operators (parseOperatorTable )
31
32
import Tidy.Precedence (PrecedenceMap , remapOperators )
@@ -70,7 +71,7 @@ type WorkerOutput =
70
71
, timing :: Number
71
72
}
72
73
73
- formatCommand :: FormatOptions -> PrecedenceMap -> String -> Either ParseError String
74
+ formatCommand :: FormatOptions -> PrecedenceMap -> String -> Either String String
74
75
formatCommand args operators contents = do
75
76
let
76
77
print = Dodo .print Dodo .plainText
@@ -92,9 +93,13 @@ formatCommand args operators contents = do
92
93
}
93
94
Right $ print $ toDoc $ formatModule opts ok
94
95
ParseSucceededWithErrors _ errs -> do
95
- Left ( NonEmptyArray .head errs).error
96
+ Left $ printPositionedError $ NonEmptyArray .head errs
96
97
ParseFailed err ->
97
- Left err.error
98
+ Left $ printPositionedError err
99
+
100
+ printPositionedError :: PositionedError -> String
101
+ printPositionedError { error, position } =
102
+ " [" <> show (position.line + 1 ) <> " :" <> show (position.column + 1 ) <> " ] " <> printParseError error
98
103
99
104
formatInPlaceCommand :: Boolean -> PrecedenceMap -> WorkerInput -> Aff WorkerOutput
100
105
formatInPlaceCommand shouldCheck operators { filePath, config } = do
@@ -129,8 +134,8 @@ formatInPlaceCommand shouldCheck operators { filePath, config } = do
129
134
else do
130
135
FS .writeTextFile UTF8 filePath formatted
131
136
pure { filePath, error: " " , alreadyFormatted: false , timing }
132
- Left err ->
133
- pure { filePath, error: printParseError err , alreadyFormatted: false , timing: zero }
137
+ Left error ->
138
+ pure { filePath, error, alreadyFormatted: false , timing: zero }
134
139
135
140
main :: Effect Unit
136
141
main = Worker .makeAsMain \{ receive, reply, workerData: { shouldCheck, operatorsByPath } } -> do
0 commit comments