【发布时间】:2015-02-23 13:01:22
【问题描述】:
我尝试编写一个插件来让当前文件夹中的所有类进行自动完成注入。
以下代码在我的 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
但不知何故,当我使用名为“LandingController.java”的类在文件夹目录中工作并尝试获取结果时,自动完成根本不起作用。
但是,正如您可能注意到的那样,我对获得的所有内容进行了 error_message 输出,实际上找到了一个类名列表。
谁能帮我解决这个问题?谢谢!
【问题讨论】:
-
你不想返回
all_text而不是results吗? -
是
on_query_completions接受字符串而不是list作为注入结果吗? -
是的,它会的。有关如何构建完成的更多信息,请参阅the docs。
标签: python sublimetext3 sublime-text-plugin