简体   繁体   English

如何从 Sublime Text 4 自动完成列表中删除当前缓冲区中的单词

[英]How to remove words in the current buffer from Sublime Text 4 autocomplete list

For the past 8 years or so, this plugin has worked fine with Sublime Text 2 and 3 to remove words in the current buffer from the ctrl + space autocomplete list, but it no longer works in ST4 (b4126):在过去 8 年左右的时间里,这个插件与 Sublime Text 2 和 3 配合得很好,可以从ctrl + space自动完成列表中删除当前缓冲区中的单词,但它不再适用于 ST4 (b4126):

import sublime, sublime_plugin

class MyAutocomplete(sublime_plugin.EventListener):
  def on_query_completions(self, view, prefix, locations):
    # Popup autocomplete only for .sublime-snippet and
    # .sublime-completions files
    return ([], sublime.INHIBIT_WORD_COMPLETIONS)

I know the on_query_completions and sublime.INHIBIT_WORD_COMPLETIONS are still valid, so I think the problem is with the array return statement.我知道on_query_completionssublime.INHIBIT_WORD_COMPLETIONS仍然有效,所以我认为问题出在数组返回语句上。 The docs don't show any changes between versions. 文档没有显示版本之间的任何更改。

The only variation of a return statement I was able to get sublime.INHIBIT_WORD_COMPLETIONS to work with was this, but now I've got an extra completion in the list I don't want:我能够使用sublime.INHIBIT_WORD_COMPLETIONS的 return 语句的唯一变体是这个,但现在我在列表中多了一个我不想要的补全:

return [
  sublime.CompletionItem(
    trigger="fox",
    completion="The quick brown fox jumps over the lazy dog",
    kind=sublime.KIND_KEYWORD
  )
], sublime.INHIBIT_WORD_COMPLETIONS

Had no luck at all with sublime.CompletionList or set_completionssublime.CompletionListset_completions运气都没有

It seems like it isn't possible to inhibit buffer/word completions without returning at least one completion.似乎不可能在不返回至少一个完成的情况下禁止缓冲区/单词完成。 But, if that completion (both trigger and outcome) is a single character, it will never be relevant, and thus the autocomplete will never be shown.但是,如果该完成(触发器和结果)是单个字符,它将永远不会相关,因此永远不会显示自动完成。

import sublime, sublime_plugin


class InhibitWordCompletionsEventListener(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        clist = sublime.CompletionList()
        sublime.set_timeout(lambda: clist.set_completions([' '], sublime.INHIBIT_WORD_COMPLETIONS), 0)
        return clist

(Note: partially based on a comment on https://github.com/sublimehq/sublime_text/issues/4999 , which I found while searching to see if a bug was reported for this or not.) (注意:部分基于对https://github.com/sublimehq/sublime_text/issues/4999的评论,我在搜索是否报告了此错误时发现了该评论。)

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

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