Skip to content

Commit

Permalink
fix(list): fix throw error on vim
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Feb 14, 2019
1 parent 5cdc38e commit 32f69fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
10 changes: 9 additions & 1 deletion autoload/coc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,18 @@ function! coc#util#timer(method, args)
if !s:is_vim
call call(a:method, a:args)
else
call timer_start(0, { -> call(a:method, a:args)})
call timer_start(0, { -> s:Call(a:method, a:args)})
endif
endfunction

function! s:Call(method, args)
try
call call(a:method, a:args)
catch /.*/
return 0
endtry
endfunction

function! coc#util#is_preview(bufnr)
let wnr = bufwinnr(a:bufnr)
if wnr == -1 | return 0 | endif
Expand Down
24 changes: 15 additions & 9 deletions src/list/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,25 @@ export class ListManager {
return
}
let { isVim } = workspace
if (workspace.bufnr == bufnr) {
let curr = await nvim.call('bufnr', '%')
if (curr == bufnr) {
this.prompt.start()
if (isVim) nvim.command(`set t_ve=`, true)
} else {
this.prompt.cancel()
if (isVim) nvim.call('coc#list#restore', [], true)
}
}, 200), null, this.disposables)
this.ui.onDidChangeLine(async () => {
}, 100), null, this.disposables)
this.ui.onDidChangeLine(debounce(async () => {
if (!this.activated) return
let previewing = await nvim.call('coc#util#has_preview')
if (previewing) await this.doAction('preview')
}, null, this.disposables)
this.ui.onDidLineChange(async () => {
}, 100), null, this.disposables)
this.ui.onDidLineChange(debounce(async () => {
let { autoPreview } = this.listOptions
if (!autoPreview || !this.activated) return
await this.doAction('preview')
}, null, this.disposables)
}, 100), null, this.disposables)
this.ui.onDidOpen(async () => {
if (this.currList) {
this.currList.doHighlight()
Expand Down Expand Up @@ -199,13 +200,13 @@ export class ListManager {
if (this.executing) return
this.executing = true
let { nvim, ui } = this
let shouldCancel = action.persist !== true && action.name != 'preview'
try {
if (action.persist !== true && action.name != 'preview') {
await this.cancel()
}
if (shouldCancel) await this.cancel()
if (action.name == 'preview') {
items = items.slice(0, 1)
}
if (!shouldCancel && !this.isActivated) return
if (action.parallel) {
await Promise.all(items.map(item => {
return Promise.resolve(action.execute(item, this.context))
Expand All @@ -215,8 +216,13 @@ export class ListManager {
await Promise.resolve(action.execute(item, this.context))
}
}
if (!shouldCancel && !this.isActivated) {
this.nvim.command('pclose', true)
return
}
if (action.persist || action.name == 'preview') {
let { window } = ui
if (!window) return
let valid = await window.valid
if (!valid) return
nvim.pauseNotification()
Expand Down
1 change: 0 additions & 1 deletion src/list/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export default class Prompt {
cmds.push(`echon '${post.replace(/'/g, "''")}'`)
}
}
if (workspace.isVim) cmds.push('redraw')
let cmd = cmds.join('|')
this.nvim.command(cmd, true)
}
Expand Down
6 changes: 1 addition & 5 deletions src/list/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ export default class ListUI {
let lnum = await nvim.call('line', '.')
if (this.currIndex + 1 == lnum) return
this.currIndex = lnum - 1
timer = setTimeout(() => {
if (workspace.bufnr == this.bufnr) {
this._onDidChangeLine.fire(lnum)
}
}, 100)
this._onDidChangeLine.fire(lnum)
}, null, this.disposables)
}

Expand Down

0 comments on commit 32f69fc

Please sign in to comment.