예제 #1
0
 def on_query_completions(self, view, prefix, locations):
     results = []
     try:
         cTags = CTags(view)
     except CTagsException as e:
         status_message('YAC: CTags exception: ' + str(e))
         return results
     setting = Setting(view)
     parser = Parser(view)
     if not parser.isCurrentPositionAMethod() or not view.window().folders():
         return results
     if not setting.isSupportedSyntax():
         status_message('YAC: auto complete not supported for language "' + setting.getSyntax() + '"')
         return results
     currentClass = cTags.getClassFromName(parser.getClassFromMethodInCurrentPosition())
     results = cTags.getMethodsFromClass(currentClass, prefix)
     if len(results):
         results = [(result.getDefinitionLine().strip(), result.getDefinitionLine.strip().replace('$', '\$')) for result in results]
         return (results, sublime.INHIBIT_EXPLICIT_COMPLETIONS)
     else:
         return results
예제 #2
0
class YacGoToDefinitionCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        self.parser = Parser(self.view)
        word = self.parser.getCurrentPositionSymbol()
        try:
            self.cTags = CTags(self.view)
        except CTagsException as e:
            status_message('YAC: CTags exception: ' + str(e))
            return
        if len(word) > 0:
            if self.parser.isCurrentPositionAMethod():
                currentClass = self.cTags.getClassFromName(self.parser.getClassFromMethodInCurrentPosition())
                if currentClass:
                    results = self.cTags.getMethodsFromClass(currentClass, word)
                    if len(results) > 0:
                        self.showQuickPanel(results)
                        return
            if self.parser.isCurrentPositionAFunction():
                results = self.cTags.getFunctionsFromName(word)
                if len(results) > 0:
                    self.showQuickPanel(results)
                    return
            results = self.cTags.getClassesFromName(word)
            if len(results) > 0:
                self.showQuickPanel(results)
                return
        status_message('YAC: current symbol not found')

    def showQuickPanel(self, items):
        self.items = items
        if len(items) == 1:
            self.goToItem(0)
        else:
            sublime.active_window().show_quick_panel([[item.getName(), self.cTags.getRelativeFilePath(item.getFile())] for item in self.items], self.goToItem)

    def goToItem(self, idx):
        if idx >= 0:
            sublime.active_window().open_file(self.items[idx].getFile() + ':' + self.items[idx].getDefinitionLineNumber(), sublime.ENCODED_POSITION)