[英]Bad autocompletion in SublimeText3 when pressing tab in PHP array
[英]Autocompletion list RESET when typing a dot on SublimeText
我實現了SublimeText自動補全插件:
import sublime_plugin
import sublime
tensorflow_functions = ["tf.test","tf.AggregationMethod","tf.Assert","tf.AttrValue", (etc....)]
class TensorflowAutocomplete(sublime_plugin.EventListener):
def __init__(self):
self.tf_completions = [("%s \tTensorflow" % s, s) for s in tensorflow_functions]
def on_query_completions(self, view, prefix, locations):
if view.match_selector(locations[0], 'source.python'):
return self.tf_completions
else:
return[]
效果很好,但問題是當我鍵入“。”時。 重置完成建議。
例如,我輸入“ tf”會提示我所有自定義列表,但隨后輸入“ tf”。 它向我顯示了一個列表,因為我之前沒有鍵入“ tf”。 我希望我的腳本考慮點之前鍵入的內容。
很難解釋。 你知道我需要做什么嗎?
編輯:
這是它的作用:
您可以在此處看到“ tf”沒有突出顯示。
通常,Sublime Text會替換所有內容,直到最后一個單詞分隔符(即點)為止,然后插入您的完成文本。
如果要插入帶有單詞分隔符的補全,只需要剝離內容,該內容將不會被替換。 因此,您只需看一下前面的行,提取最后一個點之前的文本,過濾並剝離完成的內容。 這是我執行此操作的一般模式:
import re
import sublime_plugin
import sublime
tensorflow_functions = ["tf.AggregationMethod()","tf.Assert()","tf.AttrValue()","tf.AttrValue.ListValue()"]
RE_TRIGGER_BEFORE = re.compile(
r"\w*(\.[\w\.]+)"
)
class TensorflowAutocomplete(sublime_plugin.EventListener):
def __init__(self):
self.tf_completions = [("%s \tTensorflow" % s, s) for s in tensorflow_functions]
def on_query_completions(self, view, prefix, locations):
loc = locations[0]
if not view.match_selector(loc, 'source.python'):
return
completions = self.tf_completions
# get the inverted line before the location
line_before_reg = sublime.Region(view.line(loc).a, loc)
line_before = view.substr(line_before_reg)[::-1]
# check if it matches the trigger
m = RE_TRIGGER_BEFORE.match(line_before)
if m:
# get the text before the .
trigger = m.group(1)[::-1]
# filter and strip the completions
completions = [
(c[0], c[1][len(trigger):]) for c in completions
if c[1].startswith(trigger)
]
return completions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.