Fix autocompleting a non existent directory

This commit is contained in:
Michael Nicholls 2016-08-23 07:11:11 +01:00
parent fd0aa7a6c3
commit 0441b24c21

View file

@ -40,6 +40,7 @@ class AutoComplete
if @completions.length == 0
@completions = completeFunc()
complete = ''
if @completions.length
complete = @completions[@autoCompleteIndex % @completions.length]
@autoCompleteIndex++
@ -48,7 +49,7 @@ class AutoComplete
if complete.endsWith('/') && @completions.length == 1
@resetCompletion()
return complete
return complete
getCommandCompletion: (command) ->
return @filterByPrefix(@commands, command)
@ -63,12 +64,17 @@ class AutoComplete
basePath = path.dirname(filePath)
baseName = path.basename(filePath)
files = fs.readdirSync(basePath)
return @filterByPrefix(files, baseName).map((f) =>
filePath = path.join(basePath, f)
if fs.lstatSync(filePath).isDirectory()
return command + ' ' + filePath + path.sep
else
return command + ' ' + filePath
)
try
basePathStat = fs.statSync(basePath)
if basePathStat.isDirectory()
files = fs.readdirSync(basePath)
return @filterByPrefix(files, baseName).map((f) =>
filePath = path.join(basePath, f)
if fs.lstatSync(filePath).isDirectory()
return command + ' ' + filePath + path.sep
else
return command + ' ' + filePath
)
return []
catch err
return []