@@ -8,6 +8,7 @@ using Core: CodeInfo, MethodInstance, CodeInstance, Const
8
8
const CC = Core. Compiler
9
9
using Base. Meta
10
10
using Base: propertynames, something, IdSet
11
+ using Base. Filesystem: _readdirx
11
12
12
13
abstract type Completion end
13
14
@@ -317,8 +318,8 @@ function cache_PATH()
317
318
continue
318
319
end
319
320
320
- filesinpath = try
321
- readdir (pathdir)
321
+ path_entries = try
322
+ _readdirx (pathdir)
322
323
catch e
323
324
# Bash allows dirs in PATH that can't be read, so we should as well.
324
325
if isa (e, Base. IOError) || isa (e, Base. ArgumentError)
@@ -328,13 +329,13 @@ function cache_PATH()
328
329
rethrow ()
329
330
end
330
331
end
331
- for file in filesinpath
332
+ for entry in path_entries
332
333
# In a perfect world, we would filter on whether the file is executable
333
334
# here, or even on whether the current user can execute the file in question.
334
335
try
335
- if isfile (joinpath (pathdir, file) )
336
- @lock PATH_cache_lock push! (PATH_cache, file )
337
- push! (this_PATH_cache, file )
336
+ if isfile (entry )
337
+ @lock PATH_cache_lock push! (PATH_cache, entry . name )
338
+ push! (this_PATH_cache, entry . name )
338
339
end
339
340
catch e
340
341
# `isfile()` can throw in rare cases such as when probing a
@@ -378,11 +379,11 @@ function complete_path(path::AbstractString;
378
379
else
379
380
dir, prefix = splitdir (path)
380
381
end
381
- files = try
382
+ entries = try
382
383
if isempty (dir)
383
- readdir ()
384
+ _readdirx ()
384
385
elseif isdir (dir)
385
- readdir (dir)
386
+ _readdirx (dir)
386
387
else
387
388
return Completion[], dir, false
388
389
end
@@ -392,11 +393,10 @@ function complete_path(path::AbstractString;
392
393
end
393
394
394
395
matches = Set {String} ()
395
- for file in files
396
- if startswith (file, prefix)
397
- p = joinpath (dir, file)
398
- is_dir = try isdir (p) catch ex; ex isa Base. IOError ? false : rethrow () end
399
- push! (matches, is_dir ? file * " /" : file)
396
+ for entry in entries
397
+ if startswith (entry. name, prefix)
398
+ is_dir = try isdir (entry) catch ex; ex isa Base. IOError ? false : rethrow () end
399
+ push! (matches, is_dir ? entry. name * " /" : entry. name)
400
400
end
401
401
end
402
402
@@ -1349,14 +1349,15 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
1349
1349
append! (suggestions, project_deps_get_completion_candidates (s, dir))
1350
1350
end
1351
1351
isdir (dir) || continue
1352
- for pname in readdir (dir)
1352
+ for entry in _readdirx (dir)
1353
+ pname = entry. name
1353
1354
if pname[1 ] != ' .' && pname != " METADATA" &&
1354
1355
pname != " REQUIRE" && startswith (pname, s)
1355
1356
# Valid file paths are
1356
1357
# <Mod>.jl
1357
1358
# <Mod>/src/<Mod>.jl
1358
1359
# <Mod>.jl/src/<Mod>.jl
1359
- if isfile (joinpath (dir, pname) )
1360
+ if isfile (entry )
1360
1361
endswith (pname, " .jl" ) && push! (suggestions,
1361
1362
PackageCompletion (pname[1 : prevind (pname, end - 2 )]))
1362
1363
else
@@ -1365,7 +1366,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
1365
1366
else
1366
1367
pname
1367
1368
end
1368
- if isfile (joinpath (dir, pname , " src" ,
1369
+ if isfile (joinpath (entry , " src" ,
1369
1370
" $mod_name .jl" ))
1370
1371
push! (suggestions, PackageCompletion (mod_name))
1371
1372
end
0 commit comments