Skip to content

Commit ba47db2

Browse files
committed
Auto merge of #1713 - eerden:zsh-autocompletion-testnames-fix, r=alexcrichton
Fixes #1703
2 parents d406d25 + d7cf7d9 commit ba47db2

File tree

1 file changed

+53
-43
lines changed

1 file changed

+53
-43
lines changed

src/etc/_cargo

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#compdef cargo
2+
23
typeset -A opt_args
34
autoload -U regexp-replace
45

@@ -206,7 +207,7 @@ case $state in
206207
'(-h, --help)'{-h,--help}'[show help message]' \
207208
'--manifest-path=[path to manifest]' \
208209
'(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
209-
'--precise=[update single dependency to PRECISE]: :_test_names' \
210+
'--precise=[update single dependency to PRECISE]: :' \
210211
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
211212
;;
212213

@@ -269,30 +270,10 @@ _describe 'command' commands
269270
}
270271

271272

273+
#FIXME: Disabled until fixed
272274
#gets package names from the manifest file
273-
_get_package_names(){
274-
local manifest=$(_locate_manifest)
275-
local -a packages;packages=()
276-
if ![[ $manifest ]]; then
277-
return 0
278-
fi
279-
280-
while read line
281-
do
282-
if [[ $line =~ '^.*dependencies' ]]; then
283-
regexp-replace line '^.*dependencies\.|\]' ''
284-
packages+=$line
285-
fi
286-
last_line=$line
287-
done < $manifest
288-
_describe 'packages' packages
289-
}
290-
291-
#TODO:parse Cargo.toml for benchmark names
292-
_benchmark_names(){
293-
local -a benchmarks;benchmarks=(
294-
)
295-
_describe 'tests' tests
275+
_get_package_names()
276+
{
296277
}
297278

298279
#TODO:see if it makes sense to have 'locate-project' to have non-json output.
@@ -303,26 +284,55 @@ regexp-replace manifest '\{"root":"|"\}' ''
303284
echo $manifest
304285
}
305286

306-
#gets test names from the manifest file
307-
_test_names(){
308-
local -a filelist;
309-
local manifest=$(_locate_manifest)
310-
if ![[ $manifest ]]; then
311-
return 0
312-
fi
313-
314-
local last_line
315-
local -a tests;
316-
tests=()
317-
while read line
318-
do
319-
if [[ $last_line == '[[test]]' ]]; then
320-
regexp-replace line '^.*name *= *|"' ""
321-
tests+=$line
287+
# Extracts the values of "name" from the array given in $1 and shows them as
288+
# command line options for completion
289+
_get_names_from_array()
290+
{
291+
local -a filelist;
292+
local manifest=$(_locate_manifest)
293+
if ! [[ $manifest ]]; then
294+
return 0
322295
fi
323-
last_line=$line
324-
done < $manifest
325-
_describe 'tests' tests
296+
297+
local last_line
298+
local -a names;
299+
local in_block=false
300+
local block_name=$1
301+
names=()
302+
while read line
303+
do
304+
if [[ $last_line == "[[$block_name]]" ]]; then
305+
in_block=true
306+
else
307+
if [[ $last_line =~ '.*\[\[.*' ]]; then
308+
in_block=false
309+
fi
310+
fi
311+
312+
if [[ $in_block == true ]]; then
313+
if [[ $line =~ '.*name.*=' ]]; then
314+
regexp-replace line '^.*name *= *|"' ""
315+
names+=$line
316+
fi
317+
fi
318+
319+
last_line=$line
320+
done < $manifest
321+
_describe $block_name names
322+
323+
}
324+
325+
#Gets the test names from the manifest file
326+
_test_names()
327+
{
328+
_get_names_from_array "test"
326329
}
327330

331+
#Gets the bench names from the manifest file
332+
_benchmark_names()
333+
{
334+
_get_names_from_array "bench"
335+
}
336+
337+
328338
_cargo

0 commit comments

Comments
 (0)