简体   繁体   English

sublime text 3自动完成插件无法正常工作

[英]sublime text 3 auto-complete plugin not working

I try to write a plugin to get all the classes in current folder to do an auto-complete injection. 我尝试编写一个插件来获取当前文件夹中的所有类来进行自动完成注入。

the following code is in my python file: 以下代码在我的python文件中:

class FolderPathAutoComplete(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        folders = view.window().folders()
        results = get_path_classes(folders)
        all_text = ""
        for result in results:
            all_text += result + "\n"
        #sublime.error_message(all_text)
        return results


def get_path_classes(folders):
    classesList = []
    for folder in folders:
        for root, dirs, files in os.walk(folder):
            for filename in files:
                filepath = root +"/"+filename
                if filepath.endswith(".java"):
                    filepath = filepath.replace(".java","")
                    filepath = filepath[filepath.rfind("/"):]
                    filepath = filepath[1:]
                    classesList.append(filepath)
    return classesList

but somehow when I work in a folder dir with a class named "LandingController.java" and I try to get the result, the auto complete is not working at all. 但不知何故,当我在一个名为“LandingController.java”的类的文件夹目录中工作并尝试获取结果时,自动完成功能根本无效。

However, as you may noticed I did a error_message output of all the contents I got, there are actual a list of class name found. 但是,正如您可能已经注意到我输入了所有内容的error_message输出,实际上找到了一个类名列表。

Can anyone help me solve this? 谁能帮我解决这个问题? thank you! 谢谢!

It turn outs that the actual format which sublime text accept is: [(word,word),...] 事实证明,sublime文本接受的实际格式是:[(word,word),...]

but thanks to MattDMo who point out the documentation since the official documentation says nothing about the auto complete part. 但感谢MattDMo指出文档,因为官方文档没有说明汽车完整部分。

For better understanding of the auto complete injection api, you could follow Zinggi's plugin DictionaryAutoComplete and this is the github link 为了更好地理解自动完成注入api,您可以按照Zinggi的插件DictionaryAutoComplete进行操作,这是github链接

So for a standard solution: 所以对于标准解决方案:

class FolderPathAutoComplete(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
        suggestlist = self.get_autocomplete_list(prefix)
        return suggestlist


    def get_autocomplete_list(self, word):
        global classesList

        autocomplete_list = []
        uniqueautocomplete = set()
        # filter relevant items:
        for w in classesList:
            try:
                if word.lower() in w.lower():
                    actual_class = parse_class_path_only_name(w)
                    if actual_class not in uniqueautocomplete:
                        uniqueautocomplete.add(actual_class)
                        autocomplete_list.append((actual_class, actual_class))
            except UnicodeDecodeError:
                print(actual_class)
                # autocomplete_list.append((w, w))
                continue

        return autocomplete_list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM