Пример #1
0
    def run(self, edit):
        if sublime.score_selector(self.view.scope_name(self.view.sel()[0].b),
                                  'source.php') == 0:
            return
        if self.fromMouseEvent:
            old_sel = [r for r in self.view.sel()]
            self.view.run_command("drag_select",
                                  {'event': self.fromMouseEvent})
            new_sel = self.view.sel()[0]
        editor = PhpCoder().editor(self.view)
        offset = 0
        pos = editor.getPosition()
        while re.match(r'[a-zA-Z_][a-zA-Z0-9_]*',
                       editor.substr(pos + offset, pos + offset + 1)):
            offset += 1
        expr = editor.expr()

        if expr:
            expr['prefix'] += editor.substr(pos, pos + offset)
            if editor.substr(pos + offset, pos + offset + 1) == '(':
                expr['prefix'] += '()'
        else:
            wordRegion = self.view.word(self.view.sel()[0])
            expr = {'prefix': '', 'expr': self.view.substr(wordRegion)}
            if editor.substr(wordRegion.begin() - 1,
                             wordRegion.begin()) == '$':
                expr['expr'] = '$' + expr['expr']

        if expr['expr']:
            resolver = phpcoder.resolver.Resolver(editor)
            self.prefix = None
            if expr['prefix']:
                parsedPrefix = resolver.parseExpression('Dummy' +
                                                        expr['prefix'])
                if parsedPrefix and len(parsedPrefix) > 1:
                    self.prefix = parsedPrefix[1]['name']
            self.matches = []
            for r in resolver.resolve(expr['expr']):
                if self.prefix == None or \
                    ('properties' in r and self.prefix in r['properties']) or \
                    ('methods' in r and self.prefix in r['methods']):
                    self.matches.append(r)

            results = []
            for r in self.matches:
                results.append([
                    r['name'] + expr['prefix'],
                    r['path'],
                ])
            if len(results) == 1:
                self.panel_on_select(0)
            elif len(results) > 0:
                self.view.window().show_quick_panel(
                    results,
                    self.panel_on_select,
                    on_highlight=self.panel_on_highlight)
Пример #2
0
 def _completeParams(self, editor, resolver):
     offset = 0
     pos = editor.getPosition() - 1
     open = 0
     loop = 0
     commas = 0
     while not(open == 1 or pos == offset):
         c = editor.substr(pos - offset, pos - offset + 1)
         if c == '(':
             open += 1
         elif c == ')':
             open -= 1
         elif open == 0 and c == ',':
             commas += 1
         offset += 1
     m = re.match(r'.*new\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\($', editor.substr(0, pos - offset + 2), re.DOTALL)
     if m:
         klass = m.group(1)
         expr = {'expr': m.group(1), 'prefix': '->__construct()'}
     else:
         expr = editor.expr(-1 * offset)
     ret = []
     if expr and expr['expr'] and expr['prefix']:
         parsedPrefix = resolver.parseExpression('Dummy' + expr['prefix'])
         if parsedPrefix and len(parsedPrefix) > 1:
             prefix = parsedPrefix[1]['name']
             completions = []
             for r in resolver.resolve(expr['expr']):
                 try:
                     method = r['methods'][prefix]
                     name = ''
                     value = ''
                     if commas > 0:
                         value = ' '
                     if 'params' in method:
                         p = 1
                         for param in method['params']:
                             if p > commas:
                                 if 'initial' in param:
                                     # Fix default values refering to self with correct class name
                                     initial = param['initial']
                                     initial = re.sub(r'^self', r['name'], initial)
                                     name += '$' + param['name'] + ' = ' + initial
                                     value += '${' + str(p) + ':/* \\$' + param['name'] + ' = */ ' + initial + '}, '
                                 else:
                                     name += '$' + param['name'];
                                     value += '${' + str(p) + ':\\$' + param['name'] + '}, '
                                 name += ', '
                                 ret.append([name.rstrip(', '), value.rstrip(', ')])
                             p += 1
                 except (Exception, ) as e:
                     print(e)
     return ret
