简体   繁体   English

vim / vimrc:如何查找失败的Python插件

[英]vim / vimrc: How to find the Python plugin that's failing

When I start up vim, I get the following error printed: 当我启动vim时,出现以下错误:

$ vim -V9foo.log
Error detected while processing function <SNR>14_DependenciesValid:
line   12:
Traceback (most recent call last):
  File "<string>", line 6, in <module>
AttributeError: 'module' object has no attribute 'vars'
Press ENTER or type command to continue

Looking on this site, I find a few recommendations to use -V9 to print everything vim is doing. 在该站点上,我发现一些建议使用-V9打印vim正在做的所有事情。 However, when I do this, I do not see the failure! 但是,当我这样做时,我看不到失败!

I can also use -V9foo.log to print everything it's doing to a log file (foo.log) When I do that, the startup work is all printed there, but the error is printed to the terminal. 我还可以使用-V9foo.log将其所做的所有操作打印到日志文件(foo.log)中,然后将启动工作全部打印在该文件中,但将错误打印到终端。 My guess thus is that the Python plugin runner does not know of the vim -V output target, or the python runtime error is printed straight to stderr. 因此,我的猜测是Python插件运行程序不知道vim -V输出目标,或者将python运行时错误直接打印到stderr。

Unfortunately, the Python error is extremely unhelpful. 不幸的是,Python错误是毫无帮助的。 I cannot find a function named DependenciesValid in any of my vim plugins, and the rest of the error is all "sourced from some string, using some module, have fun finding where this is!" 我在任何一个vim插件中都找不到一个名为DependenciesValid的函数,其余的错误全都是“使用某个模块从某个字符串中获取的,找到它在哪里很有趣!”

I use Vundle for plug-ins, and the only reason I do that is that I want to use ensime for in-editor Scala browsing. 我将Vundle用于插件,而这样做的唯一原因是我想使用ensime进行编辑器内Scala浏览。

Commenting out ensime/ensime-vim makes the error go away, which locates the particular bundle, but doesn't get me any closer to where in the bundle the error actually happens, or why. 注释掉ensime / ensime-vim可以使错误消失,错误可以找到特定的软件包,但并不能使我更接近错误在软件包中的实际发生位置或原因。

Here's my .vimrc: 这是我的.vimrc:

set nocompatible
filetype off

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" Plugin 'jewes/Conque-Shell'
Plugin 'ensime/ensime-vim'
Plugin 'derekwyatt/vim-scala'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

" syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

" My Stuff
set expandtab
set hidden
set ts=4
set ignorecase
set sw=4

I'm running on ubuntu 12.04 LTS (no, this is not currently upgradeable.) 我正在ubuntu 12.04 LTS上运行(不,当前无法升级。)

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:24:26)
Included patches: 1-429

$ uname -a
Linux (hostname) 3.19.0-32-generic #37~14.04.1 SMP Fri Nov 6 00:01:52 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

<SNR>14_DependenciesValid14表示脚本编号,如:scriptnames

I finally debugged this. 我终于调试了这个。

First, I commented out each plugin in turn until I found which one was causing the error. 首先,我依次注释掉每个插件,直到找到哪个插件导致了错误。 It was ensime-vim. 这是ensime-vim。

Second, I grepped the source for that plugin for the text "vars" which is the variable name it's trying to read/write from some module. 其次,我为该插件的源添加了文本“ vars”,这是它试图从某个模块读取/写入的变量名。

I found a few references, and looked them all up, figuring out where they are called. 我找到了一些参考,然后将它们全部查找,找出它们的调用位置。 It turns out, a recent change to the ensime-vim plugin did something akin to: 事实证明,最近对ensime-vim插件进行的更改类似于:

import vim
vim.vars['some_global_name'] = 1

The "vim" module does not contain a "vars" member in VIM 7.3, hence this fails. VIM 7.3中的“ vim”模块不包含“ vars”成员,因此失败。

Python could be more helpful about this. Python可能对此有所帮助。 It says "module" does not have a member named "vars" but it doesn't tell me what the module is named. 它说“模块”没有名为“ vars”的成员,但没有告诉我模块的名称。 It could know. 它可以知道。 Also, Python just says that "string" was the location of the error -- it could print the line out of the string, verbatim, to help track down the problem. 而且,Python只是说“字符串”是错误的位置-它可以逐字逐字地从字符串中打印出一行,以帮助找出问题所在。

Separately, Vim could be more helpful about this. 另外,Vim对此可能会更有帮助。 It could know which .vim file contained the Python code that errored out, and it could print the file/line that defined the Python that errored out. 它可以知道哪个.vim文件包含出错的Python代码,并且可以打印定义出错的Python的文件/行。

It turns out, neither -D, nor -V9 (which is the general recommendation on the internet before I was told about -V13 by Meninx) was all that helpful :-( 事实证明,-D或-V9(在Meninx告诉我-V13之前,这是互联网上的一般建议)都没有帮助:-(

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

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