Skip to content

Commit

Permalink
fixup! [REPL] delete complete_path's mis-computation of startpos
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 15, 2023
1 parent ff0fbbd commit 4f64654
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,16 @@ function complete_path(path::AbstractString;
else
return Completion[], dir, false
end
catch
catch ex
ex isa Base.IOError || rethrow()
return Completion[], dir, false
end

matches = Set{String}()
for file in files
if startswith(file, prefix)
p = joinpath(dir, file)
is_dir = try isdir(p) catch; false end
is_dir = try isdir(p) catch; ex isa Base.IOError ? false : rethrow() end
push!(matches, is_dir ? joinpath(file, "") : file)
end
end
Expand All @@ -313,7 +314,8 @@ function complete_path(path::AbstractString;
for pathdir in pathdirs
actualpath = try
realpath(pathdir)
catch
catch ex
ex isa Base.IOError || rethrow()
# Bash doesn't expect every folder in PATH to exist, so neither shall we
continue
end
Expand Down Expand Up @@ -371,21 +373,17 @@ function complete_path(path::AbstractString,
## TODO: enable this depwarn once Pkg is fixed
#Base.depwarn("complete_path with pos argument is deprecated because the return value [2] is incorrect to use", :complete_path)
paths, dir, success = complete_path(path; use_envpath, shell_escape, string_escape)
if success
if Base.Sys.isunix() && occursin(r"^~(?:/|$)", path)
# if the path is just "~", don't consider the expanded username as a prefix
if path == "~"
dir, prefix = homedir(), ""
else
dir, prefix = splitdir(homedir() * path[2:end])
end
if Base.Sys.isunix() && occursin(r"^~(?:/|$)", path)
# if the path is just "~", don't consider the expanded username as a prefix
if path == "~"
dir, prefix = homedir(), ""
else
dir, prefix = splitdir(path)
dir, prefix = splitdir(homedir() * path[2:end])
end
startpos = pos - lastindex(prefix) + 1
else
startpos = pos + 1
dir, prefix = splitdir(path)
end
startpos = pos - lastindex(prefix) + 1
return paths, startpos:pos, success
end

Expand Down

0 comments on commit 4f64654

Please sign in to comment.