fix tests

This commit is contained in:
Stanislav Seletskiy 2015-02-16 23:18:03 +06:00
parent b3aec07053
commit ed8cf49115
3 changed files with 11 additions and 10 deletions

View File

@ -44,7 +44,7 @@ class SnippetDefinition(object):
_TABS = re.compile(r"^\t*") _TABS = re.compile(r"^\t*")
def __init__(self, priority, trigger, value, description, def __init__(self, priority, trigger, value, description,
options, globals, location, context): options, globals, location, context=None):
self._priority = int(priority) self._priority = int(priority)
self._trigger = as_unicode(trigger) self._trigger = as_unicode(trigger)
self._value = as_unicode(value) self._value = as_unicode(value)

View File

@ -79,7 +79,6 @@ def _handle_snippet_or_global(filename, line, lines, python_globals, priority):
else: else:
context = None context = None
# Get and strip description if it exists # Get and strip description if it exists
remain = remain.strip() remain = remain.strip()
if len(remain.split()) > 1 and remain[-1] == '"': if len(remain.split()) > 1 and remain[-1] == '"':

View File

@ -203,18 +203,19 @@ class SnippetManager(object):
@err_to_scratch_buffer @err_to_scratch_buffer
def add_snippet(self, trigger, value, description, def add_snippet(self, trigger, value, description,
options, ft='all', priority=0): options, ft='all', priority=0, context=None):
"""Add a snippet to the list of known snippets of the given 'ft'.""" """Add a snippet to the list of known snippets of the given 'ft'."""
self._added_snippets_source.add_snippet(ft, self._added_snippets_source.add_snippet(ft,
UltiSnipsSnippetDefinition(priority, trigger, value, UltiSnipsSnippetDefinition(priority, trigger, value,
description, options, {}, 'added')) description, options, {}, 'added',
context))
@err_to_scratch_buffer @err_to_scratch_buffer
def expand_anon(self, value, trigger='', description='', options=''): def expand_anon(self, value, trigger='', description='', options='', context=None):
"""Expand an anonymous snippet right here.""" """Expand an anonymous snippet right here."""
before = _vim.buf.line_till_cursor before = _vim.buf.line_till_cursor
snip = UltiSnipsSnippetDefinition(0, trigger, value, description, snip = UltiSnipsSnippetDefinition(0, trigger, value, description,
options, {}, '') options, {}, '', context)
if not trigger or snip.matches(before): if not trigger or snip.matches(before):
self._do_snippet(snip, before) self._do_snippet(snip, before)
@ -573,10 +574,11 @@ class SnippetManager(object):
if not before: if not before:
return False return False
snippets = self._snips(before, False) snippets = self._snips(before, False)
# prefer snippets with context if any if snippets:
snippets_with_context = [s for s in snippets if s.context] # prefer snippets with context if any
if snippets_with_context: snippets_with_context = [s for s in snippets if s.context]
snippets = snippets_with_context if snippets_with_context:
snippets = snippets_with_context
if not snippets: if not snippets:
# No snippet found # No snippet found
return False return False