CrystalAutoComplete.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:CrystalAutoComplete 作者: TechMagister 项目源码 文件源码
def on_query_completions(self, view, prefix, locations):
        # Check if this is a Crystal source file. This check
        # relies on the Crystal syntax formatting extension
        # being installed - https://github.com/crystal-lang/sublime-crystal
        if view.match_selector(locations[0], "source.crystal"):

            try:
                raw_results = run_cracker(view, locations[0])
            except FileNotFoundError:
                print("Unable to find cracker executable (check settings)")
                return

            results = []
            regexp = '[\.#](.+)\('

            for r in raw_results:
                if r.type == "Function":
                    if r.name.find("#") != -1:
                        trigger = r.name.split("#")[1]
                    else:
                        trigger = r.name.split(".")[1]
                    contents = trigger.split("(")[0]

                    if r.name.find("()") == -1:
                        contents = contents + '('
                else:
                    trigger = r.name
                    contents = r.name
                results.append([trigger, contents])

            if len(results) > 0:
                # return results
                return (results, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)


#class CrystalGotoDefinitionCommand(sublime_plugin.TextCommand):
#    def run(self, edit):
#        # Get the buffer location in correct format for cracker
#        row, col = self.view.rowcol(self.view.sel()[0].begin())
#        row += 1
#
#        results = run_cracker(self.view, ["find-definition", str(row), str(col)])
#
#        if len(results) == 1:
#            result = results[0]
#            path = result.path
#            # On Windows the cracker will return the paths without the drive
#            # letter and we need the letter for the open_file to work.
#            if sublime.platform() == 'windows' and not re.compile('^\w\:').match(path):
#                path = 'c:' + path
#            encoded_path = "{0}:{1}:{2}".format(path, result.row, result.column)
#            self.view.window().open_file(encoded_path, sublime.ENCODED_POSITION)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号