From 6fc235c5dce6994778c731e552da9cf02e74a121 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Sat, 20 May 2017 08:13:13 +0300 Subject: [PATCH] predict files: remove loop --- predict_files.go | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/predict_files.go b/predict_files.go index 4b8c84a..c8adf7e 100644 --- a/predict_files.go +++ b/predict_files.go @@ -30,29 +30,21 @@ func files(pattern string, allowFiles bool) PredictFunc { // if only one directory has matched the result, search recursively into // this directory to give more results. return func(a Args) (prediction []string) { - for { + prediction = predictFiles(a, pattern, allowFiles) - prediction = predictFiles(a, pattern, allowFiles) - - // if the number of prediction is not 1, we either have many results or - // have no results, so we return it. - if len(prediction) != 1 { - return - } - - // if the result is only one item, we might want to recursively check - // for more accurate results. - if prediction[0] == a.Last { - return - } - - // only try deeper, if the one item is a directory - if stat, err := os.Stat(prediction[0]); err != nil || !stat.IsDir() { - return - } - - a.Last = prediction[0] + // if the number of prediction is not 1, we either have many results or + // have no results, so we return it. + if len(prediction) != 1 { + return } + + // only try deeper, if the one item is a directory + if stat, err := os.Stat(prediction[0]); err != nil || !stat.IsDir() { + return + } + + a.Last = prediction[0] + return predictFiles(a, pattern, allowFiles) } }