notifiers.vim 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. if exists('g:loaded_syntastic_notifiers') || !exists('g:loaded_syntastic_plugin')
  2. finish
  3. endif
  4. let g:loaded_syntastic_notifiers = 1
  5. let g:SyntasticNotifiers = {}
  6. let s:_NOTIFIER_TYPES = ['signs', 'balloons', 'highlighting', 'cursor', 'autoloclist']
  7. lockvar! s:_NOTIFIER_TYPES
  8. let s:_PERSISTENT_NOTIFIERS = ['signs', 'balloons']
  9. lockvar! s:_PERSISTENT_NOTIFIERS
  10. " Public methods {{{1
  11. function! g:SyntasticNotifiers.Instance() abort " {{{2
  12. if !exists('s:SyntasticNotifiersInstance')
  13. let s:SyntasticNotifiersInstance = copy(self)
  14. call s:SyntasticNotifiersInstance._initNotifiers()
  15. endif
  16. return s:SyntasticNotifiersInstance
  17. endfunction " }}}2
  18. function! g:SyntasticNotifiers.refresh(loclist) abort " {{{2
  19. if !a:loclist.isEmpty() && !a:loclist.isNewerThan([])
  20. " loclist not fully constructed yet
  21. return
  22. endif
  23. call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'notifiers: refresh')
  24. for type in self._enabled_types
  25. let class = substitute(type, '\m.*', 'Syntastic\u&Notifier', '')
  26. if !has_key(g:{class}, 'enabled') || self._notifier[type].enabled()
  27. if index(s:_PERSISTENT_NOTIFIERS, type) > -1
  28. " refresh only if loclist has changed since last call
  29. if !exists('b:syntastic_private_' . type . '_stamp')
  30. let b:syntastic_private_{type}_stamp = []
  31. endif
  32. if a:loclist.isNewerThan(b:syntastic_private_{type}_stamp) || a:loclist.isEmpty()
  33. call self._notifier[type].refresh(a:loclist)
  34. let b:syntastic_private_{type}_stamp = syntastic#util#stamp()
  35. endif
  36. else
  37. call self._notifier[type].refresh(a:loclist)
  38. endif
  39. endif
  40. endfor
  41. endfunction " }}}2
  42. function! g:SyntasticNotifiers.reset(loclist) abort " {{{2
  43. call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'notifiers: reset')
  44. for type in self._enabled_types
  45. let class = substitute(type, '\m.*', 'Syntastic\u&Notifier', '')
  46. " reset notifiers regardless if they are enabled or not, since
  47. " the user might have disabled them since the last refresh();
  48. " notifiers MUST be prepared to deal with reset() when disabled
  49. if has_key(g:{class}, 'reset')
  50. call self._notifier[type].reset(a:loclist)
  51. endif
  52. " also reset stamps
  53. if index(s:_PERSISTENT_NOTIFIERS, type) > -1
  54. let b:syntastic_private_{type}_stamp = []
  55. endif
  56. endfor
  57. endfunction " }}}2
  58. " }}}1
  59. " Private methods {{{1
  60. function! g:SyntasticNotifiers._initNotifiers() abort " {{{2
  61. let self._notifier = {}
  62. for type in s:_NOTIFIER_TYPES
  63. let class = substitute(type, '\m.*', 'Syntastic\u&Notifier', '')
  64. let self._notifier[type] = g:{class}.New()
  65. endfor
  66. let self._enabled_types = copy(s:_NOTIFIER_TYPES)
  67. endfunction " }}}2
  68. " }}}1
  69. " vim: set sw=4 sts=4 et fdm=marker: