Merge pull request #166 from mcnicholls/autocomplete-non-existant-directory-fix
Autocomplete non existant directory fix
This commit is contained in:
commit
12bb28ceda
2 changed files with 34 additions and 10 deletions
|
|
@ -40,6 +40,7 @@ class AutoComplete
|
||||||
if @completions.length == 0
|
if @completions.length == 0
|
||||||
@completions = completeFunc()
|
@completions = completeFunc()
|
||||||
|
|
||||||
|
complete = ''
|
||||||
if @completions.length
|
if @completions.length
|
||||||
complete = @completions[@autoCompleteIndex % @completions.length]
|
complete = @completions[@autoCompleteIndex % @completions.length]
|
||||||
@autoCompleteIndex++
|
@autoCompleteIndex++
|
||||||
|
|
@ -63,8 +64,10 @@ class AutoComplete
|
||||||
basePath = path.dirname(filePath)
|
basePath = path.dirname(filePath)
|
||||||
baseName = path.basename(filePath)
|
baseName = path.basename(filePath)
|
||||||
|
|
||||||
|
try
|
||||||
|
basePathStat = fs.statSync(basePath)
|
||||||
|
if basePathStat.isDirectory()
|
||||||
files = fs.readdirSync(basePath)
|
files = fs.readdirSync(basePath)
|
||||||
|
|
||||||
return @filterByPrefix(files, baseName).map((f) =>
|
return @filterByPrefix(files, baseName).map((f) =>
|
||||||
filePath = path.join(basePath, f)
|
filePath = path.join(basePath, f)
|
||||||
if fs.lstatSync(filePath).isDirectory()
|
if fs.lstatSync(filePath).isDirectory()
|
||||||
|
|
@ -72,3 +75,6 @@ class AutoComplete
|
||||||
else
|
else
|
||||||
return command + ' ' + filePath
|
return command + ' ' + filePath
|
||||||
)
|
)
|
||||||
|
return []
|
||||||
|
catch err
|
||||||
|
return []
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ describe "autocomplete functionality", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@autoComplete = new AutoComplete(['taba', 'tabb', 'tabc'])
|
@autoComplete = new AutoComplete(['taba', 'tabb', 'tabc'])
|
||||||
@testDir = path.join(os.tmpdir(), "atom-ex-mode-spec-#{uuid.v4()}")
|
@testDir = path.join(os.tmpdir(), "atom-ex-mode-spec-#{uuid.v4()}")
|
||||||
|
@nonExistentTestDir = path.join(os.tmpdir(), "atom-ex-mode-spec-#{uuid.v4()}")
|
||||||
@testFile1 = path.join(@testDir, "atom-ex-testfile-a.txt")
|
@testFile1 = path.join(@testDir, "atom-ex-testfile-a.txt")
|
||||||
@testFile2 = path.join(@testDir, "atom-ex-testfile-b.txt")
|
@testFile2 = path.join(@testDir, "atom-ex-testfile-b.txt")
|
||||||
|
|
||||||
|
|
@ -80,3 +81,20 @@ describe "autocomplete functionality", ->
|
||||||
|
|
||||||
it "lists files once", ->
|
it "lists files once", ->
|
||||||
expect(@autoComplete.getFilePathCompletion.callCount).toBe(1)
|
expect(@autoComplete.getFilePathCompletion.callCount).toBe(1)
|
||||||
|
|
||||||
|
describe "autocomplete non existent directory", ->
|
||||||
|
beforeEach ->
|
||||||
|
@completed = @autoComplete.getAutocomplete('tabe ' + @nonExistentTestDir)
|
||||||
|
|
||||||
|
it "returns no completions", ->
|
||||||
|
expected = '';
|
||||||
|
expect(@completed).toEqual(expected)
|
||||||
|
|
||||||
|
describe "autocomplete existing file as directory", ->
|
||||||
|
beforeEach ->
|
||||||
|
filePath = @testFile1 + path.sep
|
||||||
|
@completed = @autoComplete.getAutocomplete('tabe ' + filePath)
|
||||||
|
|
||||||
|
it "returns no completions", ->
|
||||||
|
expected = '';
|
||||||
|
expect(@completed).toEqual(expected)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue