You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
1.2 KiB

  1. #=============================================================================
  2. # FILE: neosnippet.py
  3. # AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
  4. # License: MIT license
  5. #=============================================================================
  6. import re
  7. from .base import Base
  8. class Source(Base):
  9. def __init__(self, vim):
  10. Base.__init__(self, vim)
  11. self.name = 'neosnippet'
  12. self.mark = '[ns]'
  13. self.rank = 200
  14. self.__cache = {}
  15. def on_event(self, context):
  16. self.__cache[context['filetype']] = self.vim.eval(
  17. 'values(neosnippet#helpers#get_completion_snippets())')
  18. for candidate in self.__cache[context['filetype']]:
  19. candidate['dup'] = 1
  20. candidate['menu'] = candidate['menu_abbr']
  21. def gather_candidates(self, context):
  22. candidates = self.__cache.get(context['filetype'], [])
  23. if context['filetype'] not in self.__cache:
  24. self.on_event(context)
  25. m1 = re.match(r'\w+$', context['complete_str'])
  26. m2 = re.match(r'\S+$', context['complete_str'])
  27. if m1 and m2 and m1.group(0) != m2.group(0):
  28. candidates = [x for x in candidates if x['options']['word']]
  29. return candidates