Пример #3
0
    def run(self, edit):
        if sublime.score_selector(self.view.scope_name(self.view.sel()[0].b), 'source.php') == 0:
            return
        if self.fromMouseEvent:
            old_sel = [r for r in self.view.sel()]
            self.view.run_command("drag_select", {'event': self.fromMouseEvent})
            new_sel = self.view.sel()[0]
        editor = PhpCoder().editor(self.view)
        offset = 0
        pos = editor.getPosition()
        while re.match(r'[a-zA-Z_][a-zA-Z0-9_]*', editor.substr(pos + offset, pos + offset + 1)):
            offset += 1
        expr = editor.expr()
        
        if expr:
            expr['prefix'] += editor.substr(pos, pos+offset)
            if editor.substr(pos + offset, pos + offset + 1) == '(':
                expr['prefix'] += '()'
        else:
            wordRegion = self.view.word(self.view.sel()[0])
            expr = {'prefix': '', 'expr': self.view.substr(wordRegion)}
            if editor.substr(wordRegion.begin() - 1, wordRegion.begin()) == '$':
                expr['expr'] = '$' + expr['expr']

        if expr['expr']:
            resolver = phpcoder.resolver.Resolver(editor)
            self.prefix = None
            if expr['prefix']:
                parsedPrefix = resolver.parseExpression('Dummy' + expr['prefix'])
                if parsedPrefix and len(parsedPrefix) > 1:
                    self.prefix = parsedPrefix[1]['name']
            self.matches = []
            for r in resolver.resolve(expr['expr']):
                if self.prefix == None or \
                    ('properties' in r and self.prefix in r['properties']) or \
                    ('methods' in r and self.prefix in r['methods']):
                    self.matches.append(r)

            results = []
            for r in self.matches:
                results.append([
                    r['name'] + expr['prefix'],
                    r['path'], 
                ])
            if len(results) == 1:
                self.panel_on_select(0)
            elif len(results) > 0:
                self.view.window().show_quick_panel(results, self.panel_on_select, on_highlight = self.panel_on_highlight)
Пример #4
0
 def _completeParams(self, editor, resolver):
     offset = 0
     pos = editor.getPosition() - 1
     open = 0
     loop = 0
     commas = 0
     while not (open == 1 or pos == offset):
         c = editor.substr(pos - offset, pos - offset + 1)
         if c == '(':
             open += 1
         elif c == ')':
             open -= 1
         elif open == 0 and c == ',':
             commas += 1
         offset += 1
     m = re.match(r'.*new\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\($',
                  editor.substr(0, pos - offset + 2), re.DOTALL)
     if m:
         klass = m.group(1)
         expr = {'expr': m.group(1), 'prefix': '->__construct()'}
     else:
         expr = editor.expr(-1 * offset)
     ret = []
     if expr and expr['expr'] and expr['prefix']:
         parsedPrefix = resolver.parseExpression('Dummy' + expr['prefix'])
         if parsedPrefix and len(parsedPrefix) > 1:
             prefix = parsedPrefix[1]['name']
             completions = []
             for r in resolver.resolve(expr['expr']):
                 try:
                     method = r['methods'][prefix]
                     name = ''
                     value = ''
                     if commas > 0:
                         value = ' '
                     if 'params' in method:
                         p = 1
                         for param in method['params']:
                             if p > commas:
                                 if 'initial' in param:
                                     # Fix default values refering to self with correct class name
                                     initial = param['initial']
                                     initial = re.sub(
                                         r'^self', r['name'], initial)
                                     name += '$' + param[
                                         'name'] + ' = ' + initial
                                     value += '${' + str(
                                         p
                                     ) + ':/* \\$' + param[
                                         'name'] + ' = */ ' + initial + '}, '
                                 else:
                                     name += '$' + param['name']
                                     value += '${' + str(
                                         p) + ':\\$' + param['name'] + '}, '
                                 name += ', '
                                 ret.append([
                                     name.rstrip(', '),
                                     value.rstrip(', ')
                                 ])
                             p += 1
                 except (Exception, ) as e:
                     print(e)
     return ret