Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! [REPL] delete complete_path's mis-computation of startpos
  • Loading branch information
vtjnash committed Nov 15, 2023
commit 5435ff7f4c125bdf6da94e57d3c51239a87d7ab8
34 changes: 19 additions & 15 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,17 @@ 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
push!(matches, is_dir ? joinpath(file, "") : file)
is_dir = try isdir(p) catch ex; ex isa Base.IOError ? false : rethrow() end
push!(matches, is_dir ? 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,20 +373,22 @@ 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
Sys.iswindows() && map!(paths, paths) do c::PathCompletion
# emulation for unnecessarily complicated return value, since / is a
# perfectly acceptable path character which does not require quoting
# but is required by Pkg's awkward parser handling
return endswith(c.path, "/") ? PathCompletion(chop(c.path) * "\\\\") : c.path
end
return paths, startpos:pos, success
end
Expand Down