mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 03:04:30 +08:00
Compare commits
223 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90f0bff2de | ||
|
|
d43768c7b5 | ||
|
|
8aa53ee576 | ||
|
|
51802fa151 | ||
|
|
1388f46137 | ||
|
|
57a2cc787b | ||
|
|
b1205ce779 | ||
|
|
3ad63c9458 | ||
|
|
3d4a594519 | ||
|
|
c1ff868cb4 | ||
|
|
44b8165ba3 | ||
|
|
e324a34c69 | ||
|
|
7b8e6bd6ed | ||
|
|
485e02d3b5 | ||
|
|
17bfd3b276 | ||
|
|
0d50a1caec | ||
|
|
e8b9fcb5d1 | ||
|
|
4e0d196e92 | ||
|
|
493d89302a | ||
|
|
bd68a98848 | ||
|
|
eceba1e675 | ||
|
|
4508fc22f8 | ||
|
|
21ce925ccb | ||
|
|
04c3fc9d1b | ||
|
|
a9ffcbbda9 | ||
|
|
882c5f0611 | ||
|
|
7bf66ebab2 | ||
|
|
20a63f6c0f | ||
|
|
0ba4993d5d | ||
|
|
b8269d70d4 | ||
|
|
a247e9b1c7 | ||
|
|
aa56af0d9c | ||
|
|
b8edeef966 | ||
|
|
2a3eaeb2dc | ||
|
|
e1cac7d3f7 | ||
|
|
27d35b4fc0 | ||
|
|
df81a593ec | ||
|
|
63162524c2 | ||
|
|
ec405fa3b2 | ||
|
|
1c24594c70 | ||
|
|
45dd72b557 | ||
|
|
e31fcf8580 | ||
|
|
f082e2b75a | ||
|
|
90d2208554 | ||
|
|
dd89f6ba6b | ||
|
|
d1f8a91fd3 | ||
|
|
f405ce625a | ||
|
|
320809c211 | ||
|
|
acfbc6850b | ||
|
|
e053a78c01 | ||
|
|
7939ef7298 | ||
|
|
4672275d62 | ||
|
|
ed629d5ec1 | ||
|
|
f0c46450c9 | ||
|
|
81b752f606 | ||
|
|
d85413feaa | ||
|
|
b618e5b863 | ||
|
|
39eba902c4 | ||
|
|
02a7c89a37 | ||
|
|
c3f9f03065 | ||
|
|
fe3840770a | ||
|
|
48d0370387 | ||
|
|
dd426c6369 | ||
|
|
3934359666 | ||
|
|
8a385ffa54 | ||
|
|
d2106d73c6 | ||
|
|
36e84dd112 | ||
|
|
87ac865919 | ||
|
|
3ce655f428 | ||
|
|
111cca5106 | ||
|
|
63f159aa76 | ||
|
|
505c067c54 | ||
|
|
e534aeee4b | ||
|
|
3154c4ab08 | ||
|
|
178b064821 | ||
|
|
b9154c7353 | ||
|
|
eae610a88d | ||
|
|
c1ec986732 | ||
|
|
c7b3ad9e2c | ||
|
|
c4980738bd | ||
|
|
ed3748a9b9 | ||
|
|
a83489e62a | ||
|
|
ac754b4785 | ||
|
|
d29bd89d58 | ||
|
|
fa405c2e3d | ||
|
|
8adc9d1eda | ||
|
|
3a96300d65 | ||
|
|
45c34d5e93 | ||
|
|
7245dff650 | ||
|
|
bb4d5a6504 | ||
|
|
32a1593d10 | ||
|
|
a9c654fe48 | ||
|
|
6c9b115661 | ||
|
|
9d2259a63d | ||
|
|
11681e2aa7 | ||
|
|
6fa00cd548 | ||
|
|
429f402675 | ||
|
|
70d65d6981 | ||
|
|
3d53e26298 | ||
|
|
89208a798e | ||
|
|
5d9d48b15b | ||
|
|
6e360a4f15 | ||
|
|
1e08c815e5 | ||
|
|
4e0f5d7ab9 | ||
|
|
683257be6b | ||
|
|
bdc6a03ac2 | ||
|
|
0fe47ce214 | ||
|
|
22149611a3 | ||
|
|
8672280054 | ||
|
|
c7c266ed29 | ||
|
|
2b52548b37 | ||
|
|
bdf86d53f1 | ||
|
|
d9d5a329f0 | ||
|
|
b5b31aa0e6 | ||
|
|
dcf884a6ca | ||
|
|
c3bea09d74 | ||
|
|
3fb703f0a7 | ||
|
|
8fb8d9903c | ||
|
|
592d19f29e | ||
|
|
2991ec7d55 | ||
|
|
10bad3310d | ||
|
|
83540e66a4 | ||
|
|
eba0689bff | ||
|
|
90bdf0c106 | ||
|
|
7e116d8295 | ||
|
|
52ff4176ed | ||
|
|
53137b85a7 | ||
|
|
c6de6c3425 | ||
|
|
23d7b99f96 | ||
|
|
d1d453b891 | ||
|
|
c49b68a25d | ||
|
|
b8ff144ed5 | ||
|
|
c8c4399d45 | ||
|
|
5993b0c599 | ||
|
|
0b8448804d | ||
|
|
59be959a3d | ||
|
|
1247e258d0 | ||
|
|
100e1ed8cd | ||
|
|
63029f5ea2 | ||
|
|
c58fc7c952 | ||
|
|
748a47e6e9 | ||
|
|
a74c3bd29a | ||
|
|
6ed0b78c90 | ||
|
|
99b53f200f | ||
|
|
9f683c4cbf | ||
|
|
6ee05f976d | ||
|
|
bba9682197 | ||
|
|
00814ef58d | ||
|
|
e01eadb9ed | ||
|
|
7c1aa736ff | ||
|
|
e93976ad44 | ||
|
|
6028e0d379 | ||
|
|
cf6551f17e | ||
|
|
33b58d894c | ||
|
|
be4039995a | ||
|
|
64aeebb12b | ||
|
|
5e5d308348 | ||
|
|
ddad7b8a90 | ||
|
|
bbebff8a21 | ||
|
|
380ab946e5 | ||
|
|
ca50a02a86 | ||
|
|
26492d1d32 | ||
|
|
bf62eebca4 | ||
|
|
dbafc2c0e3 | ||
|
|
108cfbdd5d | ||
|
|
622331afa4 | ||
|
|
9c3e9dbe03 | ||
|
|
a8422d3682 | ||
|
|
6f107578ee | ||
|
|
355203cab0 | ||
|
|
e4a2a0f30e | ||
|
|
efb1997218 | ||
|
|
cf3182e549 | ||
|
|
2cc0adcc65 | ||
|
|
d56bf264e7 | ||
|
|
b9fef7b969 | ||
|
|
dd70fa0891 | ||
|
|
ccc901f360 | ||
|
|
f88c11e353 | ||
|
|
e8e1cc7d47 | ||
|
|
34bf4479d8 | ||
|
|
403028a50c | ||
|
|
3ae35c1ea1 | ||
|
|
fcc8cf5185 | ||
|
|
ab5065753e | ||
|
|
daa7f1c60c | ||
|
|
42b240c366 | ||
|
|
211cbf1fb7 | ||
|
|
001db4bfe5 | ||
|
|
422ad483c1 | ||
|
|
165dea0a2c | ||
|
|
5b1a253e9b | ||
|
|
8c482c72db | ||
|
|
354f8da568 | ||
|
|
31611335b4 | ||
|
|
a8726171bf | ||
|
|
4c0652064a | ||
|
|
0d27821064 | ||
|
|
93e49bb888 | ||
|
|
84a982ee26 | ||
|
|
4bc8a44453 | ||
|
|
e6ef96412e | ||
|
|
c1026023f2 | ||
|
|
15605d77d6 | ||
|
|
a763f12b4e | ||
|
|
d0b0413e7b | ||
|
|
7d1d5bd492 | ||
|
|
7577ddc7a7 | ||
|
|
61f457b666 | ||
|
|
f9ea25ec4e | ||
|
|
6a4d7c40ca | ||
|
|
ed8dcf6f5d | ||
|
|
c2cbe4133e | ||
|
|
1d14abfff8 | ||
|
|
fdcc192def | ||
|
|
d5ba11971b | ||
|
|
70f4c16ae3 | ||
|
|
bf7a5b82bb | ||
|
|
f2354d3700 | ||
|
|
f234bf4376 | ||
|
|
5a5c383aa6 | ||
|
|
2b0e66b565 | ||
|
|
69e4cead81 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,2 +1,6 @@
|
||||
*.swp
|
||||
*.pyc
|
||||
*~
|
||||
*.sw?
|
||||
*.py[cod]
|
||||
.ropeproject
|
||||
doc/tags
|
||||
.cache
|
||||
|
||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
||||
[submodule "jedi"]
|
||||
path = jedi
|
||||
url = git://github.com/davidhalter/jedi.git
|
||||
url = https://github.com/davidhalter/jedi.git
|
||||
|
||||
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
language: python
|
||||
install:
|
||||
- pip install --quiet --use-mirrors pytest
|
||||
script:
|
||||
- vim --version
|
||||
- py.test
|
||||
42
AUTHORS.txt
42
AUTHORS.txt
@@ -1,11 +1,45 @@
|
||||
Main Authors
|
||||
============
|
||||
|
||||
David Halter (@davidhalter)
|
||||
David Halter (@davidhalter) <davidhalter88@gmail.com>
|
||||
|
||||
|
||||
Contributors
|
||||
============
|
||||
Contributors (in order of contributions)
|
||||
========================================
|
||||
|
||||
Danilo Bargen (@gwrtheyrn)
|
||||
Patrice Peterson (@runiq)
|
||||
tek (@tek)
|
||||
heavenshell (@heavenshell) <heavenshell.jp@gmail.com>
|
||||
Danilo Bargen (@dbrgn) <gezuru@gmail.com>
|
||||
mattn (@mattn) <mattn.jp@gmail.com>
|
||||
Enrico Batista da Luz (@ricobl) <rico.bl@gmail.com>
|
||||
coot (@coot) <mszamot@gmail.com>
|
||||
Artur Dryomov (@ming13) <artur.dryomov@gmail.com>
|
||||
andviro (@andviro)
|
||||
Jean-Louis Fuchs (@ganwell) <ganwell@fangorn.ch>
|
||||
Mathieu Comandon (@strycore) <strider@strycore.com>
|
||||
Nick Hurley (@todesschaf) <hurley@todesschaf.org>
|
||||
gpoulin (@gpoulin)
|
||||
Akinori Hattori (@hattya)
|
||||
Luper Rouch (@flupke)
|
||||
Matthew Moses (@mlmoses) <moses.matthewl@gmail.com>
|
||||
Tyler Wymer (@twymer)
|
||||
Artem Nezvigin (@artnez)
|
||||
rogererens (@rogererens)
|
||||
Emily Strickland (@emilyst) <mail@emily.st>
|
||||
Tin Tvrtković (@Tinche) <tinchester@gmail.com>
|
||||
Zekeriya Koc (@zekzekus) <zekzekus@gmail.com>
|
||||
ethinx (@ethinx) <eth2net@gmail.com>
|
||||
Wouter Overmeire (@lodagro) <lodagro@gmail.com>
|
||||
Stephen J. Fuhry (@fuhrysteve) <fuhrysteve@gmail.com>
|
||||
Sheng Yun (@ShengYun) <uewing@gmail.com>
|
||||
Yann Thomas-Gérard (@inside) <inside@gmail.com>
|
||||
Colin Su (@littleq0903) <littleq0903@gmail.com>
|
||||
Arthur Jaron (@eyetracker)
|
||||
Justin M. Keyes (@justinmk)
|
||||
nagev (@np1)
|
||||
Chris Lasher (@gotgenes) <chris.lasher@gmail.com>
|
||||
Doan Thanh Nam (@tndoan)
|
||||
|
||||
|
||||
@something are github user names.
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
Pull Requests are great (on the **dev** branch)!
|
||||
|
||||
1. Fork the Repo on github.
|
||||
2. If you are adding functionality or fixing a bug, please add a test!
|
||||
3. Push to your fork and submit a **pull request to the dev branch**.
|
||||
2. Add yourself to AUTHORS.txt
|
||||
3. Add a test if possible.
|
||||
4. Push to your fork and submit a **pull request to the dev branch**.
|
||||
|
||||
My **master** branch is a 100% stable (should be). I only push to it after I am
|
||||
certain that things are working out. Many people are using Jedi directly from
|
||||
|
||||
183
LICENSE.txt
183
LICENSE.txt
@@ -1,170 +1,21 @@
|
||||
Licensed under the GNU LGPL v3 or later.
|
||||
Copyright (C) 2012 David Halter <davidhalter88@gmail.com>.
|
||||
The MIT License (MIT)
|
||||
|
||||
===============================================================================
|
||||
Copyright (c) <2013> <David Halter and others, see AUTHORS.txt>
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
161
README.rst
161
README.rst
@@ -2,12 +2,12 @@
|
||||
jedi-vim - awesome Python autocompletion with VIM
|
||||
#################################################
|
||||
|
||||
**now in beta testing phase**
|
||||
.. image:: https://travis-ci.org/davidhalter/jedi-vim.png?branch=master
|
||||
:target: https://travis-ci.org/davidhalter/jedi-vim
|
||||
:alt: Travis-CI build status
|
||||
|
||||
*If you have any comments or feature requests, please tell me! I really want to
|
||||
know, what you think about Jedi and jedi-vim.*
|
||||
|
||||
jedi-vim is a is a VIM binding to the awesome autocompletion library *Jedi*.
|
||||
jedi-vim is a is a VIM binding to the autocompletion library
|
||||
`Jedi <http://github.com/davidhalter/jedi>`_.
|
||||
|
||||
Here are some pictures:
|
||||
|
||||
@@ -21,41 +21,72 @@ Display of function/class bodies, docstrings.
|
||||
|
||||
.. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_pydoc.png
|
||||
|
||||
Pydoc support (with highlighting, Shift+k).
|
||||
Documentation (Pydoc) support (with highlighting, Shift+k).
|
||||
|
||||
There is also support for goto and renaming.
|
||||
|
||||
|
||||
Get the latest from `github <http://github.com/davidhalter/jedi-vim>`_.
|
||||
|
||||
You can get the Jedi library is documented
|
||||
`here <http://github.com/davidhalter/jedi>`_.
|
||||
Documentation
|
||||
=============
|
||||
|
||||
Documentation is available in your vim: ``:help jedi-vim``. You can also look
|
||||
it up `on github <http://github.com/davidhalter/jedi-vim>`_.
|
||||
|
||||
You can read the Jedi library documentation `here <http://jedi.jedidjah.ch>`_.
|
||||
|
||||
|
||||
Support
|
||||
=======
|
||||
Contributing
|
||||
============
|
||||
|
||||
The Jedi library supports most of Python's core features. From decorators to
|
||||
We love Pull Requests! Read the instructions in ``CONTRIBUTING.md``.
|
||||
|
||||
|
||||
Features
|
||||
========
|
||||
|
||||
The Jedi library understands most of Python's core features. From decorators to
|
||||
generators, there is broad support.
|
||||
|
||||
Apart from that, jedi-vim supports the following commands
|
||||
|
||||
- Completion ``<C-Space>``
|
||||
- Goto assignments ``<leader>g`` (typical goto function)
|
||||
- Goto definitions ``<leader>d`` (follow identifier as far as possible,
|
||||
includes imports and statements)
|
||||
- Show Documentation/Pydoc ``K`` (shows a popup with assignments)
|
||||
- Renaming ``<leader>r``
|
||||
- Usages ``<leader>n`` (shows all the usages of a name)
|
||||
- Open module, e.g. ``:Pyimport os`` (opens the ``os`` module)
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ to
|
||||
install jedi in VIM. Also you need a VIM version that was compiled with
|
||||
``+python``, which is typical for most distributions on Linux.
|
||||
You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ or
|
||||
`vundle <https://github.com/gmarik/vundle>`_ to install jedi in VIM. Also you
|
||||
need a VIM version that was compiled with ``+python``, which is typical for most
|
||||
distributions on Linux.
|
||||
|
||||
The first thing you need after that is an up-to-date version of Jedi. You can
|
||||
either get it via ``pip install jedi`` or with ``git submodule update --init``
|
||||
in your jedi-vim repository.
|
||||
|
||||
The autocompletion can be used with <ctrl+space>, if you want it to work with
|
||||
<tab> you can use `supertab <https://github.com/ervandew/supertab>`_.
|
||||
On Arch Linux, you can also install jedi-vim from AUR: `vim-jedi
|
||||
<https://aur.archlinux.org/packages/vim-jedi/>`__.
|
||||
|
||||
Note that the `python-mode <https://github.com/klen/python-mode>`_ VIM plugin seems
|
||||
to conflict with jedi-vim, therefore you should disable it before enabling
|
||||
jedi-vim.
|
||||
|
||||
To enjoy the full features of Jedi-Vim, you should have VIM >= 7.3. For older
|
||||
version of VIM, the parameter recommendation list maybe not appeared when you type
|
||||
open bracket after the function name.
|
||||
|
||||
|
||||
Options
|
||||
=======
|
||||
Settings
|
||||
========
|
||||
|
||||
Jedi is by default automatically initialized. If you don't want that I suggest
|
||||
you disable the auto-initialization in your ``.vimrc``:
|
||||
@@ -64,30 +95,13 @@ you disable the auto-initialization in your ``.vimrc``:
|
||||
|
||||
let g:jedi#auto_initialization = 0
|
||||
|
||||
There are also some VIM options (like ``completeopt``) which are automatically
|
||||
initialized, if you don't want that:
|
||||
There are also some VIM options (like ``completeopt`` and key defaults) which
|
||||
are automatically initialized, but you can change all of them:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#auto_vim_configuration = 0
|
||||
|
||||
The goto is by default on <leader g>. If you want to change that:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#goto_command = "<leader>g"
|
||||
|
||||
``get_definition`` is by default on <leader d>. If you want to change that:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#get_definition_command = "<leader>d"
|
||||
|
||||
Showing the pydoc is by default on ``K`` If you want to change that:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#pydoc = "K"
|
||||
|
||||
If you are a person who likes to use VIM-buffers not tabs, you might want to
|
||||
put that in your ``.vimrc``:
|
||||
@@ -96,6 +110,14 @@ put that in your ``.vimrc``:
|
||||
|
||||
let g:jedi#use_tabs_not_buffers = 0
|
||||
|
||||
If you are a person who likes to use VIM-splits, you might want to put this in your ``.vimrc``:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#use_splits_not_buffers = "left"
|
||||
|
||||
This options could be "left", "right", "top" or "bottom". It will decide the direction where the split open.
|
||||
|
||||
Jedi automatically starts the completion, if you type a dot, e.g. ``str.``, if
|
||||
you don't want this:
|
||||
|
||||
@@ -103,27 +125,74 @@ you don't want this:
|
||||
|
||||
let g:jedi#popup_on_dot = 0
|
||||
|
||||
There's some support for refactoring:
|
||||
Jedi selects the first line of the completion menu: for a better typing-flow
|
||||
and usually saves one keypress.
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#popup_select_first = 0
|
||||
|
||||
Here are a few more defaults for actions, read the docs (``:help jedi-vim``) to
|
||||
get more information. If you set them to ``""``, they are not assigned.
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#goto_assignments_command = "<leader>g"
|
||||
let g:jedi#goto_definitions_command = "<leader>d"
|
||||
let g:jedi#documentation_command = "K"
|
||||
let g:jedi#usages_command = "<leader>n"
|
||||
let g:jedi#completions_command = "<C-Space>"
|
||||
let g:jedi#rename_command = "<leader>r"
|
||||
let g:jedi#show_call_signatures = "1"
|
||||
|
||||
And you can list all names that are related (have the same origin):
|
||||
|
||||
Finally, if you don't want completion, but all the other features, use:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#related_names_command = "<leader>n"
|
||||
let g:jedi#completions_enabled = 0
|
||||
|
||||
If you want to change the default autocompletion command:
|
||||
FAQ
|
||||
===
|
||||
|
||||
I don't want the docstring window to popup during completion
|
||||
------------------------------------------------------------
|
||||
|
||||
This depends on the ``completeopt`` option. Jedi initializes it in its
|
||||
``ftplugin``. Add the following line to your ``.vimrc`` to disable it:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#autocompletion_command = "<C-Space>"
|
||||
autocmd FileType python setlocal completeopt-=preview
|
||||
|
||||
By default you get a window that displays the function definition you're
|
||||
currently in. If you don't want that:
|
||||
|
||||
.. code-block:: vim
|
||||
I want <Tab> to do autocompletion
|
||||
---------------------------------
|
||||
|
||||
let g:jedi#show_function_definition = "0"
|
||||
Don't even think about changing the Jedi command to ``<Tab>``,
|
||||
use `supertab <https://github.com/ervandew/supertab>`_!
|
||||
|
||||
|
||||
The completion is waaay too slow!
|
||||
---------------------------------
|
||||
|
||||
Completion of complex libraries (like Numpy) should only be slow the first time
|
||||
you complete it. After that, the results should be cached and very fast.
|
||||
|
||||
If it's still slow, in case you've installed the python-mode VIM plugin, disable
|
||||
it. It seems to conflict with jedi-vim. See issue `#163
|
||||
<https://github.com/davidhalter/jedi-vim/issues/163>`__.
|
||||
|
||||
|
||||
Testing
|
||||
=======
|
||||
|
||||
jedi-vim is being tested with a combination of `vspec
|
||||
<https://github.com/kana/vim-vspec>`_ and `py.test <http://pytest.org/>`_.
|
||||
|
||||
The tests are in the ``test`` subdirectory, you can run them calling::
|
||||
|
||||
py.test
|
||||
|
||||
The tests are automatically run with `travis
|
||||
<https://travis-ci.org/davidhalter/jedi-vim>`_.
|
||||
|
||||
16
after/ftplugin/python/jedi.vim
Normal file
16
after/ftplugin/python/jedi.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
if g:jedi#auto_initialization
|
||||
if g:jedi#completions_enabled
|
||||
" We need our own omnifunc, so this overrides the omnifunc set by
|
||||
" $VIMRUNTIME/ftplugin/python.vim.
|
||||
setlocal omnifunc=jedi#completions
|
||||
|
||||
" map ctrl+space for autocompletion
|
||||
if g:jedi#completions_command == "<C-Space>"
|
||||
" in terminals, <C-Space> sometimes equals <Nul>
|
||||
inoremap <expr> <Nul> jedi#complete_string(0)
|
||||
endif
|
||||
if g:jedi#completions_command != ""
|
||||
execute "inoremap <expr> <buffer> ".g:jedi#completions_command." jedi#complete_string(0)"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -1,34 +1,40 @@
|
||||
if g:jedi#show_function_definition == 1 && has('conceal')
|
||||
" conceal is normal for vim >= 7.3
|
||||
|
||||
let e = g:jedi#function_definition_escape
|
||||
let l1 = e.'jedi=[^'.e.']*'.e.'[^'.e.']*'.e.'jedi'.e
|
||||
let l2 = e.'jedi=\?[^'.e.']*'.e
|
||||
exe 'syn match jediIgnore "'.l2.'" contained conceal'
|
||||
setlocal conceallevel=2
|
||||
syn match jediFatSymbol "*" contained conceal
|
||||
syn match jediFat "\*[^*]\+\*" contained contains=jediFatSymbol
|
||||
syn match jediSpace "\v[ ]+( )@=" contained
|
||||
exe 'syn match jediFunction "'.l1.'" keepend extend contains=jediIgnore,jediFat,jediSpace'
|
||||
|
||||
hi def link jediIgnore Ignore
|
||||
hi def link jediFatSymbol Ignore
|
||||
hi def link jediSpace Normal
|
||||
hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555
|
||||
hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey
|
||||
|
||||
" override defaults (add jediFunction to contains)
|
||||
syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
|
||||
syn region pythonString
|
||||
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=pythonEscape,@Spell,jediFunction
|
||||
syn region pythonString
|
||||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
|
||||
syn region pythonRawString
|
||||
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=@Spell,jediFunction
|
||||
syn region pythonRawString
|
||||
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction
|
||||
if g:jedi#show_call_signatures == 1 && has('conceal')
|
||||
" conceal is normal for vim >= 7.3
|
||||
|
||||
let e = g:jedi#call_signature_escape
|
||||
let l1 = e.'jedi=[^'.e.']*'.e.'[^'.e.']*'.e.'jedi'.e
|
||||
let l2 = e.'jedi=\?[^'.e.']*'.e
|
||||
exe 'syn match jediIgnore "'.l2.'" contained conceal'
|
||||
setlocal conceallevel=2
|
||||
syn match jediFatSymbol "*" contained conceal
|
||||
syn match jediFat "\*[^*]\+\*" contained contains=jediFatSymbol
|
||||
syn match jediSpace "\v[ ]+( )@=" contained
|
||||
exe 'syn match jediFunction "'.l1.'" keepend extend contains=jediIgnore,jediFat,jediSpace'
|
||||
|
||||
hi def link jediIgnore Ignore
|
||||
hi def link jediFatSymbol Ignore
|
||||
hi def link jediSpace Normal
|
||||
|
||||
if exists('g:colors_name')
|
||||
hi def link jediFunction CursorLine
|
||||
hi def link jediFat TabLine
|
||||
else
|
||||
hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey
|
||||
hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555
|
||||
end
|
||||
|
||||
" override defaults (add jediFunction to contains)
|
||||
syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
|
||||
syn region pythonString
|
||||
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=pythonEscape,@Spell,jediFunction
|
||||
syn region pythonString
|
||||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
|
||||
syn region pythonRawString
|
||||
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=@Spell,jediFunction
|
||||
syn region pythonRawString
|
||||
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction
|
||||
endif
|
||||
|
||||
@@ -1,33 +1,24 @@
|
||||
" ------------------------------------------------------------------------
|
||||
" functions that call python code
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#goto()
|
||||
function! jedi#goto_assignments()
|
||||
Python jedi_vim.goto()
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#get_definition()
|
||||
function! jedi#goto_definitions()
|
||||
Python jedi_vim.goto(is_definition=True)
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#related_names()
|
||||
function! jedi#usages()
|
||||
Python jedi_vim.goto(is_related_name=True)
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#rename(...)
|
||||
Python jedi_vim.rename()
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#complete(findstart, base)
|
||||
Python jedi_vim.complete()
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#show_func_def()
|
||||
Python jedi_vim.show_func_def()
|
||||
function! jedi#completions(findstart, base)
|
||||
Python jedi_vim.completions()
|
||||
endfunction
|
||||
|
||||
function! jedi#enable_speed_debugging()
|
||||
@@ -42,11 +33,21 @@ function! jedi#disable_debugging()
|
||||
Python jedi_vim.jedi.set_debug_function(None)
|
||||
endfunction
|
||||
|
||||
function! jedi#py_import(args)
|
||||
Python jedi_vim.py_import()
|
||||
endfun
|
||||
|
||||
function! jedi#py_import_completions(argl, cmdl, pos)
|
||||
Python jedi_vim.py_import_completions()
|
||||
endfun
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" show_pydoc
|
||||
" show_documentation
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#show_pydoc()
|
||||
Python jedi_vim.show_pydoc()
|
||||
function! jedi#show_documentation()
|
||||
Python jedi_vim.show_documentation()
|
||||
|
||||
if bufnr("__doc__") > 0
|
||||
" If the __doc__ buffer is open in the current window, jump to it
|
||||
silent execute "sbuffer ".bufnr("__doc__")
|
||||
@@ -83,25 +84,14 @@ function! jedi#show_pydoc()
|
||||
let b:current_syntax = "rst"
|
||||
endfunction
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" helper functions
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#new_buffer(path)
|
||||
if g:jedi#use_tabs_not_buffers
|
||||
Python jedi_vim.tabnew(jedi_vim.escape_file_path(vim.eval('a:path')))
|
||||
else
|
||||
if !&hidden && &modified
|
||||
w
|
||||
endif
|
||||
Python vim.command('edit ' + jedi_vim.escape_file_path(vim.eval('a:path')))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:add_goto_window()
|
||||
function! jedi#add_goto_window()
|
||||
set lazyredraw
|
||||
cclose
|
||||
execute 'belowright copen 3'
|
||||
execute 'belowright copen '.g:jedi#quickfix_window_height
|
||||
set nolazyredraw
|
||||
if g:jedi#use_tabs_not_buffers == 1
|
||||
map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
||||
@@ -117,7 +107,7 @@ function! jedi#goto_window_on_enter()
|
||||
if l:data.bufnr
|
||||
" close goto_window buffer
|
||||
normal ZQ
|
||||
jedi#new_buffer(bufname(l:data.bufnr))
|
||||
Python jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
|
||||
call cursor(l:data.lnum, l:data.col)
|
||||
else
|
||||
echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None
|
||||
@@ -125,7 +115,7 @@ function! jedi#goto_window_on_enter()
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#syn_stack()
|
||||
function! s:syn_stack()
|
||||
if !exists("*synstack")
|
||||
return []
|
||||
endif
|
||||
@@ -133,8 +123,8 @@ function! jedi#syn_stack()
|
||||
endfunc
|
||||
|
||||
|
||||
function! jedi#do_popup_on_dot()
|
||||
let highlight_groups = jedi#syn_stack()
|
||||
function! jedi#do_popup_on_dot_in_highlight()
|
||||
let highlight_groups = s:syn_stack()
|
||||
for a in highlight_groups
|
||||
if a == 'pythonDoctest'
|
||||
return 1
|
||||
@@ -151,30 +141,157 @@ function! jedi#do_popup_on_dot()
|
||||
return 1
|
||||
endfunc
|
||||
|
||||
function! jedi#configure_function_definition()
|
||||
autocmd InsertLeave <buffer> Python jedi_vim.clear_func_def()
|
||||
autocmd CursorMovedI <buffer> call jedi#show_func_def()
|
||||
|
||||
function! jedi#popup_on_dot_string()
|
||||
endfunction
|
||||
|
||||
|
||||
Python << PYTHONEOF
|
||||
""" here we initialize the jedi stuff """
|
||||
import vim
|
||||
function! jedi#configure_call_signatures()
|
||||
autocmd InsertLeave <buffer> Python jedi_vim.clear_call_signatures()
|
||||
autocmd CursorMovedI <buffer> Python jedi_vim.show_call_signatures()
|
||||
endfunction
|
||||
|
||||
# update the system path, to include the jedi path
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
||||
" Helper function instead of `python vim.eval()`, and `.command()` because
|
||||
" these also return error definitions.
|
||||
function! jedi#_vim_exceptions(str, is_eval)
|
||||
let l:result = {}
|
||||
try
|
||||
if a:is_eval
|
||||
let l:result.result = eval(a:str)
|
||||
else
|
||||
execute a:str
|
||||
let l:result.result = ''
|
||||
endif
|
||||
catch
|
||||
let l:result.exception = v:exception
|
||||
let l:result.throwpoint = v:throwpoint
|
||||
endtry
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
# to display errors correctly
|
||||
import traceback
|
||||
|
||||
# update the sys path to include the jedi_vim script
|
||||
sys.path.insert(1, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'plugin'))
|
||||
import jedi_vim
|
||||
sys.path.pop(1)
|
||||
function! jedi#complete_string(is_popup_on_dot)
|
||||
|
||||
if a:is_popup_on_dot && !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight())
|
||||
return ''
|
||||
|
||||
end
|
||||
if pumvisible() && !a:is_popup_on_dot
|
||||
return "\<C-n>"
|
||||
else
|
||||
return "\<C-x>\<C-o>\<C-r>=jedi#complete_opened()\<CR>"
|
||||
end
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#complete_opened()
|
||||
if pumvisible() && g:jedi#popup_select_first && stridx(&completeopt, 'longest') > -1
|
||||
" only go down if it is visible, user-enabled and the longest option is set
|
||||
return "\<Down>"
|
||||
end
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#force_py_version(py_version)
|
||||
let g:jedi#force_py_version = a:py_version
|
||||
if g:jedi#force_py_version == 2
|
||||
command! -nargs=1 Python python <args>
|
||||
execute 'pyfile '.s:script_path.'/initialize.py'
|
||||
elseif g:jedi#force_py_version == 3
|
||||
command! -nargs=1 Python python3 <args>
|
||||
execute 'py3file '.s:script_path.'/initialize.py'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#force_py_version_switch()
|
||||
if g:jedi#force_py_version == 2
|
||||
call jedi#force_py_version(3)
|
||||
elseif g:jedi#force_py_version == 3
|
||||
call jedi#force_py_version(2)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" deprecations
|
||||
" ------------------------------------------------------------------------
|
||||
let s:deprecations = {
|
||||
\ 'get_definition_command': 'goto_definitions_command',
|
||||
\ 'goto_command': 'goto_assignments_command',
|
||||
\ 'pydoc': 'documentation_command',
|
||||
\ 'related_names_command': 'usages_command',
|
||||
\ 'autocompletion_command': 'completions_command',
|
||||
\ 'show_function_definition': 'show_call_signatures',
|
||||
\ }
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" defaults for jedi-vim
|
||||
" ------------------------------------------------------------------------
|
||||
let s:settings = {
|
||||
\ 'use_tabs_not_buffers': 1,
|
||||
\ 'use_splits_not_buffers': 1,
|
||||
\ 'auto_initialization': 1,
|
||||
\ 'auto_vim_configuration': 1,
|
||||
\ 'goto_assignments_command': "'<leader>g'",
|
||||
\ 'completions_command': "'<C-Space>'",
|
||||
\ 'goto_definitions_command': "'<leader>d'",
|
||||
\ 'call_signatures_command': "'<leader>n'",
|
||||
\ 'usages_command': "'<leader>n'",
|
||||
\ 'rename_command': "'<leader>r'",
|
||||
\ 'popup_on_dot': 1,
|
||||
\ 'documentation_command': "'K'",
|
||||
\ 'show_call_signatures': 1,
|
||||
\ 'call_signature_escape': "'≡'",
|
||||
\ 'auto_close_doc': 1,
|
||||
\ 'popup_select_first': 1,
|
||||
\ 'quickfix_window_height': 10,
|
||||
\ 'completions_enabled': 1,
|
||||
\ 'force_py_version': 2
|
||||
\ }
|
||||
|
||||
|
||||
function! s:init()
|
||||
for [key, val] in items(s:deprecations)
|
||||
if exists('g:jedi#'.key)
|
||||
echom "'g:jedi#".key."' is deprecated. Please use 'g:jedi#".val."' instead. Sorry for the inconvenience."
|
||||
exe 'let g:jedi#'.val.' = g:jedi#'.key
|
||||
end
|
||||
endfor
|
||||
|
||||
for [key, val] in items(s:settings)
|
||||
if !exists('g:jedi#'.key)
|
||||
exe 'let g:jedi#'.key.' = '.val
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
call s:init()
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" Python initialization
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
let s:script_path = fnameescape(expand('<sfile>:p:h:h'))
|
||||
|
||||
if has('python') && has('python3')
|
||||
call jedi#force_py_version(g:jedi#force_py_version)
|
||||
elseif has('python')
|
||||
command! -nargs=1 Python python <args>
|
||||
execute 'pyfile '.s:script_path.'/initialize.py'
|
||||
elseif has('python3')
|
||||
command! -nargs=1 Python python3 <args>
|
||||
execute 'py3file '.s:script_path.'/initialize.py'
|
||||
else
|
||||
if !exists("g:jedi#squelch_py_warning")
|
||||
echomsg "Error: jedi-vim requires vim compiled with +python"
|
||||
endif
|
||||
finish
|
||||
end
|
||||
|
||||
|
||||
PYTHONEOF
|
||||
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
|
||||
|
||||
57
conftest.py
Normal file
57
conftest.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import os
|
||||
import urllib
|
||||
import zipfile
|
||||
import subprocess
|
||||
|
||||
CACHE_FOLDER = '.cache'
|
||||
VSPEC_FOLDER = os.path.join(CACHE_FOLDER, 'vim-vspec-master')
|
||||
VSPEC_RUNNER = os.path.join(VSPEC_FOLDER, 'bin/vspec')
|
||||
TEST_DIR = 'test'
|
||||
|
||||
|
||||
class IntegrationTestFile(object):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def run(self):
|
||||
output = subprocess.check_output([VSPEC_RUNNER, '.', VSPEC_FOLDER, self.path])
|
||||
for line in output.splitlines():
|
||||
if line.startswith('not ok') or line.startswith('Error'):
|
||||
print(output)
|
||||
assert False
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s: %s>" % (type(self), self.path)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
if not os.path.isdir(CACHE_FOLDER):
|
||||
os.mkdir(CACHE_FOLDER)
|
||||
|
||||
if not os.path.exists(VSPEC_FOLDER):
|
||||
url = 'https://github.com/kana/vim-vspec/archive/master.zip'
|
||||
name, hdrs = urllib.urlretrieve(url)
|
||||
z = zipfile.ZipFile(name)
|
||||
for n in z.namelist():
|
||||
dest = os.path.join(CACHE_FOLDER, n)
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
os.makedirs(destdir)
|
||||
data = z.read(n)
|
||||
if not os.path.isdir(dest):
|
||||
with open(dest, 'w') as f:
|
||||
f.write(data)
|
||||
z.close()
|
||||
os.chmod(VSPEC_RUNNER, 0777)
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
"""
|
||||
:type metafunc: _pytest.python.Metafunc
|
||||
"""
|
||||
def collect_tests():
|
||||
for f in os.listdir(TEST_DIR):
|
||||
if f.endswith('.vim'):
|
||||
yield IntegrationTestFile(os.path.join(TEST_DIR, f))
|
||||
|
||||
metafunc.parametrize('case', list(collect_tests()))
|
||||
460
doc/jedi-vim.txt
Normal file
460
doc/jedi-vim.txt
Normal file
@@ -0,0 +1,460 @@
|
||||
*jedi-vim.txt* - For Vim version 7.3 - Last change: 2013/3/1
|
||||
__ _______ _______ __ ____ ____ __ .___ ___.~
|
||||
| | | ____|| \ | | \ \ / / | | | \/ |~
|
||||
| | | |__ | .--. || | _____\ \/ / | | | \ / |~
|
||||
.--. | | | __| | | | || | |______\ / | | | |\/| |~
|
||||
| `--' | | |____ | '--' || | \ / | | | | | |~
|
||||
\______/ |_______||_______/ |__| \__/ |__| |__| |__|~
|
||||
|
||||
jedi-vim - awesome Python autocompletion with Vim
|
||||
|
||||
==============================================================================
|
||||
Contents *jedi-vim-contents*
|
||||
|
||||
1. Introduction |jedi-vim-introduction|
|
||||
2. Installation |jedi-vim-installation|
|
||||
2.0. Requirements |jedi-vim-installation-requirements|
|
||||
2.1. Manually |jedi-vim-installation-manually|
|
||||
2.2. Using Pathogen |jedi-vim-installation-pathogen|
|
||||
2.3. Using Vundle |jedi-vim-installation-vundle|
|
||||
3. Supported Python features |jedi-vim-support|
|
||||
4. Usage |jedi-vim-usage|
|
||||
5. Mappings |jedi-vim-keybindings|
|
||||
5.1. Start completion |g:jedi#completions_command|
|
||||
5.2. Go to assignment |g:jedi#goto_assignments_command|
|
||||
5.3. Get original definition |g:jedi#goto_definitions_command|
|
||||
5.4. Show documentation |g:jedi#documentation_command|
|
||||
5.5. Rename variables |g:jedi#rename_command|
|
||||
5.6. Show name usages |g:jedi#usages_command|
|
||||
5.7. Open module by name |:Pyimport|
|
||||
6. Configuration |jedi-vim-configuration|
|
||||
6.1. auto_initialization |g:jedi#auto_initialization|
|
||||
6.2. auto_vim_configuration |g:jedi#auto_vim_configuration|
|
||||
6.3. popup_on_dot |g:jedi#popup_on_dot|
|
||||
6.4. popup_select_first |g:jedi#popup_select_first|
|
||||
6.5. auto_close_doc |g:jedi#auto_close_doc|
|
||||
6.6. show_call_signatures |g:jedi#show_call_signatures|
|
||||
6.7. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers|
|
||||
6.8. squelch_py_warning |g:jedi#squelch_py_warning|
|
||||
6.9. completions_enable |g:jedi#completions_enable|
|
||||
6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
|
||||
6.11. force_py_version |g:jedi#force_py_version|
|
||||
7. Testing |jedi-vim-testing|
|
||||
8. Contributing |jedi-vim-contributing|
|
||||
9. License |jedi-vim-license|
|
||||
|
||||
==============================================================================
|
||||
1. Introduction *jedi-vim-introduction*
|
||||
|
||||
Jedi-vim is a is a Vim binding to the awesome Python autocompletion library
|
||||
`jedi`. Among jedi's (and, therefore, jedi-vim's) features are:
|
||||
|
||||
- Completion for a wide array of Python features (see |jedi-vim-support|)
|
||||
- Robust in dealing with syntax errors and wrong indentation
|
||||
- Parses complex module/function/class structures
|
||||
- Infers function arguments from Sphinx/Epydoc strings
|
||||
- Doesn't execute Python code
|
||||
- Supports Virtualenv
|
||||
- Supports Python 2.5+ and 3.2+
|
||||
|
||||
By leveraging this library, jedi-vim adds the following capabilities to Vim:
|
||||
|
||||
- Displaying function/class bodies
|
||||
- "Go to definition" command
|
||||
- Displaying docstrings
|
||||
- Renaming and refactoring
|
||||
- Looking up related names
|
||||
|
||||
==============================================================================
|
||||
2. Installation *jedi-vim-installation*
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.0. Requirements *jedi-vim-installation-requirements*
|
||||
|
||||
First of all, jedi-vim requires Vim to be compiled with the `+python` option.
|
||||
|
||||
The jedi library has to be installed for jedi-vim to work properly. You can
|
||||
install it first, by using e.g. your distribution's package manager, or by
|
||||
using pip: >
|
||||
|
||||
pip install jedi
|
||||
|
||||
However, you can also install it as a git submodule if you don't want to use
|
||||
jedi for anything but this plugin. How to do this is detailed below.
|
||||
|
||||
It is the best if you have VIM >= 7.3. For the older version, you probably
|
||||
cannot see the parameter recommendation list of function after typing open
|
||||
bracket.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.1. Installing manually *jedi-vim-installation-manually*
|
||||
|
||||
1a. Get the latest repository from Github: >
|
||||
|
||||
git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim
|
||||
|
||||
1b. If you want to install jedi as a submodule instead, issue this command: >
|
||||
|
||||
git clone --recursive http://github.com/davidhalter/jedi-vim
|
||||
|
||||
2. Put the plugin files into their respective folders in your vim runtime
|
||||
directory (usually ~/.vim). Be sure to pay attention to the directory
|
||||
structure!
|
||||
3. Update the Vim help tags with >
|
||||
|
||||
:helptags <path/to/vimruntime>/doc
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.1. Installing using Pathogen *jedi-vim-installation-pathogen*
|
||||
|
||||
Pathogen simplifies installation considerably.
|
||||
|
||||
1.a Clone the git repository into your bundles directory: >
|
||||
|
||||
git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim
|
||||
|
||||
1b. Again, if you want to install jedi as a submodule, use this command
|
||||
instead: >
|
||||
|
||||
git clone --recursive http://github.com/davidhalter/jedi-vim
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.3. Installing using Vundle *jedi-vim-installation-vundle*
|
||||
|
||||
1. Vundle automatically downloads subrepositories as git submodules, so you
|
||||
will automatically get the jedi library with the jedi-vim plugin. Add the
|
||||
following to the Bundles section in your .vimrc file: >
|
||||
|
||||
Bundle 'git://github.com/davidhalter/jedi-vim'
|
||||
|
||||
2. Issue the following command in Vim: >
|
||||
|
||||
:BundleInstall
|
||||
|
||||
Help tags are generated automatically, so you should be good to go.
|
||||
|
||||
==============================================================================
|
||||
3. Supported Python features *jedi-vim-support*
|
||||
|
||||
The Jedi library does all the hard work behind the scenes. It supports
|
||||
completion of a large number of Python features, among them:
|
||||
|
||||
- Builtins
|
||||
- Multiple `return`s or `yield`s
|
||||
- Tuple assignments/array indexing/dictionary indexing
|
||||
- `with`-statement/exception handling
|
||||
- `*args` and `**kwargs`
|
||||
- Decorators, lambdas, closures
|
||||
- Generators, iterators
|
||||
- Some descriptors: `property`/`staticmethod`/`classmethod`
|
||||
- Some magic methods: `__call__`, `__iter__`, `__next__`, `__get__`,
|
||||
`__getitem__`, `__init__`
|
||||
- `list.append()`, `set.add()`, `list.extend()`, etc.
|
||||
- (Nested) list comprehensions and ternary expressions
|
||||
- Relative `import`s
|
||||
- `getattr()`/`__getattr__`/`__getattribute__`
|
||||
- Function annotations (py3k feature, are being ignored at the moment, but are
|
||||
parsed)
|
||||
- Class decorators (py3k feature, are being ignored at the moment, but are
|
||||
parsed)
|
||||
- Simple/usual `sys.path` modifications
|
||||
- `isinstance` checks for `if`/`while`/`assert` case, that doesn’t work with
|
||||
Jedi
|
||||
- And more...
|
||||
|
||||
Note: This list is not necessarily up to date. For a complete list of
|
||||
features, please refer to the Jedi documentation at http://jedi.jedidjah.ch.
|
||||
|
||||
==============================================================================
|
||||
4. Usage *jedi-vim-usage*
|
||||
|
||||
With the default settings, autocompletion can be triggered by typing
|
||||
<Ctrl-Space>. The first entry will automatically be selected, so you can press
|
||||
<Return> to insert it into your code or keep typing and narrow down your
|
||||
completion options. The usual <C-X><C-O> and <C-P>/<C-N> keybindings work as
|
||||
well. Autocompletion is also triggered by typing a period in insert mode.
|
||||
Since periods rarely occur in Python code outside of method/import lookups,
|
||||
this is handy to have (but can be disabled).
|
||||
|
||||
When it encounters a new module, jedi might take a few seconds to parse that
|
||||
module's contents. Afterwards, the contents are cached and completion will be
|
||||
almost instantaneous.
|
||||
|
||||
==============================================================================
|
||||
5. Key Bindings *jedi-vim-keybindings*
|
||||
|
||||
All keybindings can be mapped by setting the appropriate global option. For
|
||||
example, to set the keybinding for starting omnicompletion to <C-N> instead of
|
||||
<Ctrl-Space>, add the following setting to your .vimrc file: >
|
||||
|
||||
let g:jedi#completions_command = "<C-N>"
|
||||
|
||||
Note: If you have |g:jedi#auto_initialization| set to 0, you have to create
|
||||
a mapping yourself by calling a function: >
|
||||
|
||||
" Using <C-N> for omnicompletion
|
||||
inoremap <silent> <buffer> <C-N> <c-x><c-o>
|
||||
" Use <localleader>r (by default <\-r>) for renaming
|
||||
nnoremap <silent> <buffer> <localleader>r :call jedi#rename()<cr>
|
||||
" etc.
|
||||
|
||||
Note: You can set commands to '', which means that they are empty and not
|
||||
assigned. It's an easy way to "disable" functionality of jedi-vim.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.1. `g:jedi#completions_command` *g:jedi#completions_command*
|
||||
Function: n/a; see above
|
||||
Default: <Ctrl-Space> Start completion
|
||||
|
||||
Performs autocompletion (or omnicompletion, to be precise).
|
||||
|
||||
Note: If you want to use <Tab> for completion, please install Supertab:
|
||||
https://github.com/ervandew/supertab.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.2. `g:jedi#goto_assignments_command` *g:jedi#goto_assignments_command*
|
||||
Function: `jedi#goto_assignments()`
|
||||
Default: <leader>g Go to definition
|
||||
|
||||
This function finds the first definition of the function/class under the
|
||||
cursor. It produces an error if the definition is not in a Python file.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.3. `g:jedi#goto_definitions_command` *g:jedi#goto_definitions_command*
|
||||
Function: `jedi#goto_definitions()`
|
||||
Default: <leader>d Go to original definition
|
||||
|
||||
This command tries to find the original definition of the function/class under
|
||||
the cursor. Just like the `jedi#goto_assignments()` function, it does not work
|
||||
if the definition isn't in a Python source file.
|
||||
|
||||
The difference between `jedi#goto_assignments()` and `jedi#goto_definitions()`
|
||||
is that the latter performs recursive lookups. Take, for example, the
|
||||
following module structure: >
|
||||
|
||||
# file1.py:
|
||||
from file2 import foo
|
||||
|
||||
# file2.py:
|
||||
from file3 import bar as foo
|
||||
|
||||
# file3.py
|
||||
def bar():
|
||||
pass
|
||||
|
||||
The `jedi#goto_assignments()` function will take you to the >
|
||||
|
||||
from file2 import foo
|
||||
|
||||
statement in file1.py, while the `jedi#goto_definitions()` function will take
|
||||
you all the way to the >
|
||||
|
||||
def bar():
|
||||
|
||||
line in file3.py.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.4. `g:jedi#documentation_command` *g:jedi#documentation_command*
|
||||
Function: `jedi#show_documentation()`
|
||||
Default: <K> Show pydoc documentation
|
||||
|
||||
This shows the pydoc documentation for the item currently under the cursor.
|
||||
The documentation is opened in a horizontally split buffer.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.5. `g:jedi#rename_command` *g:jedi#rename_command*
|
||||
Function: `jedi#rename()`
|
||||
Default: <leader>r Rename variables
|
||||
|
||||
Jedi-vim deletes the word currently under the cursor and puts Vim in insert
|
||||
mode, where the user is expected to enter the new variable name. Upon leaving
|
||||
insert mode, jedi-vim then renames all occurences of the old variable name
|
||||
with the new one. The number of performed renames is displayed in the command
|
||||
line.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.6. `g:jedi#usages_command` *g:jedi#usages_command*
|
||||
Function: `jedi#usages()`
|
||||
Default: <leader>n Show usages of a name.
|
||||
|
||||
The quickfix window is populated with a list of all names which point to the
|
||||
definition of the name under the cursor.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.7. Open module by name *:Pyimport*
|
||||
Function: `jedi#py_import(args)`
|
||||
Default: :Pyimport e.g. `:Pyimport os` shows os.py in VIM.
|
||||
|
||||
Simulate an import and open that module in VIM.
|
||||
|
||||
==============================================================================
|
||||
6. Configuration *jedi-vim-configuration*
|
||||
|
||||
Note: You currently have to set these options in your .vimrc. Setting them in
|
||||
an ftplugin (e.g. ~/.vim/ftplugin/python/jedi-vim-settings.vim) will not work
|
||||
because jedi-vim is not set up as an filetype plugin, but as a "regular"
|
||||
plugin.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.1. `g:jedi#auto_initialization` *g:jedi#auto_initialization*
|
||||
|
||||
Upon initialization, jedi-vim performs the following steps:
|
||||
|
||||
1. Set the current buffers 'omnifunc' to its own completion function
|
||||
`jedi#complete`
|
||||
2. Create mappings to commands specified in |jedi-vim-keybindings|
|
||||
3. Call `jedi#configure_call_signatures()` if
|
||||
`g:jedi#show_call_signatures` is set
|
||||
|
||||
You can disable the default initialization routine by setting this option to
|
||||
0. Beware that you have to perform the above steps yourself, though.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Perform automatic initialization)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.2. `g:jedi#auto_vim_configuration` *g:jedi#auto_vim_configuration*
|
||||
|
||||
Jedi-vim sets 'completeopt' to `menuone,longest,preview` by default. It also
|
||||
remaps <Ctrl-C> to <Esc> in insert mode. If you want to keep your own
|
||||
configuration, disable this setting.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Set 'completeopt' and mapping as described above)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.3. `g:jedi#popup_on_dot` *g:jedi#popup_on_dot*
|
||||
|
||||
Jedi-vim automatically starts completion upon typing a period in insert mode.
|
||||
|
||||
However, when working with large modules, this can slow down your typing flow
|
||||
since you have to wait for jedi to parse the module and show the completion
|
||||
menu. By disabling this setting, completion is only started when you manually
|
||||
press the completion key.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Start completion on typing a period)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.4. `g:jedi#popup_select_first` *g:jedi#popup_select_first*
|
||||
|
||||
Upon starting completion, jedi-vim can automatically select the first entry
|
||||
that pops up (without actually inserting it).
|
||||
|
||||
This leads to a better typing flow: As you type more characters, the entries
|
||||
in the completion menu are narrowed down. If they are narrowed down enough,
|
||||
you can just press <Return> to insert the first match.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Automatically select first completion entry)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.5. `g:jedi#auto_close_doc` *g:jedi#auto_close_doc*
|
||||
|
||||
When doing completion, jedi-vim shows the docstring of the currently selected
|
||||
item in a preview window. By default, this window is being closed after
|
||||
insertion of a completion item.
|
||||
|
||||
Set this to 1 to leave the preview window open even after leaving insert mode.
|
||||
This could be useful if you want to browse longer docstrings.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Automatically close preview window upon leaving insert mode)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.6. `g:jedi#show_call_signatures` *g:jedi#show_call_signatures*
|
||||
|
||||
Jedi-vim can display a small window detailing the arguments of the currently
|
||||
completed function and highlighting the currently selected argument. This can
|
||||
be disabled by setting this option to 0.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Show call signatures window)
|
||||
|
||||
Note: This setting is ignored if |g:jedi#auto_initialization| is set to 0. In
|
||||
that case, if you want to see call signatures, you have to set it up
|
||||
manually by calling a function in your configuration file: >
|
||||
|
||||
call jedi#configure_call_signatures()
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.7. `g:jedi#use_tabs_not_buffers` *g:jedi#use_tabs_not_buffers*
|
||||
|
||||
By default, jedi-vim opens a new tab if you use the "go to", "show
|
||||
definition", or "related names" commands. When you set this option to 0, they
|
||||
open in the current buffer instead.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Command output is put in a new tab)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.8. `g:jedi#squelch_py_warning` *g:jedi#squelch_py_warning*
|
||||
|
||||
When Vim has not been compiled with +python, jedi-vim shows a warning to that
|
||||
effect and aborts loading itself. Set this to 1 to suppress that warning.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 0 (Warning is shown)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.9. `g:jedi#completions_enable` *g:jedi#completions_enable*
|
||||
|
||||
If you don't want Jedi completion, but all the other features, you can disable
|
||||
it in favor of another completion engine (that probably also uses Jedi, like
|
||||
YCM).
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.10. `g:jedi#use_splits_not_buffers` *g:jedi#use_splits_not_buffers*
|
||||
|
||||
If you want to open new split for "go to", you could set this option to the
|
||||
direction which you want to open a split with.
|
||||
|
||||
Options: top, left, right or bottom
|
||||
Default: "" (not enabled by default)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.11. `g:jedi#force_py_version` *g:jedi#force_py_version*
|
||||
|
||||
If you have installed both python 2 and python 3, you can force which one jedi
|
||||
should use by setting this variable. It forces the internal Vim command, which
|
||||
will be used for every jedi call to the respective python interpreter.
|
||||
The variable can be set in the .vimrc like this to force python 3:
|
||||
|
||||
let g:jedi#force_py_version = 3
|
||||
|
||||
This variable can be switched during runtime using the following function:
|
||||
Function: `jedi#force_py_version_switch()`
|
||||
|
||||
or set directly using this function, which has the same name as the variable:
|
||||
Function: `jedi#force_py_version(py_version)`
|
||||
|
||||
Options: 2 or 3
|
||||
Default: 2
|
||||
|
||||
==============================================================================
|
||||
7. Testing *jedi-vim-testing*
|
||||
|
||||
jedi-vim is being tested with a combination of vspec
|
||||
https://github.com/kana/vim-vspec and py.test http://pytest.org/.
|
||||
|
||||
The tests are in the test subdirectory, you can run them calling::
|
||||
|
||||
py.test
|
||||
|
||||
The tests are automatically run with `travis
|
||||
<https://travis-ci.org/davidhalter/jedi-vim>`_.
|
||||
|
||||
==============================================================================
|
||||
8. Contributing *jedi-vim-contributing*
|
||||
|
||||
We love Pull Requests! Read the instructions in `CONTRIBUTING.md`.
|
||||
|
||||
==============================================================================
|
||||
9. License *jedi-vim-license*
|
||||
|
||||
Jedi-vim is licensed with the MIT license.
|
||||
|
||||
vim: textwidth=78 tabstop=8 filetype=help:norightleft:
|
||||
@@ -1,5 +1,3 @@
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
if !has('python') && !has('python3')
|
||||
finish
|
||||
endif
|
||||
@@ -8,27 +6,37 @@ endif
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
if g:jedi#auto_initialization
|
||||
setlocal omnifunc=jedi#complete
|
||||
|
||||
" map ctrl+space for autocompletion
|
||||
if g:jedi#autocompletion_command == "<C-Space>"
|
||||
" in terminals, <C-Space> sometimes equals <Nul>
|
||||
inoremap <buffer><Nul> <C-X><C-O>
|
||||
" goto / get_definition / usages
|
||||
if g:jedi#goto_assignments_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#goto_assignments_command." :call jedi#goto_assignments()<CR>"
|
||||
endif
|
||||
if g:jedi#goto_definitions_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#goto_definitions_command." :call jedi#goto_definitions()<CR>"
|
||||
endif
|
||||
if g:jedi#usages_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#usages_command." :call jedi#usages()<CR>"
|
||||
endif
|
||||
execute "inoremap <buffer>".g:jedi#autocompletion_command." <C-X><C-O>"
|
||||
|
||||
" goto / get_definition / related_names
|
||||
execute "noremap <buffer>".g:jedi#goto_command." :call jedi#goto()<CR>"
|
||||
execute "noremap <buffer>".g:jedi#get_definition_command." :call jedi#get_definition()<CR>"
|
||||
execute "noremap <buffer>".g:jedi#related_names_command." :call jedi#related_names()<CR>"
|
||||
" rename
|
||||
execute "noremap <buffer>".g:jedi#rename_command." :call jedi#rename()<CR>"
|
||||
" pydoc
|
||||
execute "nnoremap <silent> <buffer>".g:jedi#pydoc." :call jedi#show_pydoc()<CR>"
|
||||
|
||||
if g:jedi#show_function_definition == 1 && has('conceal')
|
||||
call jedi#configure_function_definition()
|
||||
if g:jedi#rename_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#rename_command." :call jedi#rename()<CR>"
|
||||
endif
|
||||
" documentation/pydoc
|
||||
if g:jedi#documentation_command != ''
|
||||
execute "nnoremap <silent> <buffer>".g:jedi#documentation_command." :call jedi#show_documentation()<CR>"
|
||||
endif
|
||||
|
||||
if g:jedi#show_call_signatures == 1 && has('conceal')
|
||||
call jedi#configure_call_signatures()
|
||||
endif
|
||||
|
||||
if g:jedi#completions_enabled == 1
|
||||
inoremap <silent> <buffer> . .<C-R>=jedi#complete_string(1)<CR>
|
||||
endif
|
||||
|
||||
if g:jedi#auto_close_doc
|
||||
" close preview if its still open after insert
|
||||
autocmd InsertLeave <buffer> if pumvisible() == 0|pclose|endif
|
||||
end
|
||||
end
|
||||
|
||||
if g:jedi#auto_vim_configuration
|
||||
@@ -37,16 +45,3 @@ if g:jedi#auto_vim_configuration
|
||||
inoremap <C-c> <ESC>
|
||||
end
|
||||
end
|
||||
|
||||
if g:jedi#popup_on_dot
|
||||
if stridx(&completeopt, 'longest') > -1
|
||||
inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>" : ""<CR>
|
||||
else
|
||||
inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>\<lt>C-P>" : ""<CR>
|
||||
end
|
||||
end
|
||||
|
||||
if g:jedi#auto_close_doc
|
||||
" close preview if its still open after insert
|
||||
autocmd InsertLeave <buffer> if pumvisible() == 0|pclose|endif
|
||||
end
|
||||
|
||||
26
initialize.py
Normal file
26
initialize.py
Normal file
@@ -0,0 +1,26 @@
|
||||
''' ------------------------------------------------------------------------
|
||||
Python initialization
|
||||
---------------------------------------------------------------------------
|
||||
here we initialize the jedi stuff '''
|
||||
|
||||
import vim
|
||||
|
||||
# update the system path, to include the jedi path
|
||||
import sys
|
||||
import os
|
||||
|
||||
# vim.command('echom expand("<sfile>:p:h:h")') # broken, <sfile> inside function
|
||||
# sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
||||
sys.path.insert(0, os.path.join(vim.eval('s:script_path'), 'jedi'))
|
||||
|
||||
# to display errors correctly
|
||||
import traceback
|
||||
|
||||
# update the sys path to include the jedi_vim script
|
||||
sys.path.insert(0, vim.eval('s:script_path'))
|
||||
try:
|
||||
import jedi_vim
|
||||
except ImportError:
|
||||
vim.command('echoerr "Please install Jedi if you want to use jedi_vim."')
|
||||
sys.path.pop(1)
|
||||
|
||||
2
jedi
2
jedi
Submodule jedi updated: 89bd32e0d7...78f1ae5e71
473
jedi_vim.py
Normal file
473
jedi_vim.py
Normal file
@@ -0,0 +1,473 @@
|
||||
"""
|
||||
The Python parts of the Jedi library for VIM. It is mostly about communicating
|
||||
with VIM.
|
||||
"""
|
||||
|
||||
import traceback # for exception output
|
||||
import re
|
||||
import os
|
||||
from shlex import split as shsplit
|
||||
|
||||
import vim
|
||||
import jedi
|
||||
import jedi.keywords
|
||||
from jedi._compatibility import unicode, is_py3k
|
||||
|
||||
|
||||
def catch_and_print_exceptions(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except (Exception, vim.error):
|
||||
print(traceback.format_exc())
|
||||
return None
|
||||
return wrapper
|
||||
|
||||
|
||||
class VimError(Exception):
|
||||
def __init__(self, message, throwpoint, executing):
|
||||
super(type(self), self).__init__(message)
|
||||
self.throwpoint = throwpoint
|
||||
self.executing = executing
|
||||
|
||||
def __str__(self):
|
||||
return self.message + '; created by: ' + repr(self.executing)
|
||||
|
||||
|
||||
def _catch_exception(string, is_eval):
|
||||
"""
|
||||
Interface between vim and python calls back to it.
|
||||
Necessary, because the exact error message is not given by `vim.error`.
|
||||
"""
|
||||
e = 'jedi#_vim_exceptions(%s, %s)'
|
||||
result = vim.eval(e % (repr(PythonToVimStr(string, 'UTF-8')), is_eval))
|
||||
if 'exception' in result:
|
||||
raise VimError(result['exception'], result['throwpoint'], string)
|
||||
return result['result']
|
||||
|
||||
|
||||
def vim_eval(string):
|
||||
return _catch_exception(string, 1)
|
||||
|
||||
|
||||
def vim_command(string):
|
||||
_catch_exception(string, 0)
|
||||
|
||||
|
||||
def echo_highlight(msg):
|
||||
vim_command('echohl WarningMsg | echom "%s" | echohl None' % msg)
|
||||
|
||||
|
||||
class PythonToVimStr(unicode):
|
||||
""" Vim has a different string implementation of single quotes """
|
||||
__slots__ = []
|
||||
def __new__(cls, obj, encoding='UTF-8'):
|
||||
if is_py3k or isinstance(obj, unicode):
|
||||
return unicode.__new__(cls, obj)
|
||||
else:
|
||||
return unicode.__new__(cls, obj, encoding)
|
||||
|
||||
def __repr__(self):
|
||||
# this is totally stupid and makes no sense but vim/python unicode
|
||||
# support is pretty bad. don't ask how I came up with this... It just
|
||||
# works...
|
||||
# It seems to be related to that bug: http://bugs.python.org/issue5876
|
||||
if unicode is str:
|
||||
s = self
|
||||
else:
|
||||
s = self.encode('UTF-8')
|
||||
return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"')
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def get_script(source=None, column=None):
|
||||
jedi.settings.additional_dynamic_modules = [b.name for b in vim.buffers
|
||||
if b.name is not None and b.name.endswith('.py')]
|
||||
if source is None:
|
||||
source = '\n'.join(vim.current.buffer)
|
||||
row = vim.current.window.cursor[0]
|
||||
if column is None:
|
||||
column = vim.current.window.cursor[1]
|
||||
buf_path = vim.current.buffer.name
|
||||
encoding = vim_eval('&encoding') or 'latin1'
|
||||
return jedi.Script(source, row, column, buf_path, encoding)
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def completions():
|
||||
row, column = vim.current.window.cursor
|
||||
clear_call_signatures()
|
||||
if vim.eval('a:findstart') == '1':
|
||||
count = 0
|
||||
for char in reversed(vim.current.line[:column]):
|
||||
if not re.match('[\w\d]', char):
|
||||
break
|
||||
count += 1
|
||||
vim.command('return %i' % (column - count))
|
||||
else:
|
||||
base = vim.eval('a:base')
|
||||
source = ''
|
||||
for i, line in enumerate(vim.current.buffer):
|
||||
# enter this path again, otherwise source would be incomplete
|
||||
if i == row - 1:
|
||||
source += line[:column] + base + line[column:]
|
||||
else:
|
||||
source += line
|
||||
source += '\n'
|
||||
# here again hacks, because jedi has a different interface than vim
|
||||
column += len(base)
|
||||
try:
|
||||
script = get_script(source=source, column=column)
|
||||
completions = script.completions()
|
||||
signatures = script.call_signatures()
|
||||
|
||||
out = []
|
||||
for c in completions:
|
||||
d = dict(word=PythonToVimStr(c.name[:len(base)] + c.complete),
|
||||
abbr=PythonToVimStr(c.name),
|
||||
# stuff directly behind the completion
|
||||
menu=PythonToVimStr(c.description),
|
||||
info=PythonToVimStr(c.doc), # docstr
|
||||
icase=1, # case insensitive
|
||||
dup=1 # allow duplicates (maybe later remove this)
|
||||
)
|
||||
out.append(d)
|
||||
|
||||
strout = str(out)
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
print(traceback.format_exc())
|
||||
strout = ''
|
||||
completions = []
|
||||
signatures = []
|
||||
|
||||
show_call_signatures(signatures)
|
||||
vim.command('return ' + strout)
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def goto(is_definition=False, is_related_name=False, no_output=False):
|
||||
definitions = []
|
||||
script = get_script()
|
||||
try:
|
||||
if is_related_name:
|
||||
definitions = script.usages()
|
||||
elif is_definition:
|
||||
definitions = script.goto_definitions()
|
||||
else:
|
||||
definitions = script.goto_assignments()
|
||||
except jedi.NotFoundError:
|
||||
echo_highlight( "Cannot follow nothing. Put your cursor on a valid name.")
|
||||
else:
|
||||
if no_output:
|
||||
return definitions
|
||||
if not definitions:
|
||||
echo_highlight("Couldn't find any definitions for this.")
|
||||
elif len(definitions) == 1 and not is_related_name:
|
||||
# just add some mark to add the current position to the jumplist.
|
||||
# this is ugly, because it overrides the mark for '`', so if anyone
|
||||
# has a better idea, let me know.
|
||||
vim_command('normal! m`')
|
||||
|
||||
d = list(definitions)[0]
|
||||
if d.in_builtin_module():
|
||||
if d.is_keyword:
|
||||
echo_highlight(
|
||||
"Cannot get the definition of Python keywords.")
|
||||
else:
|
||||
echo_highlight("Builtin modules cannot be displayed (%s)."
|
||||
% d.module_path)
|
||||
else:
|
||||
if d.module_path != vim.current.buffer.name:
|
||||
result = new_buffer(d.module_path)
|
||||
if not result:
|
||||
return
|
||||
vim.current.window.cursor = d.line, d.column
|
||||
vim_command('normal! zt') # cursor at top of screen
|
||||
else:
|
||||
# multiple solutions
|
||||
lst = []
|
||||
for d in definitions:
|
||||
if d.in_builtin_module():
|
||||
lst.append(dict(text=
|
||||
PythonToVimStr('Builtin ' + d.description)))
|
||||
else:
|
||||
lst.append(dict(filename=PythonToVimStr(d.module_path),
|
||||
lnum=d.line, col=d.column + 1,
|
||||
text=PythonToVimStr(d.description)))
|
||||
vim_eval('setqflist(%s)' % repr(lst))
|
||||
vim_eval('jedi#add_goto_window()')
|
||||
return definitions
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def show_documentation():
|
||||
script = get_script()
|
||||
try:
|
||||
definitions = script.goto_definitions()
|
||||
except jedi.NotFoundError:
|
||||
definitions = []
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
definitions = []
|
||||
print("Exception, this shouldn't happen.")
|
||||
print(traceback.format_exc())
|
||||
|
||||
if not definitions:
|
||||
echo_highlight('No documentation found for that.')
|
||||
vim.command('return')
|
||||
else:
|
||||
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc
|
||||
else '|No Docstring for %s|' % d for d in definitions]
|
||||
text = ('\n' + '-' * 79 + '\n').join(docs)
|
||||
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
|
||||
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def clear_call_signatures():
|
||||
cursor = vim.current.window.cursor
|
||||
e = vim_eval('g:jedi#call_signature_escape')
|
||||
regex = r'%sjedi=([0-9]+), ([^%s]*)%s.*%sjedi%s'.replace('%s', e)
|
||||
for i, line in enumerate(vim.current.buffer):
|
||||
match = re.search(r'%s' % regex, line)
|
||||
if match is not None:
|
||||
vim_regex = r'\v' + regex.replace('=', r'\=') + '.{%s}' % \
|
||||
int(match.group(1))
|
||||
vim_command(r'try | %s,%ss/%s/\2/g | catch | endtry' \
|
||||
% (i + 1, i + 1, vim_regex))
|
||||
vim_eval('histdel("search", -1)')
|
||||
vim_command('let @/ = histget("search", -1)')
|
||||
vim.current.window.cursor = cursor
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def show_call_signatures(signatures=()):
|
||||
if vim_eval("has('conceal') && g:jedi#show_call_signatures") == '0':
|
||||
return
|
||||
|
||||
if signatures == ():
|
||||
signatures = get_script().call_signatures()
|
||||
clear_call_signatures()
|
||||
|
||||
if not signatures:
|
||||
return
|
||||
|
||||
for i, signature in enumerate(signatures):
|
||||
line, column = signature.bracket_start
|
||||
# signatures are listed above each other
|
||||
line_to_replace = line - i - 1
|
||||
# because there's a space before the bracket
|
||||
insert_column = column - 1
|
||||
if insert_column < 0 or line_to_replace <= 0:
|
||||
# Edge cases, when the call signature has no space on the screen.
|
||||
break
|
||||
|
||||
# TODO check if completion menu is above or below
|
||||
line = vim_eval("getline(%s)" % line_to_replace)
|
||||
|
||||
params = [p.get_code().replace('\n', '') for p in signature.params]
|
||||
try:
|
||||
params[signature.index] = '*%s*' % params[signature.index]
|
||||
except (IndexError, TypeError):
|
||||
pass
|
||||
|
||||
# This stuff is reaaaaally a hack! I cannot stress enough, that
|
||||
# this is a stupid solution. But there is really no other yet.
|
||||
# There is no possibility in VIM to draw on the screen, but there
|
||||
# will be one (see :help todo Patch to access screen under Python.
|
||||
# (Marko Mahni, 2010 Jul 18))
|
||||
text = " (%s) " % ', '.join(params)
|
||||
text = ' ' * (insert_column - len(line)) + text
|
||||
end_column = insert_column + len(text) - 2 # -2 due to bold symbols
|
||||
|
||||
# Need to decode it with utf8, because vim returns always a python 2
|
||||
# string even if it is unicode.
|
||||
e = vim_eval('g:jedi#call_signature_escape')
|
||||
if hasattr(e, 'decode'):
|
||||
e = e.decode('UTF-8')
|
||||
# replace line before with cursor
|
||||
regex = "xjedi=%sx%sxjedix".replace('x', e)
|
||||
|
||||
prefix, replace = line[:insert_column], line[insert_column:end_column]
|
||||
|
||||
# Check the replace stuff for strings, to append them
|
||||
# (don't want to break the syntax)
|
||||
regex_quotes = r'''\\*["']+'''
|
||||
# `add` are all the quotation marks.
|
||||
# join them with a space to avoid producing '''
|
||||
add = ' '.join(re.findall(regex_quotes, replace))
|
||||
# search backwards
|
||||
if add and replace[0] in ['"', "'"]:
|
||||
a = re.search(regex_quotes + '$', prefix)
|
||||
add = ('' if a is None else a.group(0)) + add
|
||||
|
||||
tup = '%s, %s' % (len(add), replace)
|
||||
repl = prefix + (regex % (tup, text)) + add + line[end_column:]
|
||||
|
||||
vim_eval('setline(%s, %s)' % (line_to_replace, repr(PythonToVimStr(repl))))
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def rename():
|
||||
if not int(vim.eval('a:0')):
|
||||
_rename_cursor = vim.current.window.cursor
|
||||
|
||||
vim_command('normal A ') # otherwise startinsert doesn't work well
|
||||
vim.current.window.cursor = _rename_cursor
|
||||
|
||||
vim_command('augroup jedi_rename')
|
||||
vim_command('autocmd InsertLeave <buffer> call jedi#rename(1)')
|
||||
vim_command('augroup END')
|
||||
|
||||
vim_command('normal! diw')
|
||||
vim_command(':startinsert')
|
||||
else:
|
||||
window_path = vim.current.buffer.name
|
||||
# reset autocommand
|
||||
vim_command('autocmd! jedi_rename InsertLeave')
|
||||
|
||||
replace = vim_eval("expand('<cword>')")
|
||||
vim_command('normal! u') # undo new word
|
||||
cursor = vim.current.window.cursor
|
||||
vim_command('normal! u') # undo the space at the end
|
||||
vim.current.window.cursor = cursor
|
||||
|
||||
if replace is None:
|
||||
echo_highlight('No rename possible, if no name is given.')
|
||||
else:
|
||||
temp_rename = goto(is_related_name=True, no_output=True)
|
||||
# sort the whole thing reverse (positions at the end of the line
|
||||
# must be first, because they move the stuff before the position).
|
||||
temp_rename = sorted(temp_rename, reverse=True,
|
||||
key=lambda x: (x.module_path, x.start_pos))
|
||||
for r in temp_rename:
|
||||
if r.in_builtin_module():
|
||||
continue
|
||||
|
||||
if vim.current.buffer.name != r.module_path:
|
||||
result = new_buffer(r.module_path)
|
||||
if not result:
|
||||
return
|
||||
|
||||
vim.current.window.cursor = r.start_pos
|
||||
vim_command('normal! cw%s' % replace)
|
||||
|
||||
result = new_buffer(window_path)
|
||||
if not result:
|
||||
return
|
||||
vim.current.window.cursor = cursor
|
||||
echo_highlight('Jedi did %s renames!' % len(temp_rename))
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def py_import():
|
||||
# args are the same as for the :edit command
|
||||
args = shsplit(vim.eval('a:args'))
|
||||
import_path = args.pop()
|
||||
text = 'import %s' % import_path
|
||||
scr = jedi.Script(text, 1, len(text), '')
|
||||
try:
|
||||
completion = scr.goto_assignments()[0]
|
||||
except IndexError:
|
||||
echo_highlight('Cannot find %s in sys.path!' % import_path)
|
||||
else:
|
||||
if completion.in_builtin_module():
|
||||
echo_highlight('%s is a builtin module.' % import_path)
|
||||
else:
|
||||
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
|
||||
new_buffer(completion.module_path, cmd_args)
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def py_import_completions():
|
||||
argl = vim.eval('a:argl')
|
||||
try:
|
||||
import jedi
|
||||
except ImportError:
|
||||
print('Pyimport completion requires jedi module: https://github.com/davidhalter/jedi')
|
||||
comps = []
|
||||
else:
|
||||
text = 'import %s' % argl
|
||||
script=jedi.Script(text, 1, len(text), '')
|
||||
comps = ['%s%s' % (argl, c.complete) for c in script.completions()]
|
||||
vim.command("return '%s'" % '\n'.join(comps))
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def new_buffer(path, options=''):
|
||||
# options are what you can to edit the edit options
|
||||
if vim_eval('g:jedi#use_tabs_not_buffers') == '1':
|
||||
_tabnew(path, options)
|
||||
elif not vim_eval('g:jedi#use_splits_not_buffers') == '1':
|
||||
user_split_option = vim_eval('g:jedi#use_splits_not_buffers')
|
||||
split_options = {
|
||||
'top': 'topleft split',
|
||||
'left': 'topleft vsplit',
|
||||
'right': 'botright vsplit',
|
||||
'bottom': 'botright split'
|
||||
}
|
||||
if user_split_option not in split_options:
|
||||
print('g:jedi#use_splits_not_buffers value is not correct, valid options are: %s' % ','.join(split_options.keys()))
|
||||
else:
|
||||
vim_command(split_options[user_split_option] + " %s" % path)
|
||||
else:
|
||||
if vim_eval("!&hidden && &modified") == '1':
|
||||
if vim_eval("bufname('%')") is None:
|
||||
echo_highlight('Cannot open a new buffer, use `:set hidden` or save your buffer')
|
||||
return False
|
||||
else:
|
||||
vim_command('w')
|
||||
vim_command('edit %s %s' % (options, escape_file_path(path)))
|
||||
# sometimes syntax is being disabled and the filetype not set.
|
||||
if vim_eval('!exists("g:syntax_on")') == '1':
|
||||
vim_command('syntax enable')
|
||||
if vim_eval("&filetype != 'python'") == '1':
|
||||
vim_command('set filetype=python')
|
||||
return True
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def _tabnew(path, options=''):
|
||||
"""
|
||||
Open a file in a new tab or switch to an existing one.
|
||||
|
||||
:param options: `:tabnew` options, read vim help.
|
||||
"""
|
||||
path = os.path.abspath(path)
|
||||
if vim_eval('has("gui")') == '1':
|
||||
vim_command('tab drop %s %s' % (options, escape_file_path(path)))
|
||||
return
|
||||
|
||||
for tab_nr in range(int(vim_eval("tabpagenr('$')"))):
|
||||
for buf_nr in vim_eval("tabpagebuflist(%i + 1)" % tab_nr):
|
||||
buf_nr = int(buf_nr) - 1
|
||||
try:
|
||||
buf_path = vim.buffers[buf_nr].name
|
||||
except (LookupError, ValueError):
|
||||
# Just do good old asking for forgiveness.
|
||||
# don't know why this happens :-)
|
||||
pass
|
||||
else:
|
||||
if buf_path == path:
|
||||
# tab exists, just switch to that tab
|
||||
vim_command('tabfirst | tabnext %i' % (tab_nr + 1))
|
||||
break
|
||||
else:
|
||||
continue
|
||||
break
|
||||
else:
|
||||
# tab doesn't exist, add a new one.
|
||||
vim_command('tabnew %s' % escape_file_path(path))
|
||||
|
||||
|
||||
def escape_file_path(path):
|
||||
return path.replace(' ', r'\ ')
|
||||
|
||||
|
||||
def print_to_stdout(level, str_out):
|
||||
print(str_out)
|
||||
|
||||
if not hasattr(jedi, '__version__') or jedi.__version__ < (0, 7, 0):
|
||||
echo_highlight('Please update your Jedi version, it is to old.')
|
||||
|
||||
@@ -1,60 +1,19 @@
|
||||
"py_fuzzycomplete.vim - Omni Completion for python in vim
|
||||
"jedi-vim - Omni Completion for python in vim
|
||||
" Maintainer: David Halter <davidhalter88@gmail.com>
|
||||
" Version: 0.1
|
||||
"
|
||||
" This part of the software is just the vim interface. The main source code
|
||||
" lies in the python files around it.
|
||||
" This part of the software is just the vim interface. The really big deal is
|
||||
" the Jedi Python library.
|
||||
|
||||
if !has('python') && !has('python3')
|
||||
if !exists("g:jedi#squelch_py_warning")
|
||||
echomsg "Error: Required vim compiled with +python"
|
||||
endif
|
||||
finish
|
||||
|
||||
" jedi-vim doesn't work in compatible mode (vim script syntax problems)
|
||||
if &compatible
|
||||
set nocompatible
|
||||
endif
|
||||
|
||||
" load plugin only once
|
||||
if exists("g:loaded_jedi") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_jedi = 1
|
||||
" jedi-vim really needs, otherwise jedi-vim cannot start.
|
||||
filetype plugin on
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" defaults for jedi-vim
|
||||
" ------------------------------------------------------------------------
|
||||
let s:settings = {
|
||||
\ 'use_tabs_not_buffers': 1,
|
||||
\ 'auto_initialization': 1,
|
||||
\ 'auto_vim_configuration': 1,
|
||||
\ 'goto_command': "'<leader>g'",
|
||||
\ 'autocompletion_command': "'<C-Space>'",
|
||||
\ 'get_definition_command': "'<leader>d'",
|
||||
\ 'related_names_command': "'<leader>n'",
|
||||
\ 'rename_command': "'<leader>r'",
|
||||
\ 'popup_on_dot': 1,
|
||||
\ 'pydoc': "'K'",
|
||||
\ 'show_function_definition': 1,
|
||||
\ 'function_definition_escape': "'≡'",
|
||||
\ 'auto_close_doc': 1
|
||||
\ }
|
||||
|
||||
for [key, val] in items(s:settings)
|
||||
if !exists('g:jedi#'.key)
|
||||
exe 'let g:jedi#'.key.' = '.val
|
||||
endif
|
||||
endfor
|
||||
|
||||
|
||||
if g:jedi#auto_initialization
|
||||
" this is only here because in some cases the VIM library adds their
|
||||
" autocompletion as a default, which may cause problems, depending on the
|
||||
" order of invocation.
|
||||
autocmd FileType Python setlocal omnifunc=jedi#complete switchbuf=useopen " needed for pydoc
|
||||
endif
|
||||
|
||||
if has('python')
|
||||
command! -nargs=1 Python python <args>
|
||||
else
|
||||
command! -nargs=1 Python python3 <args>
|
||||
end
|
||||
" Pyimport command
|
||||
command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import(<q-args>)
|
||||
|
||||
" vim: set et ts=4:
|
||||
|
||||
@@ -1,336 +0,0 @@
|
||||
"""
|
||||
The Python parts of the Jedi library for VIM. It is mostly about communicating
|
||||
with VIM.
|
||||
"""
|
||||
|
||||
import traceback # for exception output
|
||||
import re
|
||||
import os
|
||||
|
||||
import vim
|
||||
import jedi
|
||||
import jedi.keywords
|
||||
from jedi._compatibility import unicode
|
||||
|
||||
temp_rename = None # used for jedi#rename
|
||||
|
||||
|
||||
class PythonToVimStr(unicode):
|
||||
""" Vim has a different string implementation of single quotes """
|
||||
__slots__ = []
|
||||
|
||||
def __repr__(self):
|
||||
# this is totally stupid and makes no sense but vim/python unicode
|
||||
# support is pretty bad. don't ask how I came up with this... It just
|
||||
# works...
|
||||
# It seems to be related to that bug: http://bugs.python.org/issue5876
|
||||
s = self.encode('UTF-8')
|
||||
return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"')
|
||||
|
||||
|
||||
def echo_highlight(msg):
|
||||
vim.command('echohl WarningMsg | echo "%s" | echohl None' % msg)
|
||||
|
||||
|
||||
def get_script(source=None, column=None):
|
||||
jedi.settings.additional_dynamic_modules = [b.name for b in vim.buffers
|
||||
if b.name is not None and b.name.endswith('.py')]
|
||||
if source is None:
|
||||
source = '\n'.join(vim.current.buffer)
|
||||
row = vim.current.window.cursor[0]
|
||||
if column is None:
|
||||
column = vim.current.window.cursor[1]
|
||||
buf_path = vim.current.buffer.name
|
||||
encoding = vim.eval('&encoding')
|
||||
return jedi.Script(source, row, column, buf_path, encoding)
|
||||
|
||||
|
||||
def complete():
|
||||
row, column = vim.current.window.cursor
|
||||
clear_func_def()
|
||||
if vim.eval('a:findstart') == '1':
|
||||
count = 0
|
||||
for char in reversed(vim.current.line[:column]):
|
||||
if not re.match('[\w\d]', char):
|
||||
break
|
||||
count += 1
|
||||
vim.command('return %i' % (column - count))
|
||||
else:
|
||||
base = vim.eval('a:base')
|
||||
source = ''
|
||||
for i, line in enumerate(vim.current.buffer):
|
||||
# enter this path again, otherwise source would be incomplete
|
||||
if i == row - 1:
|
||||
source += line[:column] + base + line[column:]
|
||||
else:
|
||||
source += line
|
||||
source += '\n'
|
||||
# here again hacks, because jedi has a different interface than vim
|
||||
column += len(base)
|
||||
try:
|
||||
script = get_script(source=source, column=column)
|
||||
completions = script.complete()
|
||||
call_def = script.get_in_function_call()
|
||||
|
||||
out = []
|
||||
for c in completions:
|
||||
d = dict(word=PythonToVimStr(c.word[:len(base)] + c.complete),
|
||||
abbr=PythonToVimStr(c.word),
|
||||
# stuff directly behind the completion
|
||||
menu=PythonToVimStr(c.description),
|
||||
info=PythonToVimStr(c.doc), # docstr
|
||||
icase=1, # case insensitive
|
||||
dup=1 # allow duplicates (maybe later remove this)
|
||||
)
|
||||
out.append(d)
|
||||
|
||||
strout = str(out)
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
print(traceback.format_exc())
|
||||
strout = ''
|
||||
completions = []
|
||||
call_def = None
|
||||
|
||||
#print 'end', strout
|
||||
show_func_def(call_def, len(completions))
|
||||
vim.command('return ' + strout)
|
||||
|
||||
|
||||
def goto(is_definition=False, is_related_name=False, no_output=False):
|
||||
definitions = []
|
||||
script = get_script()
|
||||
try:
|
||||
if is_related_name:
|
||||
definitions = script.related_names()
|
||||
elif is_definition:
|
||||
definitions = script.get_definition()
|
||||
else:
|
||||
definitions = script.goto()
|
||||
except jedi.NotFoundError:
|
||||
echo_highlight(
|
||||
"Cannot follow nothing. Put your cursor on a valid name.")
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
echo_highlight("Some different eror, this shouldn't happen.")
|
||||
print(traceback.format_exc())
|
||||
else:
|
||||
if no_output:
|
||||
return definitions
|
||||
if not definitions:
|
||||
echo_highlight("Couldn't find any definitions for this.")
|
||||
elif len(definitions) == 1 and not is_related_name:
|
||||
# just add some mark to add the current position to the jumplist.
|
||||
# this is ugly, because it overrides the mark for '`', so if anyone
|
||||
# has a better idea, let me know.
|
||||
vim.command('normal! m`')
|
||||
|
||||
d = list(definitions)[0]
|
||||
if d.in_builtin_module():
|
||||
if isinstance(d.definition, jedi.keywords.Keyword):
|
||||
echo_highlight(
|
||||
"Cannot get the definition of Python keywords.")
|
||||
else:
|
||||
echo_highlight("Builtin modules cannot be displayed.")
|
||||
else:
|
||||
if d.module_path != vim.current.buffer.name:
|
||||
vim.eval('jedi#new_buffer(%s)' % \
|
||||
repr(PythonToVimStr(d.module_path)))
|
||||
vim.current.window.cursor = d.line_nr, d.column
|
||||
vim.command('normal! zt') # cursor at top of screen
|
||||
else:
|
||||
# multiple solutions
|
||||
lst = []
|
||||
for d in definitions:
|
||||
if d.in_builtin_module():
|
||||
lst.append(dict(text=
|
||||
PythonToVimStr('Builtin ' + d.description)))
|
||||
else:
|
||||
lst.append(dict(filename=PythonToVimStr(d.module_path),
|
||||
lnum=d.line_nr, col=d.column + 1,
|
||||
text=PythonToVimStr(d.description)))
|
||||
vim.eval('setqflist(%s)' % repr(lst))
|
||||
vim.eval('<sid>add_goto_window()')
|
||||
return definitions
|
||||
|
||||
|
||||
def show_pydoc():
|
||||
script = get_script()
|
||||
try:
|
||||
definitions = script.get_definition()
|
||||
except jedi.NotFoundError:
|
||||
definitions = []
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
definitions = []
|
||||
print("Exception, this shouldn't happen.")
|
||||
print(traceback.format_exc())
|
||||
|
||||
if not definitions:
|
||||
vim.command('return')
|
||||
else:
|
||||
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc
|
||||
else '|No Docstring for %s|' % d for d in definitions]
|
||||
text = ('\n' + '-' * 79 + '\n').join(docs)
|
||||
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
|
||||
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
|
||||
|
||||
|
||||
def clear_func_def():
|
||||
cursor = vim.current.window.cursor
|
||||
e = vim.eval('g:jedi#function_definition_escape')
|
||||
regex = r'%sjedi=([0-9]+), ([^%s]*)%s.*%sjedi%s'.replace('%s', e)
|
||||
for i, line in enumerate(vim.current.buffer):
|
||||
match = re.search(r'%s' % regex, line)
|
||||
if match is not None:
|
||||
vim_regex = r'\v' + regex.replace('=', r'\=') + '.{%s}' % \
|
||||
int(match.group(1))
|
||||
vim.command(r'try | %s,%ss/%s/\2/g | catch | endtry' \
|
||||
% (i + 1, i + 1, vim_regex))
|
||||
vim.eval('histdel("search", -1)')
|
||||
vim.command('let @/ = histget("search", -1)')
|
||||
vim.current.window.cursor = cursor
|
||||
|
||||
|
||||
def show_func_def(call_def=None, completion_lines=0):
|
||||
if vim.eval("has('conceal') && g:jedi#show_function_definition") == '0':
|
||||
return
|
||||
try:
|
||||
if call_def == None:
|
||||
call_def = get_script().get_in_function_call()
|
||||
clear_func_def()
|
||||
|
||||
if call_def is None:
|
||||
return
|
||||
|
||||
row, column = call_def.bracket_start
|
||||
if column < 2 or row == 0:
|
||||
return # edge cases, just ignore
|
||||
|
||||
# TODO check if completion menu is above or below
|
||||
row_to_replace = row - 1
|
||||
line = vim.eval("getline(%s)" % row_to_replace)
|
||||
|
||||
insert_column = column - 2 # because it has stuff at the beginning
|
||||
|
||||
params = [p.get_code().replace('\n', '') for p in call_def.params]
|
||||
try:
|
||||
params[call_def.index] = '*%s*' % params[call_def.index]
|
||||
except (IndexError, TypeError):
|
||||
pass
|
||||
|
||||
# This stuff is reaaaaally a hack! I cannot stress enough, that this is
|
||||
# a stupid solution. But there is really no other yet. There is no
|
||||
# possibility in VIM to draw on the screen, but there will be one (see
|
||||
# :help todo Patch to access screen under Python. (Marko Mahni, 2010
|
||||
# Jul 18))
|
||||
text = " (%s) " % ', '.join(params)
|
||||
text = ' ' * (insert_column - len(line)) + text
|
||||
end_column = insert_column + len(text) - 2 # -2 due to bold symbols
|
||||
|
||||
# Need to decode it with utf8, because vim returns always a python 2
|
||||
# string even if it is unicode.
|
||||
e = vim.eval('g:jedi#function_definition_escape').decode('UTF-8')
|
||||
# replace line before with cursor
|
||||
regex = "xjedi=%sx%sxjedix".replace('x', e)
|
||||
|
||||
prefix, replace = line[:insert_column], line[insert_column:end_column]
|
||||
|
||||
# Check the replace stuff for strings, to append them
|
||||
# (don't want to break the syntax)
|
||||
regex_quotes = r'''\\*["']+'''
|
||||
# `add` are all the quotation marks.
|
||||
# join them with a space to avoid producing '''
|
||||
add = ' '.join(re.findall(regex_quotes, replace))
|
||||
# search backwards
|
||||
if add and replace[0] in ['"', "'"]:
|
||||
a = re.search(regex_quotes + '$', prefix)
|
||||
add = ('' if a is None else a.group(0)) + add
|
||||
|
||||
tup = '%s, %s' % (len(add), replace)
|
||||
repl = prefix + (regex % (tup, text)) + add + line[end_column:]
|
||||
|
||||
vim.eval('setline(%s, %s)' % \
|
||||
(row_to_replace, repr(PythonToVimStr(repl))))
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
|
||||
|
||||
def rename():
|
||||
global temp_rename
|
||||
if not int(vim.eval('a:0')):
|
||||
temp_rename = goto(is_related_name=True, no_output=True)
|
||||
_rename_cursor = vim.current.window.cursor
|
||||
|
||||
vim.command('normal A ') # otherwise startinsert doesn't work well
|
||||
vim.current.window.cursor = _rename_cursor
|
||||
|
||||
vim.command('augroup jedi_rename')
|
||||
vim.command('autocmd InsertLeave <buffer> call jedi#rename(1)')
|
||||
vim.command('augroup END')
|
||||
|
||||
vim.command('normal! diw')
|
||||
vim.command(':startinsert')
|
||||
else:
|
||||
cursor = vim.current.window.cursor
|
||||
window_path = vim.current.buffer.name
|
||||
# reset autocommand
|
||||
vim.command('autocmd! jedi_rename InsertLeave')
|
||||
|
||||
replace = vim.eval("expand('<cword>')")
|
||||
vim.command('normal! u') # undo new word
|
||||
vim.command('normal! u') # 2u didn't work...
|
||||
|
||||
if replace is None:
|
||||
echo_highlight('No rename possible, if no name is given.')
|
||||
else:
|
||||
# sort the whole thing reverse (positions at the end of the line
|
||||
# must be first, because they move the stuff before the position).
|
||||
temp_rename = sorted(temp_rename, reverse=True,
|
||||
key=lambda x: (x.module_path, x.start_pos))
|
||||
for r in temp_rename:
|
||||
if r.in_builtin_module():
|
||||
continue
|
||||
if vim.current.buffer.name != r.module_path:
|
||||
vim.eval("jedi#new_buffer('%s')" % r.module_path)
|
||||
|
||||
vim.current.window.cursor = r.start_pos
|
||||
vim.command('normal! cw%s' % replace)
|
||||
|
||||
vim.current.window.cursor = cursor
|
||||
vim.eval("jedi#new_buffer('%s')" % window_path)
|
||||
echo_highlight('Jedi did %s renames!' % len(temp_rename))
|
||||
# reset rename variables
|
||||
temp_rename = None
|
||||
|
||||
|
||||
def tabnew(path):
|
||||
path = os.path.abspath(path)
|
||||
for tab_nr in range(int(vim.eval("tabpagenr('$')"))):
|
||||
for buf_nr in vim.eval("tabpagebuflist(%i + 1)" % tab_nr):
|
||||
buf_nr = int(buf_nr) - 1
|
||||
try:
|
||||
buf_path = vim.buffers[buf_nr].name
|
||||
except IndexError:
|
||||
# Just do good old asking for forgiveness.
|
||||
# don't know why this happens :-)
|
||||
pass
|
||||
else:
|
||||
if buf_path == path:
|
||||
# tab exists, just switch to that tab
|
||||
vim.command('tabfirst | tabnext %i' % (tab_nr + 1))
|
||||
break
|
||||
else:
|
||||
continue
|
||||
break
|
||||
else:
|
||||
# tab doesn't exist, add a new one.
|
||||
vim.command('tabnew %s' % path)
|
||||
|
||||
|
||||
def escape_file_path(path):
|
||||
return path.replace(' ', r'\ ')
|
||||
|
||||
|
||||
def print_to_stdout(level, str_out):
|
||||
print(str_out)
|
||||
3
pytest.ini
Normal file
3
pytest.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
[pytest]
|
||||
# Ignore all files
|
||||
norecursedirs = *
|
||||
52
test/completions.vim
Normal file
52
test/completions.vim
Normal file
@@ -0,0 +1,52 @@
|
||||
let g:jedi#completions_command = 'X'
|
||||
source plugin/jedi.vim
|
||||
|
||||
describe 'completions'
|
||||
before
|
||||
new
|
||||
set filetype=python
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'import'
|
||||
" X is the completion command
|
||||
normal oimporX
|
||||
Expect getline('.') == 'import'
|
||||
normal a subproX
|
||||
Expect getline('.') == 'import subprocess'
|
||||
end
|
||||
|
||||
it 'exception'
|
||||
normal oIndentationErrX
|
||||
Expect getline('.') == 'IndentationError'
|
||||
normal a().filenaX
|
||||
Expect getline('.') == 'IndentationError().filename'
|
||||
end
|
||||
|
||||
it 'dot_open'
|
||||
normal oraisX ImpXErrX()
|
||||
Expect getline('.') == 'raise ImportError()'
|
||||
end
|
||||
|
||||
it 'cycling through entries'
|
||||
" testing select_first doesn't seem to work in ex mode
|
||||
execute "normal oraise impX\<C-n>\<C-n>\<C-n>"
|
||||
Expect getline('.') == 'raise ImportWarning'
|
||||
let g:jedi#popup_select_first = 0
|
||||
execute "normal oraise impX\<C-n>\<C-n>\<C-n>"
|
||||
Expect getline('.') == 'raise ImportWarning'
|
||||
let g:jedi#popup_select_first = 1
|
||||
|
||||
" -longest completes the first one
|
||||
set completeopt -=longest
|
||||
execute "normal oraise baseX"
|
||||
Expect getline('.') == 'raise BaseException'
|
||||
set completeopt +=longest
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
21
test/completions_disabled.vim
Normal file
21
test/completions_disabled.vim
Normal file
@@ -0,0 +1,21 @@
|
||||
let g:jedi#completions_command = 'X'
|
||||
let g:jedi#completions_enabled = 0
|
||||
source plugin/jedi.vim
|
||||
|
||||
describe 'completions_disabled'
|
||||
before
|
||||
new
|
||||
set filetype=python
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'typing'
|
||||
normal oraise ImportErrX
|
||||
Expect getline('.') == 'raise ImportErrX'
|
||||
end
|
||||
end
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
31
test/documentation.vim
Normal file
31
test/documentation.vim
Normal file
@@ -0,0 +1,31 @@
|
||||
source plugin/jedi.vim
|
||||
|
||||
describe 'documentation docstrings'
|
||||
before
|
||||
set filetype=python
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'simple'
|
||||
put = 'ImportError'
|
||||
normal GK
|
||||
Expect bufname('%') == "'__doc__'"
|
||||
Expect &filetype == 'rst'
|
||||
let content = join(getline(1,'$'), "\n")
|
||||
Expect stridx(content, "Import can't find module") > 0
|
||||
normal K
|
||||
Expect bufname('%') == ''
|
||||
end
|
||||
|
||||
it 'no documentation'
|
||||
put = 'x = 2'
|
||||
normal G0K
|
||||
Expect bufname('%') == ''
|
||||
end
|
||||
end
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
176
test/goto.vim
Normal file
176
test/goto.vim
Normal file
@@ -0,0 +1,176 @@
|
||||
let mapleader = '\'
|
||||
source plugin/jedi.vim
|
||||
source test/utils.vim
|
||||
|
||||
describe 'goto_simple'
|
||||
before
|
||||
new " open a new split
|
||||
set filetype=python
|
||||
put =[
|
||||
\ 'def a(): pass',
|
||||
\ 'b = a',
|
||||
\ 'c = b',
|
||||
\ ]
|
||||
normal! ggdd
|
||||
normal! G$
|
||||
Expect line('.') == 3
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'goto_definitions'
|
||||
silent normal \d
|
||||
Expect line('.') == 1
|
||||
"Expect col('.') == 5 " not working yet.
|
||||
end
|
||||
|
||||
it 'goto_assignments'
|
||||
silent normal \g
|
||||
Expect line('.') == 2
|
||||
Expect col('.') == 1
|
||||
|
||||
" cursor before `=` means that it stays there.
|
||||
silent normal \g
|
||||
Expect line('.') == 2
|
||||
Expect col('.') == 1
|
||||
|
||||
" going to the last line changes it.
|
||||
normal! $
|
||||
silent normal \g
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 5
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'goto_with_tabs'
|
||||
before
|
||||
set filetype=python
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'follow_import'
|
||||
put = ['import subprocess', 'subprocess']
|
||||
silent normal G\g
|
||||
Expect getline('.') == 'import subprocess'
|
||||
Expect line('.') == 2
|
||||
Expect col('.') == 8
|
||||
|
||||
silent normal G\d
|
||||
Expect g:current_buffer_is_module('subprocess') == 1
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 1
|
||||
Expect tabpagenr('$') == 2
|
||||
Expect winnr('$') == 1
|
||||
tabprevious
|
||||
Expect bufname('%') == ''
|
||||
end
|
||||
|
||||
it 'multi_definitions'
|
||||
put = ['import tokenize']
|
||||
silent normal G$\d
|
||||
Expect g:current_buffer_is_module('tokenize') == 0
|
||||
Expect g:current_buffer_is_module('token') == 0
|
||||
execute "normal \<CR>"
|
||||
Expect tabpagenr('$') == 2
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('token') == 1
|
||||
|
||||
bd
|
||||
silent normal G$\d
|
||||
execute "normal j\<CR>"
|
||||
Expect tabpagenr('$') == 2
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('tokenize') == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'goto_with_buffers'
|
||||
before
|
||||
set filetype=python
|
||||
let g:jedi#use_tabs_not_buffers = 0
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
set nohidden
|
||||
end
|
||||
|
||||
it 'no_new_tabs'
|
||||
put = ['import os']
|
||||
normal G$
|
||||
call jedi#goto_assignments()
|
||||
python jedi_vim.goto()
|
||||
Expect g:current_buffer_is_module('os') == 0
|
||||
" Without hidden, it's not possible to open a new buffer, when the old
|
||||
" one is not saved.
|
||||
set hidden
|
||||
call jedi#goto_assignments()
|
||||
Expect g:current_buffer_is_module('os') == 1
|
||||
Expect winnr('$') == 1
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 1
|
||||
end
|
||||
|
||||
it 'multi_definitions'
|
||||
set hidden
|
||||
put = ['import tokenize']
|
||||
silent normal G$\d
|
||||
Expect g:current_buffer_is_module('tokenize') == 0
|
||||
Expect g:current_buffer_is_module('token') == 0
|
||||
execute "normal \<CR>"
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('token') == 1
|
||||
|
||||
bd
|
||||
silent normal G$\d
|
||||
execute "normal j\<CR>"
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('tokenize') == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe 'goto_with_splits'
|
||||
before
|
||||
set filetype=python
|
||||
let g:jedi#use_splits_not_buffers = 'left'
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'follow_import'
|
||||
put = ['import subprocess', 'subprocess']
|
||||
silent normal G\g
|
||||
Expect getline('.') == 'import subprocess'
|
||||
Expect line('.') == 2
|
||||
Expect col('.') == 8
|
||||
|
||||
silent normal G\d
|
||||
Expect g:current_buffer_is_module('subprocess') == 1
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 1
|
||||
Expect winnr('$') == 2
|
||||
wincmd l
|
||||
Expect bufname('%') == ''
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
28
test/pyimport.vim
Normal file
28
test/pyimport.vim
Normal file
@@ -0,0 +1,28 @@
|
||||
source plugin/jedi.vim
|
||||
source test/utils.vim
|
||||
|
||||
describe 'pyimport'
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'open_tab'
|
||||
Pyimport os
|
||||
Expect g:current_buffer_is_module('os') == 1
|
||||
Pyimport subprocess
|
||||
Expect g:current_buffer_is_module('subprocess') == 1
|
||||
" the empty tab is sometimes also a tab
|
||||
Expect tabpagenr('$') >= 2
|
||||
end
|
||||
|
||||
it 'completion'
|
||||
" don't know how to test this directly
|
||||
"execute "Pyimport subproc\<Tab>"
|
||||
"Expect g:current_buffer_is_module('subprocess') == 1
|
||||
|
||||
Expect jedi#py_import_completions('subproc', 0, 0) == 'subprocess'
|
||||
Expect jedi#py_import_completions('subprocess', 0, 0) == 'subprocess'
|
||||
Expect jedi#py_import_completions('zip', 0, 0) == "zipfile\nzipimport"
|
||||
end
|
||||
end
|
||||
39
test/signatures.vim
Normal file
39
test/signatures.vim
Normal file
@@ -0,0 +1,39 @@
|
||||
source plugin/jedi.vim
|
||||
|
||||
describe 'signatures'
|
||||
before
|
||||
set filetype=python
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'simple'
|
||||
normal ostr(
|
||||
" equals doautocmd CursorMovedI
|
||||
Python jedi_vim.show_call_signatures()
|
||||
|
||||
Expect getline(1) == '≡jedi=0, ≡ (*obj*) ≡jedi≡'
|
||||
|
||||
doautocmd InsertLeave
|
||||
Expect getline(1) == ''
|
||||
end
|
||||
|
||||
it 'no signature'
|
||||
normal ostr
|
||||
Python jedi_vim.show_call_signatures()
|
||||
Expect getline(1, '$') == ['', 'str ']
|
||||
end
|
||||
|
||||
it 'signatures disabled'
|
||||
let g:jedi#show_signatures = 0
|
||||
|
||||
normal ostr(
|
||||
Python jedi_vim.show_call_signatures()
|
||||
Expect getline(1, '$') == ['', 'str( ']
|
||||
|
||||
let g:jedi#show_signatures = 1
|
||||
end
|
||||
end
|
||||
11
test/utils.vim
Normal file
11
test/utils.vim
Normal file
@@ -0,0 +1,11 @@
|
||||
function! g:current_buffer_is_module(module_name)
|
||||
return g:ends_with(bufname('%'), a:module_name.'.py')
|
||||
endfunction
|
||||
|
||||
|
||||
function g:ends_with(string, end)
|
||||
let l:should = len(a:string) - strlen(a:end)
|
||||
return l:should == stridx(a:string, a:end, should)
|
||||
endfunction
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
2
test_integration.py
Normal file
2
test_integration.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def test_integration(case, monkeypatch, pytestconfig):
|
||||
case.run()
|
||||
Reference in New Issue
Block a user