Skip to content

Commit

Permalink
Fix error when source-file can not be found. (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Apr 5, 2019
1 parent 78e8267 commit 257cbb0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ regex_escape(str) = sprint(escape_string, str, "\\^\$.|?*+()[{")

# helper to display linerange for error printing
function find_block_in_file(code, file)
content = read(Base.find_source_file(file), String)
source_file = Base.find_source_file(file)
source_file === nothing && return nothing
content = read(source_file, String)
content = replace(content, "\r\n" => "\n")
# make a regex of the code that matches leading whitespace
rcode = "\\h*" * replace(regex_escape(code), "\\n" => "\\n\\h*")
blockidx = findfirst(Regex(rcode), content)
if blockidx !== nothing
startline = countlines(IOBuffer(content[1:prevind(content, first(blockidx))]))
endline = startline + countlines(IOBuffer(code)) + 1 # +1 to include the closing ```
return ":$(startline)-$(endline)"
else
return ""
end
blockidx === nothing && return nothing
startline = countlines(IOBuffer(content[1:prevind(content, first(blockidx))]))
endline = startline + countlines(IOBuffer(code)) + 1 # +1 to include the closing ```
return ":$(startline)-$(endline)"
end

# Pretty-printing locations
Expand Down

0 comments on commit 257cbb0

Please sign in to comment.