简体   繁体   English

一段时间之后恼人的sublime文本autocompletion for Python(`self` keyword)

[英]Annoying sublime text autocompletion for Python after period (`self` keyword)

I'm using sublime text 3 for python development. 我正在使用sublime text 3进行python开发。 I have autocompletion turned on as I type, which works. 当我输入时,我打开了自动完成功能。 I expect, that when I type an object name followed by a period, a list of object's methods/attributes would popup. 我希望,当我键入一个对象名后跟一个句点时,会弹出一个对象的方法/属性列表。 It does not happen, so I press Tab . 它没有发生,所以我按Tab

import time
time.[TAB]

What happens now, is just absolutely weird! 现在发生了什么,真是太奇怪了! . is replaced by self. self.取代self. , so I end up with 所以我最终得到了

import time
timeself.

I was looking in all setting files, I tried packages python completions , code intel and code complice , but none of them disabled this "feature", which drives me crazy! 我正在寻找所有设置文件,我尝试了包python completionscode intelcode complice ,但没有一个禁用这个“功能”,这让我发疯!

Finally, I have found Jedi package, which solved this issue for the text editor. 最后,我找到了Jedi包,它解决了文本编辑器的这个问题。 But I still have problems in the interpreter window (package SublimeREPL ). 但我仍然在解释器窗口(包SublimeREPL )中遇到问题。 By the way, if I install both Jedi and code complice , the autocompletion in the REPL seems to work better, but it offers some irrelevant crap like %%! 顺便说一下,如果我同时安装了Jedicode complice ,REPL中的自动完成似乎工作得更好,但它提供了一些像%%!这样无关紧要的废话%%! or %%HTML . %%HTML And yes, if I press [TAB] twice, I still end up with timeself. 是的,如果我按两次[TAB],我仍然会自己结束timeself. instead of time. 而不是time. !

Does anyone know what's going on? 有谁知道发生了什么? Where this . 这个. -> self. - > self. behavior is coming from? 行为来自哪里? How to disable %%! 如何禁用%%! stuff? 东西?

I had this problem myself, and it was not easy to track down. 我自己遇到了这个问题,追踪并不容易。

The problem is not caused by any package. 问题不是由任何包引起的。 I found out after running default built of Sublime text 3. While I highly recommend Anaconda (as mentioned by MattDMo), the problem can occur also when Anaconda is installed. 我在运行默认构建的Sublime文本3后发现了。虽然我强烈推荐使用Anaconda(如MattDMo所述),但安装Anaconda时也会出现问题。

The problem: 问题:

The cause of the problem is the default Python snippet shipped with Sublime Text 3 called self.sublime-snippet and looks like this: 问题的原因是Sublime Text 3附带的默认Python片段self.sublime-snippet ,如下所示:

<snippet>
    <content><![CDATA[self.]]></content>
    <tabTrigger>.</tabTrigger>
    <scope>source.python</scope>
    <description>self</description>
</snippet>

In Sublime text 2, this file can simply be removed, but the default snippets in ST3 isn't stored in the same way, so there is no way to easily delete this file. 在Sublime文本2中,可以简单地删除此文件,但ST3中的默认代码段不会以相同的方式存储,因此无法轻松删除此文件。

The solution: 解决方案:

This stack overflow answer explains how to extract the package information for a language, in this case Python. 此堆栈溢出答案解释了如何提取语言的包信息,在本例中为Python。 The snippet can then be deleted as normally. 然后可以正常删除该代码段。

Update: 更新:

The snippet has now been removed in the source code due to this problem. 由于此问题,现在已在源代码中删除了代码段。 Probably included in next update. 可能包含在下一次更新中。 Source: https://github.com/sublimehq/Packages/issues/473 资料来源: https//github.com/sublimehq/Packages/issues/473

I would highly recommend getting rid of your other completion packages and install Anaconda (no relation to the Anaconda Python distribution). 我强烈建议摆脱你的其他完成包并安装Anaconda (与Anaconda Python发行版无关)。 I've been using it for a couple of years now, and I absolutely love it. 我已经使用它几年了,我非常喜欢它。 Basically all you need to do to set it up is provide a path for "python_interpreter" in Anaconda's settings or in your project 's settings, and it just works. 基本上你需要做的就是在Anaconda的设置或项目的设置中提供"python_interpreter"的路径,它就可以了。 No taking forever to index everything like SublimeCodeIntel, and no need to set up a separate linter if you don't want to, because several linters are built-in. 不要永远索引像SublimeCodeIntel这样的所有东西,如果你不想要,也不需要设置一个单独的linter,因为内置了几个linters。 Virtualenvs are seamless. Virtualenvs是无缝的。 Anaconda will see all the modules available to the version of Python specified by "python_interpreter" , so you don't need to worry about adding extra paths to the environment through settings. Anaconda将看到"python_interpreter"指定的Python版本可用的所有模块,因此您无需担心通过设置向环境添加额外路径。 Make sure you copy all of the default settings file into the user settings file, then change the options as needed. 确保将所有默认设置文件复制到用户设置文件中,然后根据需要更改选项。 Project-specific settings override user settings, so you can customize even more by editing your project. 特定于项目的设置会覆盖用户设置,因此您可以通过编辑项目来进行更多自定义。

BTW, I'm not affiliated with the project in any way, except for a minor pull request or two, I'm just a very satisfied user. 顺便说一句,我不是以任何方式加入该项目,除了一个或两个小的拉取请求,我只是一个非常满意的用户。

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

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