Esempio n. 1
0
    def _load_snippets(self) -> None:
        buf = self._vim.current.buffer
        filetype: str = self._vim.call('deoppet#util#_get_context_filetype')
        if not filetype:
            filetype = 'nothing'
        snippets_dirs = self._vim.call('deoppet#custom#_get_option',
                                       'snippets_dirs')
        ft_snippets_map = self._vim.call('deoppet#custom#_get_option',
                                         'ft_snippets_map')
        if filetype in ft_snippets_map:
            fts = ft_snippets_map[filetype]
        else:
            fts = filetype.split(',')

        snippets: typing.Dict[str, Snippet] = {}
        for dir in snippets_dirs:
            for ft in fts:
                for filename in glob.glob(f'{dir}/{ft}.snip') + glob.glob(
                        f'{dir}/_.snip'):
                    # debug(self._vim, filename)
                    with open(filename) as f:
                        parser = Parser(self._vim, filename)
                        snippets.update(parser.parse(f.read()))
        # debug(self._vim, snippets)
        buf.vars['deoppet_snippets'] = snippets
Esempio n. 2
0
def test_parse_error():
    parser = Parser()

    test_snippet0 = """
snippet bar
"""

    assert parser.parse(test_snippet0) == {}
Esempio n. 3
0
def test_parse_error():
    vim = Mock()
    parser = Parser(vim)

    test_snippet0 = """
snippet bar
"""

    assert parser.parse(test_snippet0) == {}
Esempio n. 4
0
    def __init__(self, vim):
        self._vim = vim
        self._parser = Parser()
        self._mapping = Mapping(self._vim)
        self._snippets = {}

        for filename in globruntime(self._vim.options['runtimepath'],
                                    'neosnippets/*.snip'):
            # debug(self._vim, filename)
            with open(filename) as f:
                self._snippets.update(self._parser.parse(f.read()))
        self._vim.current.buffer.vars['deoppet_snippets'] = self._snippets

        self._vim.call('deoppet#mapping#_init')
        self._vim.call('deoppet#handler#_init')
Esempio n. 5
0
def test_parse_success():
    parser = Parser()

    test_snippet0 = """
"""

    test_snippet1 = """
snippet    foo
   foobar
"""

    test_snippet2 = """
snippet    foo
   foobar

snippet    bar
   baz
"""

    test_snippet3 = """
snippet    foo
abbr       bar
alias      baz
regexp     '^% '
options    word
   foobar
"""

    test_snippet4 = """
snippet    foo
   foobar ${1} ${2}
"""

    assert parser.parse(test_snippet0) == {}

    assert parser.parse(test_snippet1) == {
        'foo': {
            'trigger': 'foo',
            'text': 'foobar',
            'options': {},
            'tabstops': [],
        }
    }

    assert parser.parse(test_snippet2) == {
        'foo': {
            'trigger': 'foo',
            'text': 'foobar',
            'options': {},
            'tabstops': [],
        },
        'bar': {
            'trigger': 'bar',
            'text': 'baz',
            'options': {},
            'tabstops': [],
        }
    }

    assert parser.parse(test_snippet3) == {
        'foo': {
            'trigger': 'foo',
            'abbr': 'bar',
            'alias': 'baz',
            'regexp': '^% ',
            'options': {
                'word': True
            },
            'text': 'foobar',
            'tabstops': [],
        }
    }

    assert parser.parse(test_snippet4) == {
        'foo': {
            'trigger':
            'foo',
            'text':
            'foobar  ',
            'options': {},
            'tabstops': [
                {
                    'number': 1,
                    'row': 0,
                    'col': 7,
                    'default': ''
                },
                {
                    'number': 2,
                    'row': 0,
                    'col': 8,
                    'default': ''
                },
            ],
        }
    }
Esempio n. 6
0
def test_parse_success():
    vim = Mock()
    parser = Parser(vim)

    test_snippet0 = """
"""

    assert parser.parse(test_snippet0) == {}

    test_snippet1 = """
snippet    foo
   foobar
"""

    assert parser.parse(test_snippet1) == {
        'foo': {
            'trigger': 'foo',
            'text': 'foobar',
            'regexp': '',
            'options': {},
            'tabstops': [],
            'evals': [],
        }
    }

    test_snippet2 = """
snippet    foo
   foobar

snippet    bar
   baz
"""

    assert parser.parse(test_snippet2) == {
        'foo': {
            'trigger': 'foo',
            'text': 'foobar',
            'regexp': '',
            'options': {},
            'tabstops': [],
            'evals': [],
        },
        'bar': {
            'trigger': 'bar',
            'text': 'baz',
            'regexp': '',
            'options': {},
            'tabstops': [],
            'evals': [],
        }
    }

    test_snippet3 = """
snippet    foo
abbr       bar
alias      baz
regexp     '^% '
options    word
   foobar
"""

    assert parser.parse(test_snippet3) == {
        'foo': {
            'trigger': 'foo',
            'abbr': 'bar',
            'alias': 'baz',
            'regexp': '^% ',
            'options': {'word': True},
            'text': 'foobar',
            'tabstops': [],
            'evals': [],
        }
    }

    test_snippet4 = """
snippet    foo
   foobar ${1} ${2}
"""

    assert parser.parse(test_snippet4) == {
        'foo': {
            'trigger': 'foo',
            'text': 'foobar  ',
            'regexp': '',
            'options': {},
            'tabstops': [
                {'number': 1, 'row': 0, 'col': 7, 'default': '', 'comment': ''},
                {'number': 2, 'row': 0, 'col': 8, 'default': '', 'comment': ''},
            ],
            'evals': [],
        }
    }

    test_snippet5 = """
snippet     if
abbr        if endif
options     head
    if ${1:#:condition}
      ${0:TARGET}
    endif

snippet     elseif
options     head
    elseif condition
        TARGET
"""

    assert parser.parse(test_snippet5) == {
        'if': {
            'abbr': 'if endif',
            'trigger': 'if',
            'text': 'if \n\nendif',
            'regexp': '',
            'options': {'head': True},
            'tabstops': [
                {
                    'number': 1, 'row': 0, 'col': 3,
                    'default': '#:condition', 'comment': ''
                 },
                {
                    'number': 0, 'row': 1, 'col': 0,
                    'default': 'TARGET', 'comment': ''
                },
            ],
            'evals': [],
        },
        'elseif': {
            'trigger': 'elseif',
            'text': 'elseif condition\nTARGET',
            'regexp': '',
            'options': {'head': True},
            'tabstops': [
            ],
            'evals': [],
        }
    }