Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when source-file can not be found. #996

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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