Skip to content

Commit 14dffad

Browse files
committed
Only display relative path of file that failed to parse
1 parent f1465db commit 14dffad

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

src/Terminal/Format.gren

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ run { fsPermission, pathToString, projectPath, outline } =
4545
parseFn { path, source } previous =
4646
Task.andThen
4747
(\previousFiles ->
48+
let
49+
relPath =
50+
pathRelativeFrom projectPath path
51+
in
4852
when Parser.run PM.parser Context.empty source is
4953
Ok _ ->
5054
Task.succeed <|
51-
Array.pushLast (pathToString path) previousFiles
55+
Array.pushLast (pathToString relPath) previousFiles
5256

5357
Err errs ->
5458
Task.fail <|
5559
ParseFailure
56-
{ path = path
60+
{ path = relPath
5761
, error = PM.errorsToString source errs
5862
}
5963
)
@@ -68,6 +72,37 @@ run { fsPermission, pathToString, projectPath, outline } =
6872
)
6973

7074

75+
pathRelativeFrom : Path -> Path -> Path
76+
pathRelativeFrom base absolute =
77+
let
78+
commonPrefix =
79+
findCommonPrefix 0 (Array.pushLast base.filename base.directory) absolute.directory
80+
in
81+
if commonPrefix > 0 then
82+
{ root = ""
83+
, directory = Array.dropFirst commonPrefix absolute.directory
84+
, filename = absolute.filename
85+
, extension = absolute.extension
86+
}
87+
88+
else
89+
absolute
90+
91+
92+
findCommonPrefix : Int -> Array String -> Array String -> Int
93+
findCommonPrefix count left right =
94+
when { l = Array.popFirst left, r = Array.popFirst right } is
95+
{ l = Just { first = lFirst, rest = lRest }, r = Just { first = rFirst, rest = rRest} } ->
96+
if lFirst == rFirst then
97+
findCommonPrefix (count + 1) lRest rRest
98+
99+
else
100+
count
101+
102+
_ ->
103+
count
104+
105+
71106
prettifyError : Error -> Report
72107
prettifyError error =
73108
when error is

0 commit comments

Comments
 (0)