Remove youcompleteme, install some other stuff.

This commit is contained in:
Max Bucknell 2015-05-02 18:39:53 +01:00
parent 07239a07b0
commit 80969bf64d
61 changed files with 2 additions and 13984 deletions

View file

@ -1,58 +0,0 @@
# Compiled Object files
*.slo
*.lo
*.o
# Compiled Dynamic libraries
*.dll
*.so
*.dylib
# Compiled Static libraries
*.lai
*.la
*.a
# CMake
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
# Python
*.py[cod]
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# custom
ycm_core_tests
# When we use the bcp tool to copy over the parts of boost we care about, it
# also copies some cruft files we don't need; this ignores them
cpp/BoostParts/libs/*/build
cpp/BoostParts/libs/*/test
# These folders in cpp/llvm contain lots of upstream cruft we don't care
# about and would rather not have in our tree...
cpp/llvm/docs/*
cpp/llvm/tools/clang/www/*
# ... but excluding these LLVMBuild.txt files breaks the build so we need to
# explicitely include them
!LLVMBuild.txt
# Exclude auto generated vim doc tags.
doc/tags

View file

@ -1,9 +0,0 @@
[submodule "third_party/requests-futures"]
path = third_party/requests-futures
url = https://github.com/ross/requests-futures
[submodule "third_party/requests"]
path = third_party/requests
url = https://github.com/kennethreitz/requests
[submodule "third_party/ycmd"]
path = third_party/ycmd
url = https://github.com/Valloric/ycmd

View file

@ -1,9 +0,0 @@
language: python
python:
- "2.6"
- "2.7"
before_install:
- git submodule update --init --recursive
install:
- pip install -r python/test_requirements.txt --use-mirrors
script: ./run_tests.sh

View file

@ -1,121 +0,0 @@
Writing good issue reports
==========================
First things first: **the issue tracker is NOT for tech support**. It is for
reporting bugs and requesting features. If your issue amounts to "I can't get
YCM to work on my machine" and the reason why is obviously related to your
machine configuration and the problem would not be resolved with _reasonable_
changes to the YCM codebase, then the issue is likely to be closed.
**A good place to ask questions is the [ycm-users][] Google group**. Rule of
thumb: if you're not sure whether your problem is a real bug, ask on the group.
**YCM compiles just fine**; [the build bots say so][build-bots]. If the bots are
green and YCM doesn't compile on your machine, then _your machine is the root
cause_. Now read the first paragraph again.
Realize that quite literally _thousands_ of people have gotten YCM to work
successfully so if you can't, it's probably because you have a peculiar
system/Vim configuration or you didn't go through the docs carefully enough.
It's very unlikely to be caused by an actual bug in YCM because someone would
have already found it and reported it.
This leads us to point #2: **make sure you have checked the docs before
reporting an issue**. The docs are extensive and cover a ton of things; there's
also an FAQ at the bottom that quite possibly addresses your problem.
Further, **search the issue tracker for similar issues** before creating a new
one. There's no point in duplication; if an existing issue addresses your
problem, please comment there instead of creating a duplicate.
You should also **search the archives of the [ycm-users][] mailing list**.
Lastly, **make sure you are running the latest version of YCM**. The issue you
have encountered may have already been fixed. **Don't forget to recompile
ycm_core.so too** (usually by just running `install.sh` again).
OK, so we've reached this far. You need to create an issue. First realize that
the time it takes to fix your issue is a multiple of how long it takes the
developer to reproduce it. The easier it is to reproduce, the quicker it'll be
fixed.
Here are the things you should do when creating an issue:
1. **Write a step-by-step procedure that when performed repeatedly reproduces
your issue.** If we can't reproduce the issue, then we can't fix it. It's
that simple.
2. Put the following options in your vimrc:
```viml
let g:ycm_server_use_vim_stdout = 1
let g:ycm_server_log_level = 'debug'
```
Then, if possible, start gvim/macvim (not console vim) from the console.
As you use Vim, you'll see the `ycmd` debug output stream in the console.
If you can not use gvim/macvim, run `:YcmDebugInfo` in vim to see what
temporary files (listed under "Server logfiles") the debug output streams
are written to. Attach the debug output stream to your issue.
3. **Create a test case for your issue**. This is critical. Don't talk about how
"when I have X in my file" or similar, _create a file with X in it_ and put
the contents inside code blocks in your issue description. Try to make this
test file _as small as possible_. Don't just paste a huge, 500 line source
file you were editing and present that as a test. _Minimize_ the file so that
the problem is reproduced with the smallest possible amount of test data.
4. **Include your OS and OS version.**
5. **Include the output of `vim --version`.**
Creating good pull requests
===========================
1. **Follow the code style of the existing codebase.**
- The Python code **DOES NOT** follow PEP 8. This is not an oversight, this
is by choice. You can dislike this as much as you want, but you still need
to follow the existing style. Look at other Python files to see what the
style is.
- The C++ code has an automated formatter (`style_format.sh` that runs
`astyle`) but it's not perfect. Again, look at the other C++ files and
match the code style you see.
- Same thing for VimScript. Match the style of the existing code.
2. **Your code needs to be well written and easy to maintain**. This is of the
_utmost_ importance. Other people will have to maintain your code so don't
just throw stuff against the wall until things kinda work.
3. **Split your pull request into several smaller ones if possible.** This
makes it easier to review your changes, which means they will be merged
faster.
4. **Write tests for your code**. If you're changing the VimScript code then
you don't have to since it's hard to test that code. This is also why you
should strive to implement your change in Python if at all possible (and if
it makes sense to do so). Python is also _much_ faster than VimScript.
5. **Explain in detail why your pull request makes sense.** Ask yourself, would
this feature be helpful to others? Not just a few people, but a lot of YCMs
users? See, good features are useful to many. If your feature is only useful
to you and _maybe_ a couple of others, then thats not a good feature.
There is such a thing as “feature overload”. When software accumulates so
many features of which most are only useful to a handful, then that software
has become “bloated”. We dont want that.
Requests for features that are obscure or are helpful to but a few, or are
not part of YCM's "vision" will be rejected. Yes, even if you provide a
patch that completely implements it.
Please include details on exactly what you would like to see, and why. The
why is important - it's not always clear why a feature is really useful. And
sometimes what you want can be done in a different way if the reason for the
change is known. _What goal is your change trying to accomplish?_
6. **Sign the Google [Contributor License Agreement][cla]** (you can sign
online at the bottom of that page). You _must_ sign this form, otherwise we
cannot merge in your changes. **_Always_ mention in the pull request that
you've signed it**, even if you signed it for a previous pull request (you
only need to sign the CLA once).
[build-bots]: https://travis-ci.org/Valloric/YouCompleteMe
[ycm-users]: https://groups.google.com/forum/?hl=en#!forum/ycm-users
[cla]: https://developers.google.com/open-source/cla/individual

View file

@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
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.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

File diff suppressed because it is too large Load diff

View file

@ -1,829 +0,0 @@
" Copyright (C) 2011, 2012 Google Inc.
"
" This file is part of YouCompleteMe.
"
" YouCompleteMe is free software: you can redistribute it and/or modify
" it under the terms of the GNU General Public License as published by
" the Free Software Foundation, either version 3 of the License, or
" (at your option) any later version.
"
" YouCompleteMe is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
"
" You should have received a copy of the GNU General Public License
" along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
" This is basic vim plugin boilerplate
let s:save_cpo = &cpo
set cpo&vim
" This needs to be called outside of a function
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
let s:omnifunc_mode = 0
let s:old_cursor_position = []
let s:cursor_moved = 0
let s:moved_vertically_in_insert_mode = 0
let s:previous_num_chars_on_current_line = -1
let s:diagnostic_ui_filetypes = {
\ 'cpp': 1,
\ 'cs': 1,
\ 'c': 1,
\ 'objc': 1,
\ 'objcpp': 1,
\ }
function! youcompleteme#Enable()
" When vim is in diff mode, don't run
if &diff
return
endif
call s:SetUpBackwardsCompatibility()
" This can be 0 if YCM libs are old or -1 if an exception occured while
" executing the function.
if s:SetUpPython() != 1
return
endif
call s:SetUpCpoptions()
call s:SetUpCompleteopt()
call s:SetUpKeyMappings()
if g:ycm_show_diagnostics_ui
call s:TurnOffSyntasticForCFamily()
endif
call s:SetUpSigns()
call s:SetUpSyntaxHighlighting()
if g:ycm_allow_changing_updatetime && &updatetime > 2000
set ut=2000
endif
call youcompleteme#EnableCursorMovedAutocommands()
augroup youcompleteme
autocmd!
" Note that these events will NOT trigger for the file vim is started with;
" so if you do "vim foo.cc", these events will not trigger when that buffer
" is read. This is because youcompleteme#Enable() is called on VimEnter and
" that happens *after" BufRead/BufEnter has already triggered for the
" initial file.
" We also need to trigger buf init code on the FileType event because when
" the user does :enew and then :set ft=something, we need to run buf init
" code again.
autocmd BufRead,BufEnter,FileType * call s:OnBufferVisit()
autocmd BufUnload * call s:OnBufferUnload( expand( '<afile>:p' ) )
autocmd CursorHold,CursorHoldI * call s:OnCursorHold()
autocmd InsertLeave * call s:OnInsertLeave()
autocmd InsertEnter * call s:OnInsertEnter()
autocmd VimLeave * call s:OnVimLeave()
augroup END
" Calling this once solves the problem of BufRead/BufEnter not triggering for
" the first loaded file. This should be the last command executed in this
" function!
call s:OnBufferVisit()
endfunction
function! youcompleteme#EnableCursorMovedAutocommands()
augroup ycmcompletemecursormove
autocmd!
autocmd CursorMovedI * call s:OnCursorMovedInsertMode()
autocmd CursorMoved * call s:OnCursorMovedNormalMode()
augroup END
endfunction
function! youcompleteme#DisableCursorMovedAutocommands()
autocmd! ycmcompletemecursormove CursorMoved *
autocmd! ycmcompletemecursormove CursorMovedI *
endfunction
function! s:SetUpPython() abort
py import sys
py import vim
exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )'
exe 'python sys.path.insert( 0, "' . s:script_folder_path .
\ '/../third_party/ycmd" )'
py from ycmd import utils
exe 'py utils.AddNearestThirdPartyFoldersToSysPath("'
\ . s:script_folder_path . '")'
" We need to import ycmd's third_party folders as well since we import and
" use ycmd code in the client.
py utils.AddNearestThirdPartyFoldersToSysPath( utils.__file__ )
py from ycm import base
py base.LoadJsonDefaultsIntoVim()
py from ycmd import user_options_store
py user_options_store.SetAll( base.BuildServerConf() )
py from ycm import vimsupport
if !pyeval( 'base.CompatibleWithYcmCore()')
echohl WarningMsg |
\ echomsg "YouCompleteMe unavailable: YCM support libs too old, PLEASE RECOMPILE" |
\ echohl None
return 0
endif
py from ycm.youcompleteme import YouCompleteMe
py ycm_state = YouCompleteMe( user_options_store.GetAll() )
return 1
endfunction
function! s:SetUpKeyMappings()
" The g:ycm_key_select_completion and g:ycm_key_previous_completion used to
" exist and are now here purely for the sake of backwards compatibility; we
" don't want to break users if we can avoid it.
if exists('g:ycm_key_select_completion') &&
\ index(g:ycm_key_list_select_completion,
\ g:ycm_key_select_completion) == -1
call add(g:ycm_key_list_select_completion, g:ycm_key_select_completion)
endif
if exists('g:ycm_key_previous_completion') &&
\ index(g:ycm_key_list_previous_completion,
\ g:ycm_key_previous_completion) == -1
call add(g:ycm_key_list_previous_completion, g:ycm_key_previous_completion)
endif
for key in g:ycm_key_list_select_completion
" With this command, when the completion window is visible, the tab key
" (default) will select the next candidate in the window. In vim, this also
" changes the typed-in text to that of the candidate completion.
exe 'inoremap <expr>' . key .
\ ' pumvisible() ? "\<C-n>" : "\' . key .'"'
endfor
for key in g:ycm_key_list_previous_completion
" This selects the previous candidate for shift-tab (default)
exe 'inoremap <expr>' . key .
\ ' pumvisible() ? "\<C-p>" : "\' . key .'"'
endfor
if !empty( g:ycm_key_invoke_completion )
let invoke_key = g:ycm_key_invoke_completion
" Inside the console, <C-Space> is passed as <Nul> to Vim
if invoke_key ==# '<C-Space>' && !has('gui_running')
let invoke_key = '<Nul>'
endif
" <c-x><c-o> trigger omni completion, <c-p> deselects the first completion
" candidate that vim selects by default
silent! exe 'inoremap <unique> ' . invoke_key . ' <C-X><C-O><C-P>'
endif
if !empty( g:ycm_key_detailed_diagnostics )
silent! exe 'nnoremap <unique> ' . g:ycm_key_detailed_diagnostics .
\ ' :YcmShowDetailedDiagnostic<cr>'
endif
endfunction
function! s:SetUpSigns()
" We try to ensure backwards compatibility with Syntastic if the user has
" already defined styling for Syntastic highlight groups.
if !hlexists( 'YcmErrorSign' )
if hlexists( 'SyntasticErrorSign')
highlight link YcmErrorSign SyntasticErrorSign
else
highlight link YcmErrorSign error
endif
endif
if !hlexists( 'YcmWarningSign' )
if hlexists( 'SyntasticWarningSign')
highlight link YcmWarningSign SyntasticWarningSign
else
highlight link YcmWarningSign todo
endif
endif
if !hlexists( 'YcmErrorLine' )
highlight link YcmErrorLine SyntasticErrorLine
endif
if !hlexists( 'YcmWarningLine' )
highlight link YcmWarningLine SyntasticWarningLine
endif
exe 'sign define YcmError text=' . g:ycm_error_symbol .
\ ' texthl=YcmErrorSign linehl=YcmErrorLine'
exe 'sign define YcmWarning text=' . g:ycm_warning_symbol .
\ ' texthl=YcmWarningSign linehl=YcmWarningLine'
endfunction
function! s:SetUpSyntaxHighlighting()
" We try to ensure backwards compatibility with Syntastic if the user has
" already defined styling for Syntastic highlight groups.
if !hlexists( 'YcmErrorSection' )
if hlexists( 'SyntasticError' )
highlight link YcmErrorSection SyntasticError
else
highlight link YcmErrorSection SpellBad
endif
endif
if !hlexists( 'YcmWarningSection' )
if hlexists( 'SyntasticWarning' )
highlight link YcmWarningSection SyntasticWarning
else
highlight link YcmWarningSection SpellCap
endif
endif
endfunction
function! s:SetUpBackwardsCompatibility()
let complete_in_comments_and_strings =
\ get( g:, 'ycm_complete_in_comments_and_strings', 0 )
if complete_in_comments_and_strings
let g:ycm_complete_in_strings = 1
let g:ycm_complete_in_comments = 1
endif
" ycm_filetypes_to_completely_ignore is the old name for fileype_blacklist
if has_key( g:, 'ycm_filetypes_to_completely_ignore' )
let g:filetype_blacklist = g:ycm_filetypes_to_completely_ignore
endif
endfunction
" Needed so that YCM is used instead of Syntastic
function! s:TurnOffSyntasticForCFamily()
let g:syntastic_cpp_checkers = []
let g:syntastic_c_checkers = []
let g:syntastic_objc_checkers = []
let g:syntastic_objcpp_checkers = []
endfunction
function! s:DiagnosticUiSupportedForCurrentFiletype()
return get( s:diagnostic_ui_filetypes, &filetype, 0 )
endfunction
function! s:AllowedToCompleteInCurrentFile()
if empty( &filetype ) ||
\ getbufvar( winbufnr( winnr() ), "&buftype" ) ==# 'nofile' ||
\ &filetype ==# 'qf'
return 0
endif
let whitelist_allows = has_key( g:ycm_filetype_whitelist, '*' ) ||
\ has_key( g:ycm_filetype_whitelist, &filetype )
let blacklist_allows = !has_key( g:ycm_filetype_blacklist, &filetype )
return whitelist_allows && blacklist_allows
endfunction
function! s:SetUpCpoptions()
" Without this flag in cpoptions, critical YCM mappings do not work. There's
" no way to not have this and have YCM working, so force the flag.
set cpoptions+=B
" This prevents the display of "Pattern not found" & similar messages during
" completion. This is only available since Vim 7.4.314
if pyeval( 'vimsupport.VimVersionAtLeast("7.4.314")' )
set shortmess+=c
endif
endfunction
function! s:SetUpCompleteopt()
" Some plugins (I'm looking at you, vim-notes) change completeopt by for
" instance adding 'longest'. This breaks YCM. So we force our settings.
" There's no two ways about this: if you want to use YCM then you have to
" have these completeopt settings, otherwise YCM won't work at all.
" We need menuone in completeopt, otherwise when there's only one candidate
" for completion, the menu doesn't show up.
set completeopt-=menu
set completeopt+=menuone
" This is unnecessary with our features. People use this option to insert
" the common prefix of all the matches and then add more differentiating chars
" so that they can select a more specific match. With our features, they
" don't need to insert the prefix; they just type the differentiating chars.
" Also, having this option set breaks the plugin.
set completeopt-=longest
if g:ycm_add_preview_to_completeopt
set completeopt+=preview
endif
endfunction
" For various functions/use-cases, we want to keep track of whether the buffer
" has changed since the last time they were invoked. We keep the state of
" b:changedtick of the last time the specific function was called in
" b:ycm_changedtick.
function! s:SetUpYcmChangedTick()
let b:ycm_changedtick =
\ get( b:, 'ycm_changedtick', {
\ 'file_ready_to_parse' : -1,
\ } )
endfunction
function! s:OnVimLeave()
py ycm_state.OnVimLeave()
endfunction
function! s:OnBufferVisit()
" We need to do this even when we are not allowed to complete in the current
" file because we might be allowed to complete in the future! The canonical
" example is creating a new buffer with :enew and then setting a filetype.
call s:SetUpYcmChangedTick()
if !s:AllowedToCompleteInCurrentFile()
return
endif
call s:SetUpCompleteopt()
call s:SetCompleteFunc()
py ycm_state.OnBufferVisit()
call s:OnFileReadyToParse()
endfunction
function! s:OnBufferUnload( deleted_buffer_file )
if !s:AllowedToCompleteInCurrentFile() || empty( a:deleted_buffer_file )
return
endif
py ycm_state.OnBufferUnload( vim.eval( 'a:deleted_buffer_file' ) )
endfunction
function! s:OnCursorHold()
if !s:AllowedToCompleteInCurrentFile()
return
endif
call s:SetUpCompleteopt()
call s:OnFileReadyToParse()
endfunction
function! s:OnFileReadyToParse()
" We need to call this just in case there is no b:ycm_changetick; this can
" happen for special buffers.
call s:SetUpYcmChangedTick()
" Order is important here; we need to extract any done diagnostics before
" reparsing the file again. If we sent the new parse request first, then
" the response would always be pending when we called
" UpdateDiagnosticNotifications.
call s:UpdateDiagnosticNotifications()
let buffer_changed = b:changedtick != b:ycm_changedtick.file_ready_to_parse
if buffer_changed
py ycm_state.OnFileReadyToParse()
endif
let b:ycm_changedtick.file_ready_to_parse = b:changedtick
endfunction
function! s:SetCompleteFunc()
let &completefunc = 'youcompleteme#Complete'
let &l:completefunc = 'youcompleteme#Complete'
if pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
let &omnifunc = 'youcompleteme#OmniComplete'
let &l:omnifunc = 'youcompleteme#OmniComplete'
" If we don't have native filetype support but the omnifunc is set to YCM's
" omnifunc because the previous file the user was editing DID have native
" support, we remove our omnifunc.
elseif &omnifunc == 'youcompleteme#OmniComplete'
let &omnifunc = ''
let &l:omnifunc = ''
endif
endfunction
function! s:OnCursorMovedInsertMode()
if !s:AllowedToCompleteInCurrentFile()
return
endif
py ycm_state.OnCursorMoved()
call s:UpdateCursorMoved()
" Basically, we need to only trigger the completion menu when the user has
" inserted or deleted a character, NOT just when the user moves in insert mode
" (with, say, the arrow keys). If we trigger the menu even on pure moves, then
" it's impossible to move in insert mode since the up/down arrows start moving
" the selected completion in the completion menu. Yeah, people shouldn't be
" moving in insert mode at all (that's what normal mode is for) but explain
" that to the users who complain...
if !s:BufferTextChangedSinceLastMoveInInsertMode()
return
endif
call s:IdentifierFinishedOperations()
if g:ycm_autoclose_preview_window_after_completion
call s:ClosePreviewWindowIfNeeded()
endif
if g:ycm_auto_trigger || s:omnifunc_mode
call s:InvokeCompletion()
endif
" We have to make sure we correctly leave omnifunc mode even when the user
" inserts something like a "operator[]" candidate string which fails
" CurrentIdentifierFinished check.
if s:omnifunc_mode && !pyeval( 'base.LastEnteredCharIsIdentifierChar()')
let s:omnifunc_mode = 0
endif
endfunction
function! s:OnCursorMovedNormalMode()
if !s:AllowedToCompleteInCurrentFile()
return
endif
call s:OnFileReadyToParse()
py ycm_state.OnCursorMoved()
endfunction
function! s:OnInsertLeave()
if !s:AllowedToCompleteInCurrentFile()
return
endif
let s:omnifunc_mode = 0
call s:OnFileReadyToParse()
py ycm_state.OnInsertLeave()
if g:ycm_autoclose_preview_window_after_completion ||
\ g:ycm_autoclose_preview_window_after_insertion
call s:ClosePreviewWindowIfNeeded()
endif
endfunction
function! s:OnInsertEnter()
if !s:AllowedToCompleteInCurrentFile()
return
endif
let s:old_cursor_position = []
endfunction
function! s:UpdateCursorMoved()
let current_position = getpos('.')
let s:cursor_moved = current_position != s:old_cursor_position
let s:moved_vertically_in_insert_mode = s:old_cursor_position != [] &&
\ current_position[ 1 ] != s:old_cursor_position[ 1 ]
let s:old_cursor_position = current_position
endfunction
function! s:BufferTextChangedSinceLastMoveInInsertMode()
if s:moved_vertically_in_insert_mode
let s:previous_num_chars_on_current_line = -1
return 0
endif
let num_chars_in_current_cursor_line = strlen( getline('.') )
if s:previous_num_chars_on_current_line == -1
let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line
return 0
endif
let changed_text_on_current_line = num_chars_in_current_cursor_line !=
\ s:previous_num_chars_on_current_line
let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line
return changed_text_on_current_line
endfunction
function! s:ClosePreviewWindowIfNeeded()
let current_buffer_name = bufname('')
" We don't want to try to close the preview window in special buffers like
" "[Command Line]"; if we do, Vim goes bonkers. Special buffers always start
" with '['.
if current_buffer_name[ 0 ] == '['
return
endif
" This command does the actual closing of the preview window. If no preview
" window is shown, nothing happens.
pclose
endfunction
function! s:UpdateDiagnosticNotifications()
let should_display_diagnostics = g:ycm_show_diagnostics_ui &&
\ s:DiagnosticUiSupportedForCurrentFiletype() &&
\ pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
if !should_display_diagnostics
return
endif
py ycm_state.UpdateDiagnosticInterface()
endfunction
function! s:IdentifierFinishedOperations()
if !pyeval( 'base.CurrentIdentifierFinished()' )
return
endif
py ycm_state.OnCurrentIdentifierFinished()
let s:omnifunc_mode = 0
endfunction
" Returns 1 when inside comment and 2 when inside string
function! s:InsideCommentOrString()
" Has to be col('.') -1 because col('.') doesn't exist at this point. We are
" in insert mode when this func is called.
let syntax_group = synIDattr( synIDtrans( synID( line( '.' ), col( '.' ) - 1, 1 ) ), 'name')
if stridx(syntax_group, 'Comment') > -1
return 1
endif
if stridx(syntax_group, 'String') > -1
return 2
endif
return 0
endfunction
function! s:InsideCommentOrStringAndShouldStop()
let retval = s:InsideCommentOrString()
let inside_comment = retval == 1
let inside_string = retval == 2
if inside_comment && g:ycm_complete_in_comments ||
\ inside_string && g:ycm_complete_in_strings
return 0
endif
return retval
endfunction
function! s:OnBlankLine()
return pyeval( 'not vim.current.line or vim.current.line.isspace()' )
endfunction
function! s:InvokeCompletion()
if &completefunc != "youcompleteme#Complete"
return
endif
if s:InsideCommentOrStringAndShouldStop() || s:OnBlankLine()
return
endif
" This is tricky. First, having 'refresh' set to 'always' in the dictionary
" that our completion function returns makes sure that our completion function
" is called on every keystroke. Second, when the sequence of characters the
" user typed produces no results in our search an infinite loop can occur. The
" problem is that our feedkeys call triggers the OnCursorMovedI event which we
" are tied to. We prevent this infinite loop from starting by making sure that
" the user has moved the cursor since the last time we provided completion
" results.
if !s:cursor_moved
return
endif
" <c-x><c-u> invokes the user's completion function (which we have set to
" youcompleteme#Complete), and <c-p> tells Vim to select the previous
" completion candidate. This is necessary because by default, Vim selects the
" first candidate when completion is invoked, and selecting a candidate
" automatically replaces the current text with it. Calling <c-p> forces Vim to
" deselect the first candidate and in turn preserve the user's current text
" until he explicitly chooses to replace it with a completion.
call feedkeys( "\<C-X>\<C-U>\<C-P>", 'n' )
endfunction
python << EOF
def GetCompletionsInner():
request = ycm_state.GetCurrentCompletionRequest()
request.Start()
while not request.Done():
if bool( int( vim.eval( 'complete_check()' ) ) ):
return { 'words' : [], 'refresh' : 'always'}
results = base.AdjustCandidateInsertionText( request.Response() )
return { 'words' : results, 'refresh' : 'always' }
EOF
function! s:GetCompletions()
py results = GetCompletionsInner()
let results = pyeval( 'results' )
return results
endfunction
" This is our main entry point. This is what vim calls to get completions.
function! youcompleteme#Complete( findstart, base )
" After the user types one character after the call to the omnifunc, the
" completefunc will be called because of our mapping that calls the
" completefunc on every keystroke. Therefore we need to delegate the call we
" 'stole' back to the omnifunc
if s:omnifunc_mode
return youcompleteme#OmniComplete( a:findstart, a:base )
endif
if a:findstart
" InvokeCompletion has this check but we also need it here because of random
" Vim bugs and unfortunate interactions with the autocommands of other
" plugins
if !s:cursor_moved
" for vim, -2 means not found but don't trigger an error message
" see :h complete-functions
return -2
endif
if !pyeval( 'ycm_state.IsServerAlive()' )
return -2
endif
py ycm_state.CreateCompletionRequest()
return pyeval( 'base.CompletionStartColumn()' )
else
return s:GetCompletions()
endif
endfunction
function! youcompleteme#OmniComplete( findstart, base )
if a:findstart
if !pyeval( 'ycm_state.IsServerAlive()' )
return -2
endif
let s:omnifunc_mode = 1
py ycm_state.CreateCompletionRequest( force_semantic = True )
return pyeval( 'base.CompletionStartColumn()' )
else
return s:GetCompletions()
endif
endfunction
function! youcompleteme#ServerPid()
return pyeval( 'ycm_state.ServerPid()' )
endfunction
function! s:RestartServer()
py ycm_state.RestartServer()
endfunction
command! YcmRestartServer call s:RestartServer()
function! s:ShowDetailedDiagnostic()
py ycm_state.ShowDetailedDiagnostic()
endfunction
command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic()
function! s:DebugInfo()
echom "Printing YouCompleteMe debug information..."
let debug_info = pyeval( 'ycm_state.DebugInfo()' )
for line in split( debug_info, "\n" )
echom '-- ' . line
endfor
endfunction
command! YcmDebugInfo call s:DebugInfo()
function! s:CompleterCommand(...)
" CompleterCommand will call the OnUserCommand function of a completer.
" If the first arguments is of the form "ft=..." it can be used to specify the
" completer to use (for example "ft=cpp"). Else the native filetype completer
" of the current buffer is used. If no native filetype completer is found and
" no completer was specified this throws an error. You can use
" "ft=ycm:ident" to select the identifier completer.
" The remaining arguments will be passed to the completer.
let arguments = copy(a:000)
let completer = ''
if a:0 > 0 && strpart(a:1, 0, 3) == 'ft='
if a:1 == 'ft=ycm:ident'
let completer = 'identifier'
endif
let arguments = arguments[1:]
endif
py ycm_state.SendCommandRequest( vim.eval( 'l:arguments' ),
\ vim.eval( 'l:completer' ) )
endfunction
function! youcompleteme#OpenGoToList()
set lazyredraw
cclose
execute 'belowright copen 3'
set nolazyredraw
au WinLeave <buffer> q " automatically leave, if an option is chosen
redraw!
endfunction
command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
\ YcmCompleter call s:CompleterCommand(<f-args>)
function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
return join( pyeval( 'ycm_state.GetDefinedSubcommands()' ),
\ "\n")
endfunction
function! s:ForceCompile()
if !pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
echom "Native filetype completion not supported for current file, "
\ . "cannot force recompilation."
return 0
endif
echom "Forcing compilation, this will block Vim until done."
py ycm_state.OnFileReadyToParse()
while 1
let diagnostics_ready = pyeval(
\ 'ycm_state.DiagnosticsForCurrentFileReady()' )
if diagnostics_ready
break
endif
sleep 100m
endwhile
return 1
endfunction
function! s:ForceCompileAndDiagnostics()
let compilation_succeeded = s:ForceCompile()
if !compilation_succeeded
return
endif
call s:UpdateDiagnosticNotifications()
echom "Diagnostics refreshed."
endfunction
command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics()
function! s:ShowDiagnostics()
let compilation_succeeded = s:ForceCompile()
if !compilation_succeeded
return
endif
let diags = pyeval(
\ 'ycm_state.GetDiagnosticsFromStoredRequest( qflist_format = True )' )
if !empty( diags )
call setloclist( 0, diags )
if g:ycm_open_loclist_on_ycm_diags
lopen
endif
else
echom "No warnings or errors detected"
endif
endfunction
command! YcmDiags call s:ShowDiagnostics()
" This is basic vim plugin boilerplate
let &cpo = s:save_cpo
unlet s:save_cpo

File diff suppressed because it is too large Load diff

View file

@ -1,20 +0,0 @@
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
build_file=$SCRIPT_DIR/third_party/ycmd/build.sh
if [[ ! -f "$build_file" ]]; then
echo "File $build_file doesn't exist; you probably forgot to run:"
printf "\n\tgit submodule update --init --recursive\n\n"
exit 1
fi
"$build_file" "$@"
# Remove old YCM libs if present so that YCM can start.
rm -f python/*ycm_core.* &> /dev/null
rm -f python/*ycm_client_support.* &> /dev/null
rm -f python/*clang*.* &> /dev/null

View file

@ -1,178 +0,0 @@
" Copyright (C) 2011, 2012 Google Inc.
"
" This file is part of YouCompleteMe.
"
" YouCompleteMe is free software: you can redistribute it and/or modify
" it under the terms of the GNU General Public License as published by
" the Free Software Foundation, either version 3 of the License, or
" (at your option) any later version.
"
" YouCompleteMe is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
"
" You should have received a copy of the GNU General Public License
" along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
" This is basic vim plugin boilerplate
let s:save_cpo = &cpo
set cpo&vim
function! s:restore_cpo()
let &cpo = s:save_cpo
unlet s:save_cpo
endfunction
if exists( "g:loaded_youcompleteme" )
call s:restore_cpo()
finish
elseif v:version < 703 || (v:version == 703 && !has('patch584'))
echohl WarningMsg |
\ echomsg "YouCompleteMe unavailable: requires Vim 7.3.584+" |
\ echohl None
call s:restore_cpo()
finish
elseif !has( 'python' )
echohl WarningMsg |
\ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
\ "Python 2.x support" |
\ echohl None
call s:restore_cpo()
finish
endif
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
let s:python_folder_path = s:script_folder_path . '/../python/'
let s:ycmd_folder_path = s:script_folder_path . '/../third_party/ycmd/'
function! s:YcmLibsPresentIn( path_prefix )
if filereadable(a:path_prefix . 'ycm_client_support.so') &&
\ filereadable(a:path_prefix . 'ycm_core.so')
return 1
elseif filereadable(a:path_prefix . 'ycm_client_support.pyd') &&
\ filereadable(a:path_prefix . 'ycm_core.pyd')
return 1
elseif filereadable(a:path_prefix . 'ycm_client_support.dll') &&
\ filereadable(a:path_prefix . 'ycm_core.dll')
return 1
endif
return 0
endfunction
if s:YcmLibsPresentIn( s:python_folder_path )
echohl WarningMsg |
\ echomsg "YCM libraries found in old YouCompleteMe/python location; " .
\ "please RECOMPILE YCM." |
\ echohl None
call s:restore_cpo()
finish
endif
let g:ycm_check_if_ycm_core_present =
\ get( g:, 'ycm_check_if_ycm_core_present', 1 )
if g:ycm_check_if_ycm_core_present &&
\ !s:YcmLibsPresentIn( s:ycmd_folder_path )
echohl WarningMsg |
\ echomsg "ycm_client_support.[so|pyd|dll] and " .
\ "ycm_core.[so|pyd|dll] not detected; you need to compile " .
\ "YCM before using it. Read the docs!" |
\ echohl None
call s:restore_cpo()
finish
endif
let g:loaded_youcompleteme = 1
" NOTE: Most defaults are in default_settings.json. They are loaded into Vim
" global with the 'ycm_' prefix if such a key does not already exist; thus, the
" user can override the defaults.
" The only defaults that are here are the ones that are only relevant to the YCM
" Vim client and not the server.
let g:ycm_allow_changing_updatetime =
\ get( g:, 'ycm_allow_changing_updatetime', 1 )
let g:ycm_open_loclist_on_ycm_diags =
\ get( g:, 'ycm_open_loclist_on_ycm_diags', 1 )
let g:ycm_add_preview_to_completeopt =
\ get( g:, 'ycm_add_preview_to_completeopt', 0 )
let g:ycm_autoclose_preview_window_after_completion =
\ get( g:, 'ycm_autoclose_preview_window_after_completion', 0 )
let g:ycm_autoclose_preview_window_after_insertion =
\ get( g:, 'ycm_autoclose_preview_window_after_insertion', 0 )
let g:ycm_key_list_select_completion =
\ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
let g:ycm_key_list_previous_completion =
\ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
let g:ycm_key_invoke_completion =
\ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
let g:ycm_key_detailed_diagnostics =
\ get( g:, 'ycm_key_detailed_diagnostics', '<leader>d' )
let g:ycm_cache_omnifunc =
\ get( g:, 'ycm_cache_omnifunc', 1 )
let g:ycm_server_use_vim_stdout =
\ get( g:, 'ycm_server_use_vim_stdout', 0 )
let g:ycm_server_log_level =
\ get( g:, 'ycm_server_log_level', 'info' )
let g:ycm_server_keep_logfiles =
\ get( g:, 'ycm_server_keep_logfiles', 0 )
let g:ycm_extra_conf_vim_data =
\ get( g:, 'ycm_extra_conf_vim_data', [] )
let g:ycm_path_to_python_interpreter =
\ get( g:, 'ycm_path_to_python_interpreter', '' )
let g:ycm_show_diagnostics_ui =
\ get( g:, 'ycm_show_diagnostics_ui',
\ get( g:, 'ycm_register_as_syntastic_checker', 1 ) )
let g:ycm_enable_diagnostic_signs =
\ get( g:, 'ycm_enable_diagnostic_signs',
\ get( g:, 'syntastic_enable_signs', 1 ) )
let g:ycm_enable_diagnostic_highlighting =
\ get( g:, 'ycm_enable_diagnostic_highlighting',
\ get( g:, 'syntastic_enable_highlighting', 1 ) )
let g:ycm_echo_current_diagnostic =
\ get( g:, 'ycm_echo_current_diagnostic',
\ get( g:, 'syntastic_echo_current_error', 1 ) )
let g:ycm_always_populate_location_list =
\ get( g:, 'ycm_always_populate_location_list',
\ get( g:, 'syntastic_always_populate_loc_list', 0 ) )
let g:ycm_error_symbol =
\ get( g:, 'ycm_error_symbol',
\ get( g:, 'syntastic_error_symbol', '>>' ) )
let g:ycm_warning_symbol =
\ get( g:, 'ycm_warning_symbol',
\ get( g:, 'syntastic_warning_symbol', '>>' ) )
let g:ycm_goto_buffer_command =
\ get( g:, 'ycm_goto_buffer_command', 'same-buffer' )
" On-demand loading. Let's use the autoload folder and not slow down vim's
" startup procedure.
augroup youcompletemeStart
autocmd!
autocmd VimEnter * call youcompleteme#Enable()
augroup END
" This is basic vim plugin boilerplate
call s:restore_cpo()

View file

@ -1,8 +0,0 @@
#!/bin/bash
ag \
--ignore gmock \
--ignore jedi/ \
--ignore OmniSharpServer \
--ignore testdata \
TODO \
third_party/ycmd/cpp/ycm python autoload plugin

View file

@ -1,5 +0,0 @@
flake8>=2.0
mock>=1.0.1
nose>=1.3.0
PyHamcrest>=1.8.0

View file

@ -1,184 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2011, 2012 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycm import vimsupport
from ycmd import user_options_store
from ycmd import request_wrap
from ycmd import identifier_utils
import ycm_client_support
YCM_VAR_PREFIX = 'ycm_'
def BuildServerConf():
"""Builds a dictionary mapping YCM Vim user options to values. Option names
don't have the 'ycm_' prefix."""
vim_globals = vimsupport.GetReadOnlyVimGlobals( force_python_objects = True )
server_conf = {}
for key, value in vim_globals.items():
if not key.startswith( YCM_VAR_PREFIX ):
continue
try:
new_value = int( value )
except:
new_value = value
new_key = key[ len( YCM_VAR_PREFIX ): ]
server_conf[ new_key ] = new_value
return server_conf
def LoadJsonDefaultsIntoVim():
defaults = user_options_store.DefaultOptions()
vim_defaults = {}
for key, value in defaults.iteritems():
vim_defaults[ 'ycm_' + key ] = value
vimsupport.LoadDictIntoVimGlobals( vim_defaults, overwrite = False )
def CompletionStartColumn():
return ( request_wrap.CompletionStartColumn(
vimsupport.CurrentLineContents(),
vimsupport.CurrentColumn() + 1,
vimsupport.CurrentFiletypes()[ 0 ] ) - 1 )
def CurrentIdentifierFinished():
current_column = vimsupport.CurrentColumn()
previous_char_index = current_column - 1
if previous_char_index < 0:
return True
line = vimsupport.CurrentLineContents()
filetype = vimsupport.CurrentFiletypes()[ 0 ]
regex = identifier_utils.IdentifierRegexForFiletype( filetype )
for match in regex.finditer( line ):
if match.end() == previous_char_index:
return True
# If the whole line is whitespace, that means the user probably finished an
# identifier on the previous line.
return line[ : current_column ].isspace()
def LastEnteredCharIsIdentifierChar():
current_column = vimsupport.CurrentColumn()
if current_column - 1 < 0:
return False
line = vimsupport.CurrentLineContents()
filetype = vimsupport.CurrentFiletypes()[ 0 ]
return (
identifier_utils.StartOfLongestIdentifierEndingAtIndex(
line, current_column, filetype ) != current_column )
def AdjustCandidateInsertionText( candidates ):
"""This function adjusts the candidate insertion text to take into account the
text that's currently in front of the cursor.
For instance ('|' represents the cursor):
1. Buffer state: 'foo.|bar'
2. A completion candidate of 'zoobar' is shown and the user selects it.
3. Buffer state: 'foo.zoobar|bar' instead of 'foo.zoo|bar' which is what the
user wanted.
This function changes candidates to resolve that issue.
It could be argued that the user actually wants the final buffer state to be
'foo.zoobar|' (the cursor at the end), but that would be much more difficult
to implement and is probably not worth doing.
"""
def NewCandidateInsertionText( to_insert, text_after_cursor ):
overlap_len = OverlapLength( to_insert, text_after_cursor )
if overlap_len:
return to_insert[ :-overlap_len ]
return to_insert
text_after_cursor = vimsupport.TextAfterCursor()
if not text_after_cursor:
return candidates
new_candidates = []
for candidate in candidates:
if type( candidate ) is dict:
new_candidate = candidate.copy()
if not 'abbr' in new_candidate:
new_candidate[ 'abbr' ] = new_candidate[ 'word' ]
new_candidate[ 'word' ] = NewCandidateInsertionText(
new_candidate[ 'word' ],
text_after_cursor )
new_candidates.append( new_candidate )
elif type( candidate ) is str:
new_candidates.append(
{ 'abbr': candidate,
'word': NewCandidateInsertionText( candidate, text_after_cursor ) } )
return new_candidates
def OverlapLength( left_string, right_string ):
"""Returns the length of the overlap between two strings.
Example: "foo baro" and "baro zoo" -> 4
"""
left_string_length = len( left_string )
right_string_length = len( right_string )
if not left_string_length or not right_string_length:
return 0
# Truncate the longer string.
if left_string_length > right_string_length:
left_string = left_string[ -right_string_length: ]
elif left_string_length < right_string_length:
right_string = right_string[ :left_string_length ]
if left_string == right_string:
return min( left_string_length, right_string_length )
# Start by looking for a single character match
# and increase length until no match is found.
best = 0
length = 1
while True:
pattern = left_string[ -length: ]
found = right_string.find( pattern )
if found < 0:
return best
length += found
if left_string[ -length: ] == right_string[ :length ]:
best = length
length += 1
COMPATIBLE_WITH_CORE_VERSION = 13
def CompatibleWithYcmCore():
try:
current_core_version = ycm_client_support.YcmCoreVersion()
except AttributeError:
return False
return current_core_version == COMPATIBLE_WITH_CORE_VERSION

View file

@ -1,205 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import requests
import urlparse
from base64 import b64decode, b64encode
from retries import retries
from requests_futures.sessions import FuturesSession
from ycm.unsafe_thread_pool_executor import UnsafeThreadPoolExecutor
from ycm import vimsupport
from ycmd import utils
from ycmd.utils import ToUtf8Json
from ycmd.responses import ServerError, UnknownExtraConf
_HEADERS = {'content-type': 'application/json'}
_EXECUTOR = UnsafeThreadPoolExecutor( max_workers = 30 )
# Setting this to None seems to screw up the Requests/urllib3 libs.
_DEFAULT_TIMEOUT_SEC = 30
_HMAC_HEADER = 'x-ycm-hmac'
class BaseRequest( object ):
def __init__( self ):
pass
def Start( self ):
pass
def Done( self ):
return True
def Response( self ):
return {}
# This method blocks
# |timeout| is num seconds to tolerate no response from server before giving
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def GetDataFromHandler( handler, timeout = _DEFAULT_TIMEOUT_SEC ):
return JsonFromFuture( BaseRequest._TalkToHandlerAsync( '',
handler,
'GET',
timeout ) )
# This is the blocking version of the method. See below for async.
# |timeout| is num seconds to tolerate no response from server before giving
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def PostDataToHandler( data, handler, timeout = _DEFAULT_TIMEOUT_SEC ):
return JsonFromFuture( BaseRequest.PostDataToHandlerAsync( data,
handler,
timeout ) )
# This returns a future! Use JsonFromFuture to get the value.
# |timeout| is num seconds to tolerate no response from server before giving
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def PostDataToHandlerAsync( data, handler, timeout = _DEFAULT_TIMEOUT_SEC ):
return BaseRequest._TalkToHandlerAsync( data, handler, 'POST', timeout )
# This returns a future! Use JsonFromFuture to get the value.
# |method| is either 'POST' or 'GET'.
# |timeout| is num seconds to tolerate no response from server before giving
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def _TalkToHandlerAsync( data,
handler,
method,
timeout = _DEFAULT_TIMEOUT_SEC ):
def SendRequest( data, handler, method, timeout ):
if method == 'POST':
sent_data = ToUtf8Json( data )
return BaseRequest.session.post(
_BuildUri( handler ),
data = sent_data,
headers = BaseRequest._ExtraHeaders( sent_data ),
timeout = timeout )
if method == 'GET':
return BaseRequest.session.get(
_BuildUri( handler ),
headers = BaseRequest._ExtraHeaders(),
timeout = timeout )
@retries( 5, delay = 0.5, backoff = 1.5 )
def DelayedSendRequest( data, handler, method ):
if method == 'POST':
sent_data = ToUtf8Json( data )
return requests.post( _BuildUri( handler ),
data = sent_data,
headers = BaseRequest._ExtraHeaders( sent_data ) )
if method == 'GET':
return requests.get( _BuildUri( handler ),
headers = BaseRequest._ExtraHeaders() )
if not _CheckServerIsHealthyWithCache():
return _EXECUTOR.submit( DelayedSendRequest, data, handler, method )
return SendRequest( data, handler, method, timeout )
@staticmethod
def _ExtraHeaders( request_body = None ):
if not request_body:
request_body = ''
headers = dict( _HEADERS )
headers[ _HMAC_HEADER ] = b64encode(
utils.CreateHexHmac( request_body, BaseRequest.hmac_secret ) )
return headers
session = FuturesSession( executor = _EXECUTOR )
server_location = ''
hmac_secret = ''
def BuildRequestData( include_buffer_data = True ):
line, column = vimsupport.CurrentLineAndColumn()
filepath = vimsupport.GetCurrentBufferFilepath()
request_data = {
'line_num': line + 1,
'column_num': column + 1,
'filepath': filepath
}
if include_buffer_data:
request_data[ 'file_data' ] = vimsupport.GetUnsavedAndCurrentBufferData()
return request_data
def JsonFromFuture( future ):
response = future.result()
_ValidateResponseObject( response )
if response.status_code == requests.codes.server_error:
_RaiseExceptionForData( response.json() )
# We let Requests handle the other status types, we only handle the 500
# error code.
response.raise_for_status()
if response.text:
return response.json()
return None
def _ValidateResponseObject( response ):
if not utils.ContentHexHmacValid(
response.content,
b64decode( response.headers[ _HMAC_HEADER ] ),
BaseRequest.hmac_secret ):
raise RuntimeError( 'Received invalid HMAC for response!' )
return True
def _BuildUri( handler ):
return urlparse.urljoin( BaseRequest.server_location, handler )
SERVER_HEALTHY = False
def _CheckServerIsHealthyWithCache():
global SERVER_HEALTHY
def _ServerIsHealthy():
response = requests.get( _BuildUri( 'healthy' ),
headers = BaseRequest._ExtraHeaders() )
_ValidateResponseObject( response )
response.raise_for_status()
return response.json()
if SERVER_HEALTHY:
return True
try:
SERVER_HEALTHY = _ServerIsHealthy()
return SERVER_HEALTHY
except:
return False
def _RaiseExceptionForData( data ):
if data[ 'exception' ][ 'TYPE' ] == UnknownExtraConf.__name__:
raise UnknownExtraConf( data[ 'exception' ][ 'extra_conf_file' ] )
raise ServerError( '{0}: {1}'.format( data[ 'exception' ][ 'TYPE' ],
data[ 'message' ] ) )

View file

@ -1,93 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import vim
from ycm.client.base_request import BaseRequest, BuildRequestData, ServerError
from ycm import vimsupport
from ycmd.utils import ToUtf8IfNeeded
def _EnsureBackwardsCompatibility( arguments ):
if arguments and arguments[ 0 ] == 'GoToDefinitionElseDeclaration':
arguments[ 0 ] = 'GoTo'
return arguments
class CommandRequest( BaseRequest ):
def __init__( self, arguments, completer_target = None ):
super( CommandRequest, self ).__init__()
self._arguments = _EnsureBackwardsCompatibility( arguments )
self._completer_target = ( completer_target if completer_target
else 'filetype_default' )
self._is_goto_command = (
self._arguments and self._arguments[ 0 ].startswith( 'GoTo' ) )
self._response = None
def Start( self ):
request_data = BuildRequestData()
request_data.update( {
'completer_target': self._completer_target,
'command_arguments': self._arguments
} )
try:
self._response = self.PostDataToHandler( request_data,
'run_completer_command' )
except ServerError as e:
vimsupport.PostVimMessage( e )
def Response( self ):
return self._response
def RunPostCommandActionsIfNeeded( self ):
if not self._is_goto_command or not self.Done() or not self._response:
return
if isinstance( self._response, list ):
defs = [ _BuildQfListItem( x ) for x in self._response ]
vim.eval( 'setqflist( %s )' % repr( defs ) )
vim.eval( 'youcompleteme#OpenGoToList()' )
else:
vimsupport.JumpToLocation( self._response[ 'filepath' ],
self._response[ 'line_num' ],
self._response[ 'column_num' ] )
def SendCommandRequest( arguments, completer ):
request = CommandRequest( arguments, completer )
# This is a blocking call.
request.Start()
request.RunPostCommandActionsIfNeeded()
return request.Response()
def _BuildQfListItem( goto_data_item ):
qf_item = {}
if 'filepath' in goto_data_item:
qf_item[ 'filename' ] = ToUtf8IfNeeded( goto_data_item[ 'filepath' ] )
if 'description' in goto_data_item:
qf_item[ 'text' ] = ToUtf8IfNeeded( goto_data_item[ 'description' ] )
if 'line_num' in goto_data_item:
qf_item[ 'lnum' ] = goto_data_item[ 'line_num' ]
if 'column_num' in goto_data_item:
qf_item[ 'col' ] = goto_data_item[ 'column_num' ] - 1
return qf_item

View file

@ -1,75 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycm import vimsupport
from ycmd.utils import ToUtf8IfNeeded
from ycm.client.base_request import BaseRequest, JsonFromFuture
TIMEOUT_SECONDS = 0.5
class CompletionRequest( BaseRequest ):
def __init__( self, request_data ):
super( CompletionRequest, self ).__init__()
self.request_data = request_data
def Start( self ):
self._response_future = self.PostDataToHandlerAsync( self.request_data,
'completions',
TIMEOUT_SECONDS )
def Done( self ):
return self._response_future.done()
def Response( self ):
if not self._response_future:
return []
try:
return _ConvertCompletionResponseToVimDatas(
JsonFromFuture( self._response_future ) )
except Exception as e:
vimsupport.PostVimMessage( str( e ) )
return []
def _ConvertCompletionDataToVimData( completion_data ):
# see :h complete-items for a description of the dictionary fields
vim_data = {
'word' : ToUtf8IfNeeded( completion_data[ 'insertion_text' ] ),
'dup' : 1,
}
if 'menu_text' in completion_data:
vim_data[ 'abbr' ] = ToUtf8IfNeeded( completion_data[ 'menu_text' ] )
if 'extra_menu_info' in completion_data:
vim_data[ 'menu' ] = ToUtf8IfNeeded( completion_data[ 'extra_menu_info' ] )
if 'kind' in completion_data:
vim_data[ 'kind' ] = ToUtf8IfNeeded(
completion_data[ 'kind' ] )[ 0 ].lower()
if 'detailed_info' in completion_data:
vim_data[ 'info' ] = ToUtf8IfNeeded( completion_data[ 'detailed_info' ] )
return vim_data
def _ConvertCompletionResponseToVimDatas( response_data ):
return [ _ConvertCompletionDataToVimData( x )
for x in response_data[ 'completions' ] ]

View file

@ -1,79 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycm import vimsupport
from ycmd.responses import UnknownExtraConf
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
JsonFromFuture )
class EventNotification( BaseRequest ):
def __init__( self, event_name, extra_data = None ):
super( EventNotification, self ).__init__()
self._event_name = event_name
self._extra_data = extra_data
self._cached_response = None
def Start( self ):
request_data = BuildRequestData()
if self._extra_data:
request_data.update( self._extra_data )
request_data[ 'event_name' ] = self._event_name
self._response_future = self.PostDataToHandlerAsync( request_data,
'event_notification' )
def Done( self ):
return self._response_future.done()
def Response( self ):
if self._cached_response:
return self._cached_response
if not self._response_future or self._event_name != 'FileReadyToParse':
return []
try:
try:
self._cached_response = JsonFromFuture( self._response_future )
except UnknownExtraConf as e:
if vimsupport.Confirm( str( e ) ):
_LoadExtraConfFile( e.extra_conf_file )
else:
_IgnoreExtraConfFile( e.extra_conf_file )
except Exception as e:
vimsupport.PostVimMessage( str( e ) )
return self._cached_response if self._cached_response else []
def SendEventNotificationAsync( event_name, extra_data = None ):
event = EventNotification( event_name, extra_data )
event.Start()
def _LoadExtraConfFile( filepath ):
BaseRequest.PostDataToHandler( { 'filepath': filepath },
'load_extra_conf_file' )
def _IgnoreExtraConfFile( filepath ):
BaseRequest.PostDataToHandler( { 'filepath': filepath },
'ignore_extra_conf_file' )

View file

@ -1,38 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycm.client.completion_request import CompletionRequest
class OmniCompletionRequest( CompletionRequest ):
def __init__( self, omni_completer, request_data ):
super( OmniCompletionRequest, self ).__init__( request_data )
self._omni_completer = omni_completer
def Start( self ):
self._results = self._omni_completer.ComputeCandidates( self.request_data )
def Done( self ):
return True
def Response( self ):
return self._results

View file

@ -1,48 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import time
from threading import Thread
from ycm.client.base_request import BaseRequest
# This class can be used to keep the ycmd server alive for the duration of the
# life of the client. By default, ycmd shuts down if it doesn't see a request in
# a while.
class YcmdKeepalive( object ):
def __init__( self, ping_interval_seconds = 60 * 10 ):
self._keepalive_thread = Thread( target = self._ThreadMain )
self._keepalive_thread.daemon = True
self._ping_interval_seconds = ping_interval_seconds
def Start( self ):
self._keepalive_thread.start()
def _ThreadMain( self ):
while True:
time.sleep( self._ping_interval_seconds )
# We don't care if there's an intermittent problem in contacting the
# server; it's fine to just skip this ping.
try:
BaseRequest.GetDataFromHandler( 'healthy' )
except:
pass

View file

@ -1,226 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from collections import defaultdict, namedtuple
from ycm import vimsupport
import vim
class DiagnosticInterface( object ):
def __init__( self, user_options ):
self._user_options = user_options
# Line and column numbers are 1-based
self._buffer_number_to_line_to_diags = defaultdict(
lambda: defaultdict( list ) )
self._next_sign_id = 1
self._previous_line_number = -1
self._diag_message_needs_clearing = False
self._placed_signs = []
def OnCursorMoved( self ):
line, _ = vimsupport.CurrentLineAndColumn()
line += 1 # Convert to 1-based
if line != self._previous_line_number:
self._previous_line_number = line
if self._user_options[ 'echo_current_diagnostic' ]:
self._EchoDiagnosticForLine( line )
def UpdateWithNewDiagnostics( self, diags ):
normalized_diags = [ _NormalizeDiagnostic( x ) for x in diags ]
self._buffer_number_to_line_to_diags = _ConvertDiagListToDict(
normalized_diags )
if self._user_options[ 'enable_diagnostic_signs' ]:
self._placed_signs, self._next_sign_id = _UpdateSigns(
self._placed_signs,
self._buffer_number_to_line_to_diags,
self._next_sign_id )
if self._user_options[ 'enable_diagnostic_highlighting' ]:
_UpdateSquiggles( self._buffer_number_to_line_to_diags )
if self._user_options[ 'always_populate_location_list' ]:
vimsupport.SetLocationList(
vimsupport.ConvertDiagnosticsToQfList( normalized_diags ) )
def _EchoDiagnosticForLine( self, line_num ):
buffer_num = vim.current.buffer.number
diags = self._buffer_number_to_line_to_diags[ buffer_num ][ line_num ]
if not diags:
if self._diag_message_needs_clearing:
# Clear any previous diag echo
vimsupport.EchoText( '', False )
self._diag_message_needs_clearing = False
return
vimsupport.EchoTextVimWidth( diags[ 0 ][ 'text' ] )
self._diag_message_needs_clearing = True
def _UpdateSquiggles( buffer_number_to_line_to_diags ):
vimsupport.ClearYcmSyntaxMatches()
line_to_diags = buffer_number_to_line_to_diags[ vim.current.buffer.number ]
for diags in line_to_diags.itervalues():
for diag in diags:
location_extent = diag[ 'location_extent' ]
is_error = _DiagnosticIsError( diag )
if location_extent[ 'start' ][ 'line_num' ] < 0:
location = diag[ 'location' ]
vimsupport.AddDiagnosticSyntaxMatch(
location[ 'line_num' ],
location[ 'column_num' ] )
else:
vimsupport.AddDiagnosticSyntaxMatch(
location_extent[ 'start' ][ 'line_num' ],
location_extent[ 'start' ][ 'column_num' ],
location_extent[ 'end' ][ 'line_num' ],
location_extent[ 'end' ][ 'column_num' ],
is_error = is_error )
for diag_range in diag[ 'ranges' ]:
vimsupport.AddDiagnosticSyntaxMatch(
diag_range[ 'start' ][ 'line_num' ],
diag_range[ 'start' ][ 'column_num' ],
diag_range[ 'end' ][ 'line_num' ],
diag_range[ 'end' ][ 'column_num' ],
is_error = is_error )
def _UpdateSigns( placed_signs, buffer_number_to_line_to_diags, next_sign_id ):
new_signs, kept_signs, next_sign_id = _GetKeptAndNewSigns(
placed_signs, buffer_number_to_line_to_diags, next_sign_id
)
# Dummy sign used to prevent "flickering" in Vim when last mark gets
# deleted from buffer. Dummy sign prevents Vim to collapsing the sign column
# in that case.
# There's also a vim bug which causes the whole window to redraw in some
# conditions (vim redraw logic is very complex). But, somehow, if we place a
# dummy sign before placing other "real" signs, it will not redraw the
# buffer (patch to vim pending).
dummy_sign_needed = not kept_signs and new_signs
if dummy_sign_needed:
vimsupport.PlaceDummySign( next_sign_id + 1,
vim.current.buffer.number,
new_signs[ 0 ].line )
# We place only those signs that haven't been placed yet.
new_placed_signs = _PlaceNewSigns( kept_signs, new_signs )
# We use incremental placement, so signs that already placed on the correct
# lines will not be deleted and placed again, which should improve performance
# in case of many diags. Signs which don't exist in the current diag should be
# deleted.
_UnplaceObsoleteSigns( kept_signs, placed_signs )
if dummy_sign_needed:
vimsupport.UnPlaceDummySign( next_sign_id + 1, vim.current.buffer.number )
return new_placed_signs, next_sign_id
def _GetKeptAndNewSigns( placed_signs, buffer_number_to_line_to_diags,
next_sign_id ):
new_signs = []
kept_signs = []
for buffer_number, line_to_diags in buffer_number_to_line_to_diags.iteritems():
if not vimsupport.BufferIsVisible( buffer_number ):
continue
for line, diags in line_to_diags.iteritems():
for diag in diags:
sign = _DiagSignPlacement( next_sign_id,
line,
buffer_number,
_DiagnosticIsError( diag ) )
if sign not in placed_signs:
new_signs += [ sign ]
next_sign_id += 1
else:
# We use .index here because `sign` contains a new id, but
# we need the sign with the old id to unplace it later on.
# We won't be placing the new sign.
kept_signs += [ placed_signs[ placed_signs.index( sign ) ] ]
return new_signs, kept_signs, next_sign_id
def _PlaceNewSigns( kept_signs, new_signs ):
placed_signs = kept_signs[:]
for sign in new_signs:
# Do not set two signs on the same line, it will screw up storing sign
# locations.
if sign in placed_signs:
continue
vimsupport.PlaceSign( sign.id, sign.line, sign.buffer, sign.is_error )
placed_signs.append(sign)
return placed_signs
def _UnplaceObsoleteSigns( kept_signs, placed_signs ):
for sign in placed_signs:
if sign not in kept_signs:
vimsupport.UnplaceSignInBuffer( sign.buffer, sign.id )
def _ConvertDiagListToDict( diag_list ):
buffer_to_line_to_diags = defaultdict( lambda: defaultdict( list ) )
for diag in diag_list:
location = diag[ 'location' ]
buffer_number = vimsupport.GetBufferNumberForFilename(
location[ 'filepath' ] )
line_number = location[ 'line_num' ]
buffer_to_line_to_diags[ buffer_number ][ line_number ].append( diag )
for line_to_diags in buffer_to_line_to_diags.itervalues():
for diags in line_to_diags.itervalues():
# We also want errors to be listed before warnings so that errors aren't
# hidden by the warnings; Vim won't place a sign oven an existing one.
diags.sort( key = lambda diag: ( diag[ 'location' ][ 'column_num' ],
diag[ 'kind' ] ) )
return buffer_to_line_to_diags
def _DiagnosticIsError( diag ):
return diag[ 'kind' ] == 'ERROR'
def _NormalizeDiagnostic( diag ):
def ClampToOne( value ):
return value if value > 0 else 1
location = diag[ 'location' ]
location[ 'column_num' ] = ClampToOne( location[ 'column_num' ] )
location[ 'line_num' ] = ClampToOne( location[ 'line_num' ] )
return diag
class _DiagSignPlacement( namedtuple( "_DiagSignPlacement",
[ 'id', 'line', 'buffer', 'is_error' ] ) ):
# We want two signs that have different ids but the same location to compare
# equal. ID doesn't matter.
def __eq__( self, other ):
return ( self.line == other.line and
self.buffer == other.buffer and
self.is_error == other.is_error )

View file

@ -1,96 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2011, 2012, 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import vim
from ycm import vimsupport
from ycmd.completers.completer import Completer
OMNIFUNC_RETURNED_BAD_VALUE = 'Omnifunc returned bad value to YCM!'
OMNIFUNC_NOT_LIST = ( 'Omnifunc did not return a list or a dict with a "words" '
' list when expected.' )
class OmniCompleter( Completer ):
def __init__( self, user_options ):
super( OmniCompleter, self ).__init__( user_options )
self._omnifunc = None
def SupportedFiletypes( self ):
return []
def ShouldUseCache( self ):
return bool( self.user_options[ 'cache_omnifunc' ] )
def ShouldUseNow( self, request_data ):
if not self._omnifunc:
return False
if self.ShouldUseCache():
return super( OmniCompleter, self ).ShouldUseNow( request_data )
return self.ShouldUseNowInner( request_data )
def ShouldUseNowInner( self, request_data ):
if not self._omnifunc:
return False
return super( OmniCompleter, self ).ShouldUseNowInner( request_data )
def ComputeCandidates( self, request_data ):
if self.ShouldUseCache():
return super( OmniCompleter, self ).ComputeCandidates(
request_data )
else:
if self.ShouldUseNowInner( request_data ):
return self.ComputeCandidatesInner( request_data )
return []
def ComputeCandidatesInner( self, request_data ):
if not self._omnifunc:
return []
try:
return_value = int( vim.eval( self._omnifunc + '(1,"")' ) )
if return_value < 0:
return []
omnifunc_call = [ self._omnifunc,
"(0,'",
vimsupport.EscapeForVim( request_data[ 'query' ] ),
"')" ]
items = vim.eval( ''.join( omnifunc_call ) )
if 'words' in items:
items = items[ 'words' ]
if not hasattr( items, '__iter__' ):
raise TypeError( OMNIFUNC_NOT_LIST )
return filter( bool, items )
except ( TypeError, ValueError, vim.error ) as error:
vimsupport.PostVimMessage(
OMNIFUNC_RETURNED_BAD_VALUE + ' ' + str( error ) )
return []
def OnFileReadyToParse( self, request_data ):
self._omnifunc = vim.eval( '&omnifunc' )

View file

@ -1,219 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import re
import vim
from ycm import vimsupport
SYNTAX_GROUP_REGEX = re.compile(
r"""^
(?P<group_name>\w+)
\s+
xxx
\s+
(?P<content>.+?)
$""",
re.VERBOSE )
KEYWORD_REGEX = re.compile( r'^[\w,]+$' )
SYNTAX_ARGUMENT_REGEX = re.compile(
r"^\w+=.*$" )
SYNTAX_ARGUMENTS = set([
'cchar',
'conceal',
'contained',
'containedin',
'nextgroup',
'skipempty',
'skipnl',
'skipwhite',
'transparent',
'concealends',
'contains',
'display',
'extend',
'fold',
'oneline',
'keepend',
'excludenl',
])
# We want to parse lines starting with these args
ALLOWED_SYNTAX_ARGUMENTS = set([
'contained',
])
# These are the parent groups from which we want to extract keywords
ROOT_GROUPS = set([
'Statement',
'Boolean',
'Include',
'Type',
'Identifier',
])
class SyntaxGroup( object ):
def __init__( self, name, lines = None ):
self.name = name
self.lines = lines if lines else []
self.children = []
def SyntaxKeywordsForCurrentBuffer():
vim.command( 'redir => b:ycm_syntax' )
vim.command( 'silent! syntax list' )
vim.command( 'redir END' )
syntax_output = vimsupport.GetVariableValue( 'b:ycm_syntax' )
return _KeywordsFromSyntaxListOutput( syntax_output )
def _KeywordsFromSyntaxListOutput( syntax_output ):
group_name_to_group = _SyntaxGroupsFromOutput( syntax_output )
_ConnectGroupChildren( group_name_to_group )
groups_with_keywords = []
for root_group in ROOT_GROUPS:
groups_with_keywords.extend(
_GetAllDescendentats( group_name_to_group[ root_group ] ) )
keywords = []
for group in groups_with_keywords:
keywords.extend( _ExtractKeywordsFromGroup( group ) )
return set( keywords )
def _SyntaxGroupsFromOutput( syntax_output ):
group_name_to_group = _CreateInitialGroupMap()
lines = syntax_output.split( '\n' )
looking_for_group = True
current_group = None
for line in lines:
if not line:
continue
match = SYNTAX_GROUP_REGEX.search( line )
if match:
if looking_for_group:
looking_for_group = False
else:
group_name_to_group[ current_group.name ] = current_group
current_group = SyntaxGroup( match.group( 'group_name' ),
[ match.group( 'content').strip() ] )
else:
if looking_for_group:
continue
if line[ 0 ] == ' ' or line[ 0 ] == '\t':
current_group.lines.append( line.strip() )
if current_group:
group_name_to_group[ current_group.name ] = current_group
return group_name_to_group
def _CreateInitialGroupMap():
def AddToGroupMap( name, parent ):
new_group = SyntaxGroup( name )
group_name_to_group[ name ] = new_group
parent.children.append( new_group )
statement_group = SyntaxGroup( 'Statement' )
type_group = SyntaxGroup( 'Type' )
identifier_group = SyntaxGroup( 'Identifier' )
# See `:h group-name` for details on how the initial group hierarchy is built
group_name_to_group = {
'Statement': statement_group,
'Type': type_group,
'Boolean': SyntaxGroup( 'Boolean' ),
'Include': SyntaxGroup( 'Include' ),
'Identifier': identifier_group,
}
AddToGroupMap( 'Conditional', statement_group )
AddToGroupMap( 'Repeat' , statement_group )
AddToGroupMap( 'Label' , statement_group )
AddToGroupMap( 'Operator' , statement_group )
AddToGroupMap( 'Keyword' , statement_group )
AddToGroupMap( 'Exception' , statement_group )
AddToGroupMap( 'StorageClass', type_group )
AddToGroupMap( 'Structure' , type_group )
AddToGroupMap( 'Typedef' , type_group )
AddToGroupMap( 'Function', identifier_group )
return group_name_to_group
def _ConnectGroupChildren( group_name_to_group ):
def GetParentNames( group ):
links_to = 'links to '
parent_names = []
for line in group.lines:
if line.startswith( links_to ):
parent_names.append( line[ len( links_to ): ] )
return parent_names
for group in group_name_to_group.itervalues():
parent_names = GetParentNames( group )
for parent_name in parent_names:
try:
parent_group = group_name_to_group[ parent_name ]
except KeyError:
continue
parent_group.children.append( group )
def _GetAllDescendentats( root_group ):
descendants = []
for child in root_group.children:
descendants.append( child )
descendants.extend( _GetAllDescendentats( child ) )
return descendants
def _ExtractKeywordsFromGroup( group ):
keywords = []
for line in group.lines:
if line.startswith( 'links to ' ):
continue
words = line.split()
if not words or ( words[ 0 ] in SYNTAX_ARGUMENTS and
words[ 0 ] not in ALLOWED_SYNTAX_ARGUMENTS ):
continue
for word in words:
if ( word not in SYNTAX_ARGUMENTS and
not SYNTAX_ARGUMENT_REGEX.match( word ) and
KEYWORD_REGEX.match( word ) ):
if word.endswith( ',' ):
word = word[ :-1 ]
keywords.append( word )
return keywords

View file

@ -1,36 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2011, 2012 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from mock import MagicMock
import sys
def MockVimModule():
"""The 'vim' module is something that is only present when running inside the
Vim Python interpreter, so we replace it with a MagicMock for tests. """
def VimEval( value ):
if value == "g:ycm_min_num_of_chars_for_completion":
return 0
return ''
vim_mock = MagicMock()
vim_mock.eval = MagicMock( side_effect = VimEval )
sys.modules[ 'vim' ] = vim_mock
return vim_mock

View file

@ -1,279 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from nose.tools import eq_, ok_, with_setup
from mock import MagicMock
from ycm.test_utils import MockVimModule
vim_mock = MockVimModule()
from ycm import base
from ycm import vimsupport
import sys
# column is 0-based
def SetVimCurrentColumnAndLineValue( column, line_value ):
vimsupport.CurrentColumn = MagicMock( return_value = column )
vimsupport.CurrentLineContents = MagicMock( return_value = line_value )
def Setup():
sys.modules[ 'ycm.vimsupport' ] = MagicMock()
vimsupport.CurrentFiletypes = MagicMock( return_value = [''] )
vimsupport.CurrentColumn = MagicMock( return_value = 1 )
vimsupport.CurrentLineContents = MagicMock( return_value = '' )
@with_setup( Setup )
def AdjustCandidateInsertionText_Basic_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar' )
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ 'foobar' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_ParenInTextAfterCursor_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar(zoo' )
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ 'foobar' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_PlusInTextAfterCursor_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar+zoo' )
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ 'foobar' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_WhitespaceInTextAfterCursor_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar zoo' )
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ 'foobar' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_MoreThanWordMatchingAfterCursor_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar.h' )
eq_( [ { 'abbr': 'foobar.h', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ 'foobar.h' ] ) )
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar(zoo' )
eq_( [ { 'abbr': 'foobar(zoo', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ 'foobar(zoo' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_NotSuffix_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar' )
eq_( [ { 'abbr': 'foofoo', 'word': 'foofoo' } ],
base.AdjustCandidateInsertionText( [ 'foofoo' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_NothingAfterCursor_test():
vimsupport.TextAfterCursor = MagicMock( return_value = '' )
eq_( [ 'foofoo',
'zobar' ],
base.AdjustCandidateInsertionText( [ 'foofoo',
'zobar' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_MultipleStrings_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar' )
eq_( [ { 'abbr': 'foobar', 'word': 'foo' },
{ 'abbr': 'zobar', 'word': 'zo' },
{ 'abbr': 'qbar', 'word': 'q' },
{ 'abbr': 'bar', 'word': '' },
],
base.AdjustCandidateInsertionText( [ 'foobar',
'zobar',
'qbar',
'bar' ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_DictInput_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar' )
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ],
base.AdjustCandidateInsertionText(
[ { 'word': 'foobar' } ] ) )
@with_setup( Setup )
def AdjustCandidateInsertionText_DontTouchAbbr_test():
vimsupport.TextAfterCursor = MagicMock( return_value = 'bar' )
eq_( [ { 'abbr': '1234', 'word': 'foo' } ],
base.AdjustCandidateInsertionText(
[ { 'abbr': '1234', 'word': 'foobar' } ] ) )
@with_setup( Setup )
def OverlapLength_Basic_test():
eq_( 3, base.OverlapLength( 'foo bar', 'bar zoo' ) )
eq_( 3, base.OverlapLength( 'foobar', 'barzoo' ) )
@with_setup( Setup )
def OverlapLength_BasicWithUnicode_test():
eq_( 3, base.OverlapLength( u'bar fäö', u'fäö bar' ) )
eq_( 3, base.OverlapLength( u'zoofäö', u'fäözoo' ) )
@with_setup( Setup )
def OverlapLength_OneCharOverlap_test():
eq_( 1, base.OverlapLength( 'foo b', 'b zoo' ) )
@with_setup( Setup )
def OverlapLength_SameStrings_test():
eq_( 6, base.OverlapLength( 'foobar', 'foobar' ) )
@with_setup( Setup )
def OverlapLength_Substring_test():
eq_( 6, base.OverlapLength( 'foobar', 'foobarzoo' ) )
eq_( 6, base.OverlapLength( 'zoofoobar', 'foobar' ) )
@with_setup( Setup )
def OverlapLength_LongestOverlap_test():
eq_( 7, base.OverlapLength( 'bar foo foo', 'foo foo bar' ) )
@with_setup( Setup )
def OverlapLength_EmptyInput_test():
eq_( 0, base.OverlapLength( '', 'goobar' ) )
eq_( 0, base.OverlapLength( 'foobar', '' ) )
eq_( 0, base.OverlapLength( '', '' ) )
@with_setup( Setup )
def OverlapLength_NoOverlap_test():
eq_( 0, base.OverlapLength( 'foobar', 'goobar' ) )
eq_( 0, base.OverlapLength( 'foobar', '(^($@#$#@' ) )
eq_( 0, base.OverlapLength( 'foo bar zoo', 'foo zoo bar' ) )
@with_setup( Setup )
def LastEnteredCharIsIdentifierChar_Basic_test():
SetVimCurrentColumnAndLineValue( 3, 'abc' )
ok_( base.LastEnteredCharIsIdentifierChar() )
SetVimCurrentColumnAndLineValue( 2, 'abc' )
ok_( base.LastEnteredCharIsIdentifierChar() )
SetVimCurrentColumnAndLineValue( 1, 'abc' )
ok_( base.LastEnteredCharIsIdentifierChar() )
@with_setup( Setup )
def LastEnteredCharIsIdentifierChar_FiletypeHtml_test():
SetVimCurrentColumnAndLineValue( 3, 'ab-' )
vimsupport.CurrentFiletypes = MagicMock( return_value = ['html'] )
ok_( base.LastEnteredCharIsIdentifierChar() )
@with_setup( Setup )
def LastEnteredCharIsIdentifierChar_ColumnIsZero_test():
SetVimCurrentColumnAndLineValue( 0, 'abc' )
ok_( not base.LastEnteredCharIsIdentifierChar() )
@with_setup( Setup )
def LastEnteredCharIsIdentifierChar_LineEmpty_test():
SetVimCurrentColumnAndLineValue( 3, '' )
ok_( not base.LastEnteredCharIsIdentifierChar() )
SetVimCurrentColumnAndLineValue( 0, '' )
ok_( not base.LastEnteredCharIsIdentifierChar() )
@with_setup( Setup )
def LastEnteredCharIsIdentifierChar_NotIdentChar_test():
SetVimCurrentColumnAndLineValue( 3, 'ab;' )
ok_( not base.LastEnteredCharIsIdentifierChar() )
SetVimCurrentColumnAndLineValue( 1, ';' )
ok_( not base.LastEnteredCharIsIdentifierChar() )
SetVimCurrentColumnAndLineValue( 3, 'ab-' )
ok_( not base.LastEnteredCharIsIdentifierChar() )
@with_setup( Setup )
def CurrentIdentifierFinished_Basic_test():
SetVimCurrentColumnAndLineValue( 3, 'ab;' )
ok_( base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 2, 'ab;' )
ok_( not base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 1, 'ab;' )
ok_( not base.CurrentIdentifierFinished() )
@with_setup( Setup )
def CurrentIdentifierFinished_NothingBeforeColumn_test():
SetVimCurrentColumnAndLineValue( 0, 'ab;' )
ok_( base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 0, '' )
ok_( base.CurrentIdentifierFinished() )
@with_setup( Setup )
def CurrentIdentifierFinished_InvalidColumn_test():
SetVimCurrentColumnAndLineValue( 5, '' )
ok_( not base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 5, 'abc' )
ok_( not base.CurrentIdentifierFinished() )
@with_setup( Setup )
def CurrentIdentifierFinished_InMiddleOfLine_test():
SetVimCurrentColumnAndLineValue( 4, 'bar.zoo' )
ok_( base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 4, 'bar(zoo' )
ok_( base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 4, 'bar-zoo' )
ok_( base.CurrentIdentifierFinished() )
@with_setup( Setup )
def CurrentIdentifierFinished_Html_test():
SetVimCurrentColumnAndLineValue( 4, 'bar-zoo' )
vimsupport.CurrentFiletypes = MagicMock( return_value = ['html'] )
ok_( not base.CurrentIdentifierFinished() )
@with_setup( Setup )
def CurrentIdentifierFinished_WhitespaceOnly_test():
SetVimCurrentColumnAndLineValue( 1, '\n' )
ok_( base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 3, '\n ' )
ok_( base.CurrentIdentifierFinished() )
SetVimCurrentColumnAndLineValue( 3, '\t\t\t\t' )
ok_( base.CurrentIdentifierFinished() )

View file

@ -1,326 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import os
from nose.tools import eq_
from hamcrest import assert_that, has_items
from ycm.test_utils import MockVimModule
vim_mock = MockVimModule()
from ycm import syntax_parse
def ContentsOfTestFile( test_file ):
dir_of_script = os.path.dirname( os.path.abspath( __file__ ) )
full_path_to_test_file = os.path.join( dir_of_script, 'testdata', test_file )
return open( full_path_to_test_file ).read()
def KeywordsFromSyntaxListOutput_PythonSyntax_test():
eq_( set(['bytearray', 'IndexError', 'all', 'help', 'vars',
'SyntaxError', 'global', 'elif', 'unicode', 'sorted', 'memoryview',
'isinstance', 'except', 'nonlocal', 'NameError', 'finally',
'BytesWarning', 'dict', 'IOError', 'pass', 'oct', 'match', 'bin',
'SystemExit', 'return', 'StandardError', 'format', 'TabError',
'break', 'next', 'not', 'UnicodeDecodeError', 'False',
'RuntimeWarning', 'list', 'iter', 'try', 'reload', 'Warning',
'round', 'dir', 'cmp', 'set', 'bytes', 'UnicodeTranslateError',
'intern', 'issubclass', 'yield', 'Ellipsis', 'hash', 'locals',
'BufferError', 'slice', 'for', 'FloatingPointError', 'sum',
'VMSError', 'getattr', 'abs', 'print', 'import', 'True',
'FutureWarning', 'ImportWarning', 'None', 'EOFError', 'len',
'frozenset', 'ord', 'super', 'raise', 'TypeError',
'KeyboardInterrupt', 'UserWarning', 'filter', 'range',
'staticmethod', 'SystemError', 'or', 'BaseException', 'pow',
'RuntimeError', 'float', 'MemoryError', 'StopIteration', 'globals',
'divmod', 'enumerate', 'apply', 'LookupError', 'open', 'basestring',
'from', 'UnicodeError', 'zip', 'hex', 'long', 'IndentationError',
'int', 'chr', '__import__', 'type', 'Exception', 'continue',
'tuple', 'reduce', 'reversed', 'else', 'assert',
'UnicodeEncodeError', 'input', 'with', 'hasattr', 'delattr',
'setattr', 'raw_input', 'PendingDeprecationWarning', 'compile',
'ArithmeticError', 'while', 'del', 'str', 'property', 'def', 'and',
'GeneratorExit', 'ImportError', 'xrange', 'is', 'EnvironmentError',
'KeyError', 'coerce', 'SyntaxWarning', 'file', 'in', 'unichr',
'ascii', 'any', 'as', 'if', 'OSError', 'DeprecationWarning', 'min',
'UnicodeWarning', 'execfile', 'id', 'complex', 'bool', 'ValueError',
'NotImplemented', 'map', 'exec', 'buffer', 'max', 'class', 'object',
'repr', 'callable', 'ZeroDivisionError', 'eval', '__debug__',
'ReferenceError', 'AssertionError', 'classmethod',
'UnboundLocalError', 'NotImplementedError', 'lambda',
'AttributeError', 'OverflowError', 'WindowsError'] ),
syntax_parse._KeywordsFromSyntaxListOutput(
ContentsOfTestFile( 'python_syntax' ) ) )
def KeywordsFromSyntaxListOutput_CppSyntax_test():
eq_( set(['int_fast32_t', 'FILE', 'size_t', 'bitor', 'typedef', 'const',
'struct', 'uint8_t', 'fpos_t', 'thread_local', 'unsigned',
'uint_least16_t', 'match', 'do', 'intptr_t', 'uint_least64_t',
'return', 'auto', 'void', '_Complex', 'break', '_Alignof', 'not',
'using', '_Static_assert', '_Thread_local', 'public',
'uint_fast16_t', 'this', 'continue', 'char32_t', 'int16_t',
'intmax_t', 'static', 'clock_t', 'sizeof', 'int_fast64_t',
'mbstate_t', 'try', 'xor', 'uint_fast32_t', 'int_least8_t', 'div_t',
'volatile', 'template', 'char16_t', 'new', 'ldiv_t',
'int_least16_t', 'va_list', 'uint_least8_t', 'goto', 'noreturn',
'enum', 'static_assert', 'bitand', 'compl', 'imaginary', 'jmp_buf',
'throw', 'asm', 'ptrdiff_t', 'uint16_t', 'or', 'uint_fast8_t',
'_Bool', 'int32_t', 'float', 'private', 'restrict', 'wint_t',
'operator', 'not_eq', '_Imaginary', 'alignas', 'union', 'long',
'uint_least32_t', 'int_least64_t', 'friend', 'uintptr_t', 'int8_t',
'else', 'export', 'int_fast8_t', 'catch', 'true', 'case', 'default',
'double', '_Noreturn', 'signed', 'typename', 'while', 'protected',
'wchar_t', 'wctrans_t', 'uint64_t', 'delete', 'and', 'register',
'false', 'int', 'uintmax_t', 'off_t', 'char', 'int64_t',
'int_fast16_t', 'DIR', '_Atomic', 'time_t', 'xor_eq', 'namespace',
'virtual', 'complex', 'bool', 'mutable', 'if', 'int_least32_t',
'sig_atomic_t', 'and_eq', 'ssize_t', 'alignof', '_Alignas',
'_Generic', 'extern', 'class', 'typeid', 'short', 'for',
'uint_fast64_t', 'wctype_t', 'explicit', 'or_eq', 'switch',
'uint32_t', 'inline']),
syntax_parse._KeywordsFromSyntaxListOutput(
ContentsOfTestFile( 'cpp_syntax' ) ) )
def KeywordsFromSyntaxListOutput_JavaSyntax_test():
eq_( set(['code', 'text', 'cols', 'datetime', 'disabled', 'shape', 'codetype',
'alt', 'compact', 'style', 'valuetype', 'short', 'finally',
'continue', 'extends', 'valign', 'match', 'bordercolor', 'do',
'return', 'rel', 'rules', 'void', 'nohref', 'abbr', 'background',
'scrolling', 'instanceof', 'name', 'summary', 'try', 'default',
'noshade', 'coords', 'dir', 'frame', 'usemap', 'ismap', 'static',
'hspace', 'vlink', 'for', 'selected', 'rev', 'vspace', 'content',
'method', 'version', 'volatile', 'above', 'new', 'charoff', 'public',
'alink', 'enum', 'codebase', 'if', 'noresize', 'interface',
'checked', 'byte', 'super', 'throw', 'src', 'language', 'package',
'standby', 'script', 'longdesc', 'maxlength', 'cellpadding',
'throws', 'tabindex', 'color', 'colspan', 'accesskey', 'float',
'while', 'private', 'height', 'boolean', 'wrap', 'prompt', 'nowrap',
'size', 'rows', 'span', 'clip', 'bgcolor', 'top', 'long', 'start',
'scope', 'scheme', 'type', 'final', 'lang', 'visibility', 'else',
'assert', 'transient', 'link', 'catch', 'true', 'serializable',
'target', 'lowsrc', 'this', 'double', 'align', 'value', 'cite',
'headers', 'below', 'protected', 'declare', 'classid', 'defer',
'false', 'synchronized', 'int', 'abstract', 'accept', 'hreflang',
'char', 'border', 'id', 'native', 'rowspan', 'charset', 'archive',
'strictfp', 'readonly', 'axis', 'cellspacing', 'profile', 'multiple',
'object', 'action', 'pagex', 'pagey', 'marginheight', 'data',
'class', 'frameborder', 'enctype', 'implements', 'break', 'gutter',
'url', 'clear', 'face', 'switch', 'marginwidth', 'width', 'left']),
syntax_parse._KeywordsFromSyntaxListOutput(
ContentsOfTestFile( 'java_syntax' ) ) )
def KeywordsFromSyntaxListOutput_PhpSyntax_ContainsFunctions_test():
assert_that( syntax_parse._KeywordsFromSyntaxListOutput(
ContentsOfTestFile( 'php_syntax' ) ),
has_items( 'array_change_key_case' ) )
def KeywordsFromSyntaxListOutput_Basic_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
foogroup xxx foo bar
zoo goo
links to Statement"""
)
)
def KeywordsFromSyntaxListOutput_Function_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
foogroup xxx foo bar
zoo goo
links to Function"""
)
)
def KeywordsFromSyntaxListOutput_ContainedArgAllowed_test():
assert_that( syntax_parse._KeywordsFromSyntaxListOutput( """
phpFunctions xxx contained gzclose yaz_syntax html_entity_decode fbsql_read_blob png2wbmp mssql_init cpdf_set_title gztell fbsql_insert_id empty cpdf_restore mysql_field_type closelog swftext ldap_search curl_errno gmp_div_r mssql_data_seek getmyinode printer_draw_pie mcve_initconn ncurses_getmaxyx defined
contained replace_child has_attributes specified insertdocument assign node_name hwstat addshape get_attribute_node html_dump_mem userlist
links to Function""" ),
has_items( 'gzclose', 'userlist', 'ldap_search' ) )
def KeywordsFromSyntaxListOutput_JunkIgnored_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
--- Syntax items ---
foogroup xxx foo bar
zoo goo
links to Statement
Spell cluster=NONE
NoSpell cluster=NONE"""
)
)
def KeywordsFromSyntaxListOutput_MultipleStatementGroups_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
foogroup xxx foo bar
links to Statement
bargroup xxx zoo goo
links to Statement"""
)
)
def KeywordsFromSyntaxListOutput_StatementAndTypeGroups_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
foogroup xxx foo bar
links to Statement
bargroup xxx zoo goo
links to Type"""
)
)
def KeywordsFromSyntaxListOutput_StatementHierarchy_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo', 'qux', 'moo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
baa xxx foo bar
links to Foo
Foo xxx zoo goo
links to Bar
Bar xxx qux moo
links to Statement"""
)
)
def KeywordsFromSyntaxListOutput_TypeHierarchy_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo', 'qux', 'moo' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
baa xxx foo bar
links to Foo
Foo xxx zoo goo
links to Bar
Bar xxx qux moo
links to Type"""
)
)
def KeywordsFromSyntaxListOutput_StatementAndTypeHierarchy_test():
eq_( set([ 'foo', 'bar', 'zoo', 'goo', 'qux', 'moo', 'na', 'nb', 'nc' ]),
syntax_parse._KeywordsFromSyntaxListOutput( """
tBaa xxx foo bar
links to tFoo
tFoo xxx zoo goo
links to tBar
tBar xxx qux moo
links to Type
sBaa xxx na bar
links to sFoo
sFoo xxx zoo nb
links to sBar
sBar xxx qux nc
links to Statement"""
)
)
def SyntaxGroupsFromOutput_Basic_test():
groups = syntax_parse._SyntaxGroupsFromOutput(
"""foogroup xxx foo bar
zoo goo
links to Statement""" )
assert 'foogroup' in groups
def ExtractKeywordsFromGroup_Basic_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo bar',
'zoo goo',
] ) )
)
def ExtractKeywordsFromGroup_Commas_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo, bar,',
'zoo goo',
] ) )
)
def ExtractKeywordsFromGroup_WithLinksTo_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo bar',
'zoo goo',
'links to Statement'
] ) )
)
def ExtractKeywordsFromGroup_KeywordStarts_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo bar',
'transparent boo baa',
'zoo goo',
] ) )
)
def ExtractKeywordsFromGroup_KeywordMiddle_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo oneline bar',
'zoo goo',
] ) )
)
def ExtractKeywordsFromGroup_KeywordAssign_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo end=zoo((^^//)) bar',
'zoo goo',
] ) )
)
def ExtractKeywordsFromGroup_KeywordAssignAndMiddle_test():
eq_( ['foo', 'bar', 'zoo', 'goo' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'foo end=zoo((^^//)) transparent bar',
'zoo goo',
] ) )
)
def ExtractKeywordsFromGroup_ContainedSyntaxArgAllowed_test():
eq_( ['foo', 'zoq', 'bar', 'goo', 'far' ],
syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [
'contained foo zoq',
'contained bar goo',
'far',
] ) )
)

View file

@ -1,160 +0,0 @@
--- Syntax items ---
cCustomFunc xxx match /\w\+\s*\((\)\@=/
links to Function
cCustomClass xxx match /\w\+\s*\(::\)\@=/
links to Function
OperatorChars xxx match #?\|+\|-\|\*\|;\|:\|,\|<\|>\|&\||\|!\|\~\|%\|=\|)\|(\|{\|}\|\.\|\[\|\]\|/\(/\|*\)\@!#
cStatement xxx return goto asm continue break
links to Statement
cLabel xxx default case
links to Label
cConditional xxx if switch else
links to Conditional
cRepeat xxx for while do
links to Repeat
cTodo xxx contained XXX FIXME TODO
links to Todo
cBadContinuation xxx match /\\\s\+$/ contained
links to Error
cSpecial xxx match /\\\(x\x\+\|\o\{1,3}\|.\|$\)/ display contained
match /\\\(u\x\{4}\|U\x\{8}\)/ display contained
links to SpecialChar
cFormat xxx match /%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)/ display contained
match /%%/ display contained
links to cSpecial
cString xxx start=/L\="/ skip=/\\\\\|\\"/ end=/"/ extend contains=cSpecial,cFormat,@Spell
start=/\%(U\|u8\=\)"/ skip=/\\\\\|\\"/ end=/"/ extend contains=cSpecial,cFormat,@Spell
links to String
cCppString xxx start=/L\="/ skip=/\\\\\|\\"\|\\$/ end=/$/ end=/"/ excludenl contains=cSpecial,cFormat,@Spell
links to cString
cCharacter xxx match /L\='[^\\]'/
match /L'[^']*'/ contains=cSpecial
match /[Uu]'[^\\]'/
match /[Uu]'[^']*'/ contains=cSpecial
links to Character
cSpecialError xxx match /L\='\\[^'\"?\\abfnrtv]'/
match /[Uu]'\\[^'\"?\\abfnrtv]'/
links to cError
cSpecialCharacter xxx match /L\='\\['\"?\\abfnrtv]'/
match /L\='\\\o\{1,3}'/ display
match /'\\x\x\{1,2}'/ display
match /L'\\x\x\+'/ display
match /[Uu]'\\['\"?\\abfnrtv]'/
match /[Uu]'\\\o\{1,3}'/ display
match /[Uu]'\\x\x\+'/ display
links to cSpecial
cBadBlock xxx start=/{/ end=/}/ contained keepend transparent fold containedin=cParen,cBracket,cBadBlock
cErrInParen xxx match /[\]{}]\|<%\|%>/ display contained
links to cError
cCppParen xxx start=/(/ skip=/\\$/ end=/$/ end=/)/ contained excludenl transparent contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
cErrInBracket xxx match /[);{}]\|<%\|%>/ display contained
links to cError
cCppBracket xxx start=/\[\|<::\@!/ skip=/\\$/ end=/$/ end=/]\|:>/ contained excludenl transparent contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell
cBlock xxx start=/{/ end=/}/ transparent fold
cParenError xxx match /[\])]/ display
links to cError
cIncluded xxx start=/"/ skip=/\\\\\|\\"/ end=/"/ display contained
match /<[^>]*>/ display contained
links to cString
cCommentStartError xxx match +/\*+me=e-1 display contained
links to cError
cUserCont xxx match /^\s*\I\i*\s*:$/ display contains=@cLabelGroup
match /;\s*\I\i*\s*:$/ display contains=@cLabelGroup
match /^\s*\I\i*\s*:[^:]/me=e-1 display contains=@cLabelGroup
match /;\s*\I\i*\s*:[^:]/me=e-1 display contains=@cLabelGroup
cUserLabel xxx match /\I\i*/ display contained
links to Label
cBitField xxx match /^\s*\I\i*\s*:\s*[1-9]/me=e-1 display contains=cType
match /;\s*\I\i*\s*:\s*[1-9]/me=e-1 display contains=cType
cOctalZero xxx match /\<0/ display contained
links to PreProc
cNumber xxx match /\d\+\(u\=l\{0,2}\|ll\=u\)\>/ display contained
match /0x\x\+\(u\=l\{0,2}\|ll\=u\)\>/ display contained
links to Number
cFloat xxx match /\d\+f/ display contained
match /\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=/ display contained
match /\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>/ display contained
match /\d\+e[-+]\=\d\+[fl]\=\>/ display contained
match /0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>/ display contained
match /0x\x\+\.\=p[-+]\=\d\+[fl]\=\>/ display contained
links to Float
cOctal xxx match /0\o\+\(u\=l\{0,2}\|ll\=u\)\>/ display contained contains=cOctalZero
links to Number
cOctalError xxx match /0\o*[89]\d*/ display contained
links to cError
cNumbersCom xxx match /\<\d\|\.\d/ display contained transparent contains=cNumber,cFloat,cOctal
cParen xxx start=/(/ end=/}/me=s-1 end=/)/ transparent contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell
cBracket xxx start=/\[\|<::\@!/ end=/}/me=s-1 end=/]\|:>/ transparent contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell
cNumbers xxx match /\<\d\|\.\d/ display transparent contains=cNumber,cFloat,cOctalError,cOctal
cCommentL xxx start=+//+ skip=/\\$/ end=/$/ keepend contains=@cCommentGroup,cSpaceError,@Spell
links to cComment
cComment xxx matchgroup=cCommentStart start=+/\*+ end=+\*/+ extend fold contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell
links to Comment
cCommentError xxx match +\*/+ display
links to cError
cOperator xxx _Generic sizeof _Alignof _Static_assert alignof static_assert
links to Operator
cType xxx wchar_t uint8_t uint_fast32_t _Bool int_fast8_t float off_t _Complex uint_least32_t int_fast16_t int_fast32_t ptrdiff_t uintptr_t uint64_t uint_fast8_t int_least32_t long void wint_t complex uint_least8_t uint16_t uint_fast64_t imaginary int32_t unsigned char16_t FILE uint_least64_t int_least8_t va_list intptr_t int_fast64_t uint_fast16_t fpos_t size_t wctrans_t div_t jmp_buf uintmax_t mbstate_t int_least64_t _Imaginary uint_least16_t int8_t time_t DIR clock_t sig_atomic_t wctype_t int_least16_t ldiv_t bool ssize_t uint32_t double short char intmax_t int64_t char32_t int int16_t signed
links to Type
cStructure xxx struct union typedef enum
links to Structure
cStorageClass xxx inline const volatile alignas register thread_local _Noreturn static extern _Alignas _Atomic restrict noreturn _Thread_local auto
links to StorageClass
cConstant xxx stderr USHRT_MAX CHAR_BIT SIGINT SIGINT EINVAL LDBL_MIN_EXP INT_FAST32_MIN UINT_LEAST16_MAX LONG_MAX EROFS EXIT_FAILURE ENOTSUP SCHAR_MAX SEEK_END EINPROGRESS SLONG_MIN SIGSEGV SIGSEGV UINT_FAST8_MAX EINTR true ENOSYS INT32_MAX ULLONG_MAX SINT_MIN SIGALRM SHRT_MIN INT64_MAX WINT_MAX ENOTDIR INT_FAST16_MAX ESPIPE __FILE__ M_PI TMP_MAX MB_LEN_MAX SIGKILL DBL_MIN_10_EXP INT_LEAST8_MAX LC_COLLATE ENOSPC HUGE_VAL EIO INT8_MAX LC_MONETARY LDBL_MIN INT_LEAST16_MIN INT_FAST64_MIN INT_MAX EILSEQ FLT_MANT_DIG INT_FAST32_MAX __func__ FLT_MIN EOF false DBL_MIN_EXP ETIMEDOUT INT_FAST8_MIN M_LN10 FLT_EPSILON stdin INT_FAST64_MAX EISDIR ENOENT UINTMAX_MAX SIGSTOP UINT_LEAST32_MAX LDBL_MIN_10_EXP SLONG_MAX SIG_ATOMIC_MIN SIZE_MAX SIGTERM SIGTERM EPERM NULL FOPEN_MAX EMFILE UINT_LEAST64_MAX DBL_MAX SIGFPE SIGFPE INT_LEAST32_MIN SIGPIPE SINT_MAX SHRT_MAX __STDC_VERSION__ SIGQUIT UINT16_MAX SSHRT_MIN INT_LEAST64_MIN M_SQRT2 INTPTR_MAX EMSGSIZE DBL_MANT_DIG _IOFBF DBL_MAX_10_EXP stdout SIGUSR2 LC_ALL EMLINK SIGTTOU SIGHUP SIGHUP LDBL_MAX INT_LEAST16_MAX UINT32_MAX __DATE__ FLT_MAX FILENAME_MAX INT_FAST8_MAX BUFSIZ UINT64_MAX EBADMSG INT_MIN UCHAR_MAX LDBL_EPSILON FLT_MIN_10_EXP SIGABRT SIGABRT SIG_ATOMIC_MAX M_E LLONG_MIN UINT_FAST16_MAX ECHILD INT_LEAST32_MAX M_1_PI LDBL_DIG ENOLCK L_tmpnam ENOTTY FLT_DIG SSHRT_MAX INT_LEAST64_MAX EACCES WEOF __LINE__ UINT_LEAST8_MAX __TIME__ CHAR_MIN M_PI_2 _IONBF M_PI_4 __STDC__ UINT_FAST32_MAX FLT_ROUNDS SEEK_SET EBUSY INTMAX_MIN FLT_MAX_10_EXP LC_TIME CLOCKS_PER_SEC ENXIO ERANGE _IOLBF ENODEV EXDEV FLT_MIN_EXP EFAULT M_2_PI WCHAR_MIN LDBL_MAX_EXP DBL_EPSILON ULONG_MAX ENOMEM SIGTRAP UINT_MAX M_LOG2E LLONG_MAX LDBL_MAX_10_EXP SIG_IGN M_SQRT1_2 EDEADLK ENOTEMPTY LC_NUMERIC ENOEXEC INT16_MIN PTRDIFF_MIN ESRCH MB_CUR_MAX RAND_MAX M_LN2 ENFILE INTPTR_MIN EXIT_SUCCESS CHAR_MAX SIGILL SIGILL LONG_MIN INT_LEAST8_MIN SCHAR_MIN SIG_DFL SEEK_CUR SIGTTIN FLT_MAX_EXP EDOM INT32_MIN SIGUSR1 ECANCELED UINT8_MAX EEXIST LDBL_MANT_DIG EAGAIN INT64_MIN WINT_MIN INT_FAST16_MIN LC_CTYPE ENAMETOOLONG EBADF M_LOG10E E2BIG SIGCONT M_2_SQRTPI WCHAR_MAX DBL_MAX_EXP EPIPE SIGTSTP UINTPTR_MAX UINT_FAST64_MAX SIGCHLD INTMAX_MAX EFBIG SIG_ERR INT8_MIN INT16_MAX PTRDIFF_MAX FLT_RADIX DBL_MIN DBL_DIG
links to Constant
cPreCondit xxx start=/^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>/ skip=/\\$/ end=/$/ keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
links to PreCondit
cPreConditMatch xxx match /^\s*\(%:\|#\)\s*\(else\|endif\)\>/ display
links to cPreCondit
cCppInIf xxx matchgroup=cCppInWrapper start=/\d\+/ end=/^\s*\(%:\|#\)\s*endif\>/ contained contains=TOP,cPreCondit
cCppInElse xxx start==^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)= end=/.\@=\|$/ contained fold contains=cCppInElse2 containedin=cCppInIf
cCppInElse2 xxx matchgroup=cCppInWrapper start=+^\s*\(%:\|#\)\s*\(else\|elif\)\([^/]\|/[^/*]\)*+ end=/^\s*\(%:\|#\)\s*endif\>/me=s-1 contained contains=cSpaceError,cCppOutSkip
links to cCppOutIf2
cCppOutIf xxx start=/0\+/ matchgroup=cCppOutWrapper end=/^\s*\(%:\|#\)\s*endif\>/ contained contains=cCppOutIf2,cCppOutElse
cCppOutIf2 xxx matchgroup=cCppOutWrapper start=/0\+/ end==^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0\+\s*\($\|//\|/\*\|&\)\)\@!\|endif\>\)=me=s-1 contained fold contains=cSpaceError,cCppOutSkip
links to cCppOut2
cCppOutElse xxx matchgroup=cCppOutWrapper start=/^\s*\(%:\|#\)\s*\(else\|elif\)/ end=/^\s*\(%:\|#\)\s*endif\>/me=s-1 contained contains=TOP,cPreCondit
cCppInSkip xxx matchgroup=cCppInWrapper start==^\s*\(%:\|#\)\s*\(if\s\+\(\d\+\s*\($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)= skip=/\\$/ end=/^\s*\(%:\|#\)\s*endif\>/ contained contains=TOP,cPreProc containedin=cCppOutElse,cCppInIf,cCppInSkip
cCppOutSkip xxx start=/^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)/ skip=/\\$/ end=/^\s*\(%:\|#\)\s*endif\>/ contained contains=cSpaceError,cCppOutSkip
links to cCppOutIf2
cCppOutWrapper xxx start==^\s*\(%:\|#\)\s*if\s\+0\+\s*\($\|//\|/\*\|&\)= end=/.\@=\|$/ fold contains=cCppOutIf,cCppOutElse
links to cPreCondit
cCppInWrapper xxx start==^\s*\(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\($\|//\|/\*\||\)= end=/.\@=\|$/ fold contains=cCppInIf,cCppInElse
links to cCppOutWrapper
cPreProc xxx start=/^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)/ skip=/\\$/ end=/$/ keepend contains=ALLBUT,@cPreProcGroup,@Spell
links to PreProc
cInclude xxx match /^\s*\(%:\|#\)\s*include\>\s*["<]/ display contains=cIncluded
links to Include
cDefine xxx start=/^\s*\(%:\|#\)\s*\(define\|undef\)\>/ skip=/\\$/ end=/$/ keepend contains=ALLBUT,@cPreProcGroup,@Spell
links to Macro
cMulti xxx start=/?/ skip=/::/ end=/:/ transparent contains=ALLBUT,@cMultiGroup,@Spell
cppStatement xxx this delete using friend new
links to Statement
cppAccess xxx public protected private
links to cppStatement
cppType xxx wchar_t inline explicit virtual export bool
links to Type
cppExceptions xxx catch try throw
links to Exception
cppOperator xxx bitand or compl operator and_eq not_eq xor_eq bitor xor and or_eq not typeid
links to Operator
cppCast xxx match /\<\(const\|static\|dynamic\|reinterpret\)_cast\s*</me=e-1
match /\<\(const\|static\|dynamic\|reinterpret\)_cast\s*$/
links to cppStatement
cppStorageClass xxx mutable
links to StorageClass
cppStructure xxx class typename template namespace
links to Structure
cppNumber xxx NPOS
links to Number
cppBoolean xxx true false
links to Boolean
cppMinMax xxx match /[<>]?/
cCommentGroup cluster=cTodo,cBadContinuation
Spell cluster=NONE
cParenGroup cluster=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
cCppOutInGroup cluster=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
cPreProcGroup cluster=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti,cBadBlock
cMultiGroup cluster=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
cLabelGroup cluster=cUserLabel

View file

@ -1,231 +0,0 @@
--- Syntax items ---
htmlValue xxx match /=[\t ]*[^'" \t>][^ \t>]*/hs=s+1 contained contains=javaScriptExpression,@htmlPreproc
links to Normal
cCustomFunc xxx match /\w\+\s*\((\)\@=/
links to Function
cCustomClass xxx match /\w\+\s*\(::\)\@=/
links to Function
OperatorChars xxx match #?\|+\|-\|\*\|;\|:\|,\|<\|>\|&\||\|!\|\~\|%\|=\|)\|(\|{\|}\|\.\|\[\|\]\|/\(/\|*\)\@!#
javaFold xxx start=/{/ end=/}/ transparent fold
javaError xxx const goto
match /[\\@`]/
match +<<<\|\.\.\|=>\|||=\|&&=\|[^-]->\|\*\/+
links to Error
javaOK xxx match /\.\.\./
javaError2 xxx match /#\|=</
links to javaError
javaExternal xxx native package
match /\<import\>\(\s\+static\>\)\?/
links to Include
javaConditional xxx if else switch
links to Conditional
javaRepeat xxx do for while
links to Repeat
javaBoolean xxx true false
links to Boolean
javaConstant xxx null
links to Constant
javaTypedef xxx this super
match /\.\s*\<class\>/ms=s+1
links to Typedef
javaOperator xxx new instanceof
links to Operator
javaType xxx float boolean long void double short char byte int
links to Type
javaStatement xxx return
links to Statement
javaStorageClass xxx transient strictfp serializable synchronized static final volatile
links to StorageClass
javaExceptions xxx finally catch try throw
links to Exception
javaAssert xxx assert
links to Statement
javaMethodDecl xxx synchronized throws
links to javaStorageClass
javaClassDecl xxx interface implements enum extends
match /^class\>/
match /[^.]\s*\<class\>/ms=s+1
match /@interface\>/
links to javaStorageClass
javaAnnotation xxx match /@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>/
links to PreProc
javaBranch xxx nextgroup=javaUserLabelRef skipwhite continue
nextgroup=javaUserLabelRef skipwhite break
links to Conditional
javaUserLabelRef xxx match /\k\+/ contained
links to javaUserLabel
javaVarArg xxx match /\.\.\./
links to Function
javaScopeDecl xxx protected public private abstract
links to javaStorageClass
javaLabel xxx default
links to Label
javaNumber xxx match /\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>/
match /\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\=/
match /\<\d\+[eE][-+]\=\d\+[fFdD]\=\>/
match /\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>/
links to Number
javaCharacter xxx match /'[^']*'/ contains=javaSpecialChar,javaSpecialCharError
match /'\\''/ contains=javaSpecialChar
match /'[^\\]'/
links to Character
javaLabelRegion xxx matchgroup=javaLabel start=/\<case\>/ matchgroup=NONE end=/:/ transparent contains=javaNumber,javaCharacter
javaUserLabel xxx match /^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:/he=e-1 contains=javaLabel
links to Label
javaTodo xxx contained TODO XXX FIXME
links to Todo
javaSpecial xxx match /\\u\d\{4\}/
links to Special
javaCommentStar xxx match +^\s*\*[^/]+me=e-1 contained
match /^\s*\*$/ contained
links to javaComment
javaSpecialChar xxx match /\\\([4-9]\d\|[0-3]\d\d\|[\"\\'ntbrf]\|u\x\{4\}\)/ contained
links to SpecialChar
javaComment xxx start=+/\*+ end=+\*/+ contains=@javaCommentSpecial,javaTodo,@Spell
match +/\*\*/+
links to Comment
javaLineComment xxx match +//.*+ contains=@javaCommentSpecial2,javaTodo,@Spell
links to Comment
javaString xxx start=/"/ end=/$/ end=/"/ contains=javaSpecialChar,javaSpecialError,@Spell
links to String
htmlError xxx match /[<>&]/ contained
links to Error
htmlSpecialChar xxx match /&#\=[0-9A-Za-z]\{1,8};/ contained
links to Special
htmlString xxx start=/"/ end=/"/ contained contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc
start=/'/ end=/'/ contained contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc
links to String
htmlTagN xxx match /<\s*[-a-zA-Z0-9]\+/hs=s+1 contained contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
match =</\s*[-a-zA-Z0-9]\+=hs=s+2 contained contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
htmlTagError xxx match /[^>]</ms=s+1 contained
links to htmlError
htmlEndTag xxx start=+</+ end=/>/ contained contains=htmlTagN,htmlTagError
links to Identifier
htmlArg xxx contained below color name gutter span classid alt marginheight target rows bgcolor ismap cellspacing object codetype frame noshade data for bordercolor clip rowspan defer cellpadding shape usemap rules multiple start selected language summary hspace lowsrc type valign hreflang noresize scheme
contained class visibility checked pagex pagey headers scrolling clear charset id id declare codebase tabindex standby version link accept coords alink background vspace wrap profile width compact marginwidth above content border top maxlength prompt dir value charoff height longdesc nowrap
contained accesskey cols cite rel rev style method size src axis vlink valuetype colspan nohref face lang frameborder enctype readonly action left text url char align scope code disabled abbr datetime archive
match /\<\(http-equiv\|href\|title\)=/me=e-1 contained
match /\<z-index\>/ contained
match /\<\(accept-charset\|label\)\>/ contained
links to Type
htmlTag xxx start=+<[^/]+ end=/>/ contained fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
links to Function
htmlTagName xxx contained marquee span ol thead pre blink tbody a p q s object legend frame acronym noframes blockquote var table input hr button bdo font caption sub del sup col basefont xmp iframe dfn html meta nobr fieldset optgroup option applet link area map li td th tr tt param center address small frameset
contained label ul dir div kbd cite big layer form textarea base tfoot br strike samp select menu colgroup img nolayer spacer ilayer code abbr isindex dd ins dl dt noscript
match /\<\(b\|i\|u\|h[1-6]\|em\|strong\|head\|body\|title\)\>/ contained
links to htmlStatement
htmlSpecialTagName xxx contained script style
links to Exception
htmlCommentPart xxx start=/--/ end=/--\s*/ contained contains=@htmlPreproc,@Spell
links to Comment
htmlCommentError xxx match /[^><!]/ contained
links to htmlError
htmlComment xxx start=/<!/ end=/>/ contained contains=htmlCommentPart,htmlCommentError,@Spell
start=/<!DOCTYPE/ end=/>/ contained keepend
links to Comment
htmlPreStmt xxx match /<!--#\(config\|echo\|exec\|fsize\|flastmod\|include\|printenv\|set\|if\|elif\|else\|endif\|geoguide\)\>/ contained
links to PreProc
htmlPreError xxx match /<!--#\S*/ms=s+4 contained
links to Error
htmlPreAttr xxx match /\w\+=[^"]\S\+/ contained contains=htmlPreProcAttrError,htmlPreProcAttrName
start=/\w\+="/ skip=/\\\\\|\\"/ end=/"/ contained keepend contains=htmlPreProcAttrName
links to String
htmlPreProc xxx start=/<!--#/ end=/-->/ contained contains=htmlPreStmt,htmlPreError,htmlPreAttr
links to PreProc
htmlPreProcAttrError xxx match /\w\+=/he=e-1 contained
links to Error
htmlPreProcAttrName xxx match /\(expr\|errmsg\|sizefmt\|timefmt\|var\|cgi\|cmd\|file\|virtual\|value\)=/he=e-1 contained
links to PreProc
htmlLink xxx start=/<a\>\_[^>]*\<href\>/ end=+</a>+me=e-4 contained contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLeadingSpace,javaScript,@htmlPreproc
links to Underlined
htmlBoldUnderline xxx start=/<u\>/ end=+</u>+me=e-4 contained contains=@htmlTop,htmlBoldUnderlineItalic
htmlBoldItalic xxx start=/<i\>/ end=+</i>+me=e-4 contained contains=@htmlTop,htmlBoldItalicUnderline
start=/<em\>/ end=+</em>+me=e-5 contained contains=@htmlTop,htmlBoldItalicUnderline
htmlBold xxx start=/<b\>/ end=+</b>+me=e-4 contained contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
start=/<strong\>/ end=+</strong>+me=e-9 contained contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
htmlBoldUnderlineItalic xxx start=/<i\>/ end=+</i>+me=e-4 contained contains=@htmlTop
start=/<em\>/ end=+</em>+me=e-5 contained contains=@htmlTop
htmlBoldItalicUnderline xxx start=/<u\>/ end=+</u>+me=e-4 contained contains=@htmlTop,htmlBoldUnderlineItalic
links to htmlBoldUnderlineItalic
htmlUnderlineBold xxx start=/<b\>/ end=+</b>+me=e-4 contained contains=@htmlTop,htmlUnderlineBoldItalic
start=/<strong\>/ end=+</strong>+me=e-9 contained contains=@htmlTop,htmlUnderlineBoldItalic
links to htmlBoldUnderline
htmlUnderlineItalic xxx start=/<i\>/ end=+</i>+me=e-4 contained contains=@htmlTop,htmlUnderlineItalicBold
start=/<em\>/ end=+</em>+me=e-5 contained contains=@htmlTop,htmlUnderlineItalicBold
htmlUnderline xxx start=/<u\>/ end=+</u>+me=e-4 contained contains=@htmlTop,htmlUnderlineBold,htmlUnderlineItalic
htmlUnderlineBoldItalic xxx start=/<i\>/ end=+</i>+me=e-4 contained contains=@htmlTop
start=/<em\>/ end=+</em>+me=e-5 contained contains=@htmlTop
links to htmlBoldUnderlineItalic
htmlUnderlineItalicBold xxx start=/<b\>/ end=+</b>+me=e-4 contained contains=@htmlTop
start=/<strong\>/ end=+</strong>+me=e-9 contained contains=@htmlTop
links to htmlBoldUnderlineItalic
htmlItalicBold xxx start=/<b\>/ end=+</b>+me=e-4 contained contains=@htmlTop,htmlItalicBoldUnderline
start=/<strong\>/ end=+</strong>+me=e-9 contained contains=@htmlTop,htmlItalicBoldUnderline
links to htmlBoldItalic
htmlItalicUnderline xxx start=/<u\>/ end=+</u>+me=e-4 contained contains=@htmlTop,htmlItalicUnderlineBold
links to htmlUnderlineItalic
htmlItalic xxx start=/<i\>/ end=+</i>+me=e-4 contained contains=@htmlTop,htmlItalicBold,htmlItalicUnderline
start=/<em\>/ end=+</em>+me=e-5 contained contains=@htmlTop
htmlItalicBoldUnderline xxx start=/<u\>/ end=+</u>+me=e-4 contained contains=@htmlTop
links to htmlBoldUnderlineItalic
htmlItalicUnderlineBold xxx start=/<b\>/ end=+</b>+me=e-4 contained contains=@htmlTop
start=/<strong\>/ end=+</strong>+me=e-9 contained contains=@htmlTop
links to htmlBoldUnderlineItalic
htmlLeadingSpace xxx match /^\s\+/ contained
links to None
htmlH1 xxx start=/<h1\>/ end=+</h1>+me=e-5 contained contains=@htmlTop
links to Title
htmlH2 xxx start=/<h2\>/ end=+</h2>+me=e-5 contained contains=@htmlTop
links to htmlH1
htmlH3 xxx start=/<h3\>/ end=+</h3>+me=e-5 contained contains=@htmlTop
links to htmlH2
htmlH4 xxx start=/<h4\>/ end=+</h4>+me=e-5 contained contains=@htmlTop
links to htmlH3
htmlH5 xxx start=/<h5\>/ end=+</h5>+me=e-5 contained contains=@htmlTop
links to htmlH4
htmlH6 xxx start=/<h6\>/ end=+</h6>+me=e-5 contained contains=@htmlTop
links to htmlH5
htmlTitle xxx start=/<title\>/ end=+</title>+me=e-8 contained contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,javaScript,@htmlPreproc
links to Title
htmlHead xxx start=/<head\>/ end=/<h[1-6]\>/me=e-3 end=/<body\>/me=e-5 end=+</head>+me=e-7 contained contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,htmlTitle,javaScript,cssStyle,@htmlPreproc
links to PreProc
javaCommentTitle xxx matchgroup=javaDocComment start=+/\*\*+ matchgroup=javaCommentTitle end=+\*/+me=s-1,he=s-1 end=/[^{]@/me=s-2,he=s-1 end=/\.[ \t\r<&]/me=e-1 end=/\.$/ contained keepend contains=@javaHtml,javaCommentStar,javaTodo,@Spell,javaDocTags,javaDocSeeTag
links to SpecialComment
javaDocTags xxx start=/{@\(code\|link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)/ end=/}/ contained
match /@\(param\|exception\|throws\|since\)\s\+\S\+/ contained contains=javaDocParam
match /@\(version\|author\|return\|deprecated\|serial\|serialField\|serialData\)\>/ contained
links to Special
javaDocSeeTag xxx matchgroup=javaDocTags start=/@see\s\+/ matchgroup=NONE end=/\_./re=e-1 contained contains=javaDocSeeTagParam
javaDocComment xxx start=+/\*\*+ end=+\*/+ keepend contains=javaCommentTitle,@javaHtml,javaDocTags,javaDocSeeTag,javaTodo,@Spell
links to Comment
javaDocParam xxx match /\s\S\+/ contained
links to Function
javaDocSeeTagParam xxx match @"\_[^"]\+"\|<a\s\+\_.\{-}</a>\|\(\k\|\.\)*\(#\k\+\((\_[^)]\+)\)\=\)\=@ contained extend
links to Function
javaSpecialError xxx match /\\./ contained
links to Error
javaSpecialCharError xxx match /[^']/ contained
links to Error
javaParenT1 xxx matchgroup=javaParen1 start=/(/ end=/)/ contained transparent contains=@javaTop,javaParenT2
matchgroup=javaParen1 start=/\[/ end=/\]/ contained transparent contains=@javaTop,javaParenT2
javaParenT xxx matchgroup=javaParen start=/(/ end=/)/ transparent contains=@javaTop,javaParenT1
matchgroup=javaParen start=/\[/ end=/\]/ transparent contains=@javaTop,javaParenT1
javaParenT2 xxx matchgroup=javaParen2 start=/(/ end=/)/ contained transparent contains=@javaTop,javaParenT
matchgroup=javaParen2 start=/\[/ end=/\]/ contained transparent contains=@javaTop,javaParenT
javaParenError xxx match /)/
match /\]/
links to javaError
javaTop cluster=javaError,javaError,javaError,javaError2,javaExternal,javaConditional,javaRepeat,javaBoolean,javaConstant,javaTypedef,javaOperator,javaType,javaType,javaStatement,javaStorageClass,javaExceptions,javaAssert,javaMethodDecl,javaClassDecl,javaClassDecl,javaClassDecl,javaAnnotation,javaBranch,javaVarArg,javaScopeDecl,javaLangObject,javaLabel,javaNumber,javaCharacter,javaLabelRegion,javaUserLabel,javaSpecial,javaComment,javaLineComment,javaString,javaStringError
Spell cluster=NONE
javaCommentSpecial cluster=NONE
javaCommentSpecial2 cluster=NONE
javaHtml cluster=htmlError,htmlSpecialChar,htmlEndTag,htmlTag,htmlComment,htmlPreProc,htmlLink,htmlBold,htmlUnderline,htmlItalic,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,htmlTitle,htmlHead
htmlPreproc cluster=NONE
htmlArgCluster cluster=NONE
htmlTagNameCluster cluster=NONE
htmlTop cluster=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,javaScript,@htmlPreproc
htmlJavaScript cluster=@htmlPreproc
htmlVbScript cluster=NONE
htmlCss cluster=NONE
javaClasses cluster=NONE

File diff suppressed because it is too large Load diff

View file

@ -1,63 +0,0 @@
--- Syntax items ---
cCustomFunc xxx match /\w\+\s*\((\)\@=/
links to Function
cCustomClass xxx match /\w\+\s*\(::\)\@=/
links to Function
pythonStatement xxx return True lambda
nextgroup=pythonFunction skipwhite def
del
nextgroup=pythonFunction skipwhite class
global nonlocal as None, False, yield with print continue break pass assert exec
links to Statement
pythonFunction xxx match /\%(\%(def\s\|class\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*/ contained
links to Function
pythonConditional xxx if else elif
links to Conditional
pythonRepeat xxx for while
links to Repeat
pythonOperator xxx or is and in not
links to Operator
pythonException xxx finally raise except try
links to Exception
pythonInclude xxx from import
links to Include
pythonDecorator xxx match /@/ display nextgroup=pythonFunction skipwhite
links to Define
pythonTodo xxx contained NOTE XXX TODO NOTES FIXME
links to Todo
pythonComment xxx match /#.*$/ contains=pythonTodo,@Spell
links to Comment
pythonEscape xxx match /\\[abfnrtv'"\\]/ contained
match /\\\o\{1,3}/ contained
match /\\x\x\{2}/ contained
match /\%(\\u\x\{4}\|\\U\x\{8}\)/ contained
match /\\N{\a\+\%(\s\a\+\)*}/ contained
match /\\$/
links to Special
pythonString xxx start=/[uU]\=\z(['"]\)/ skip=/\\\\\|\\\z1/ end=/\z1/ contains=pythonEscape,@Spell
start=/[uU]\=\z('''\|"""\)/ end=/\z1/ keepend contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
links to String
pythonDoctest xxx start=/^\s*>>>\s/ end=/^\s*$/ contained contains=ALLBUT,pythonDoctest,@Spell
links to Special
pythonRawString xxx start=/[uU]\=[rR]\z(['"]\)/ skip=/\\\\\|\\\z1/ end=/\z1/ contains=@Spell
start=/[uU]\=[rR]\z('''\|"""\)/ end=/\z1/ keepend contains=pythonSpaceError,pythonDoctest,@Spell
links to String
pythonNumber xxx match /\<0[oO]\=\o\+[Ll]\=\>/
match /\<0[xX]\x\+[Ll]\=\>/
match /\<0[bB][01]\+[Ll]\=\>/
match /\<\%([1-9]\d*\|0\)[Ll]\=\>/
match /\<\d\+[jJ]\>/
match /\<\d\+[eE][+-]\=\d\+[jJ]\=\>/
match /\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@=/
match /\%(^\|\W\)\@<=\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>/
links to Number
pythonBuiltin xxx list locals all classmethod None abs cmp reduce ord hex object memoryview enumerate __debug__ compile str False True issubclass input hasattr frozenset slice callable sum filter range any long execfile min type sorted reload super complex xrange file ascii setattr unicode staticmethod basestring unichr float iter map globals max isinstance dict chr reversed buffer delattr __import__ oct dir eval raw_input hash getattr tuple id bin vars apply bytes repr pow print zip open NotImplemented intern round format bool help property coerce Ellipsis len int next exec set bytearray divmod
links to Function
pythonExceptions xxx OSError EnvironmentError UserWarning NameError ArithmeticError NotImplementedError ReferenceError BaseException LookupError ImportWarning OverflowError SystemExit IndentationError GeneratorExit Warning RuntimeError MemoryError WindowsError AssertionError UnicodeWarning KeyError TypeError TabError ImportError SyntaxWarning SyntaxError UnboundLocalError KeyboardInterrupt UnicodeDecodeError IOError Exception FutureWarning AttributeError UnicodeTranslateError VMSError EOFError FloatingPointError ValueError IndexError RuntimeWarning DeprecationWarning PendingDeprecationWarning UnicodeEncodeError StopIteration UnicodeError BytesWarning StandardError SystemError ZeroDivisionError BufferError
links to Structure
pythonDoctestValue xxx start=/^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\+/ end=/$/ contained
links to Define
OperatorChars xxx match #?\|+\|-\|\*\|;\|:\|,\|<\|>\|&\||\|!\|\~\|%\|=\|)\|(\|{\|}\|\.\|\[\|\]\|/\(/\|*\)\@!#
Spell cluster=NONE
NoSpell cluster=NONE

View file

@ -1,119 +0,0 @@
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
#
# Copyright (C) 2013 Google Inc.
# Changes to this file are licensed under the same terms as the original file
# (the Python Software Foundation License).
from __future__ import with_statement
import threading
import weakref
import sys
from concurrent.futures import _base
try:
import queue
except ImportError:
import Queue as queue
# This file provides an UnsafeThreadPoolExecutor, which operates exactly like
# the upstream Python version of ThreadPoolExecutor with one exception: it
# doesn't wait for worker threads to finish before shutting down the Python
# interpreter.
#
# This is dangerous for many workloads, but fine for some (like when threads
# only send network requests). The YCM workload is one of those workloads where
# it's safe (the aforementioned network requests case).
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):
self.future = future
self.fn = fn
self.args = args
self.kwargs = kwargs
def run(self):
if not self.future.set_running_or_notify_cancel():
return
try:
result = self.fn(*self.args, **self.kwargs)
except BaseException:
e = sys.exc_info()[1]
self.future.set_exception(e)
else:
self.future.set_result(result)
def _worker(executor_reference, work_queue):
try:
while True:
work_item = work_queue.get(block=True)
if work_item is not None:
work_item.run()
continue
executor = executor_reference()
# Exit if:
# - The executor that owns the worker has been collected OR
# - The executor that owns the worker has been shutdown.
if executor is None or executor._shutdown:
# Notice other workers
work_queue.put(None)
return
del executor
except BaseException:
_base.LOGGER.critical('Exception in worker', exc_info=True)
class UnsafeThreadPoolExecutor(_base.Executor):
def __init__(self, max_workers):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
"""
self._max_workers = max_workers
self._work_queue = queue.Queue()
self._threads = set()
self._shutdown = False
self._shutdown_lock = threading.Lock()
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
if self._shutdown:
raise RuntimeError('cannot schedule new futures after shutdown')
f = _base.Future()
w = _WorkItem(f, fn, args, kwargs)
self._work_queue.put(w)
self._adjust_thread_count()
return f
submit.__doc__ = _base.Executor.submit.__doc__
def _adjust_thread_count(self):
# When the executor gets lost, the weakref callback will wake up
# the worker threads.
def weakref_cb(_, q=self._work_queue):
q.put(None)
# TODO(bquinlan): Should avoid creating new threads if there are more
# idle threads than items in the work queue.
if len(self._threads) < self._max_workers:
t = threading.Thread(target=_worker,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
t.daemon = True
t.start()
self._threads.add(t)
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown = True
self._work_queue.put(None)
if wait:
for t in self._threads:
t.join()
shutdown.__doc__ = _base.Executor.shutdown.__doc__

View file

@ -1,426 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2011, 2012 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import vim
import os
import tempfile
import json
from ycmd.utils import ToUtf8IfNeeded
from ycmd import user_options_store
BUFFER_COMMAND_MAP = { 'same-buffer' : 'edit',
'horizontal-split' : 'split',
'vertical-split' : 'vsplit',
'new-tab' : 'tabedit' }
def CurrentLineAndColumn():
"""Returns the 0-based current line and 0-based current column."""
# See the comment in CurrentColumn about the calculation for the line and
# column number
line, column = vim.current.window.cursor
line -= 1
return line, column
def CurrentColumn():
"""Returns the 0-based current column. Do NOT access the CurrentColumn in
vim.current.line. It doesn't exist yet when the cursor is at the end of the
line. Only the chars before the current column exist in vim.current.line."""
# vim's columns are 1-based while vim.current.line columns are 0-based
# ... but vim.current.window.cursor (which returns a (line, column) tuple)
# columns are 0-based, while the line from that same tuple is 1-based.
# vim.buffers buffer objects OTOH have 0-based lines and columns.
# Pigs have wings and I'm a loopy purple duck. Everything makes sense now.
return vim.current.window.cursor[ 1 ]
def CurrentLineContents():
return vim.current.line
def TextAfterCursor():
"""Returns the text after CurrentColumn."""
return vim.current.line[ CurrentColumn(): ]
# Expects version_string in 'MAJOR.MINOR.PATCH' format, e.g. '7.4.301'
def VimVersionAtLeast( version_string ):
major, minor, patch = [ int( x ) for x in version_string.split( '.' ) ]
# For Vim 7.4.301, v:version is '704'
actual_major_and_minor = GetIntValue( 'v:version' )
if actual_major_and_minor != major * 100 + minor:
return False
return GetBoolValue( 'has("patch{0}")'.format( patch ) )
# Note the difference between buffer OPTIONS and VARIABLES; the two are not
# the same.
def GetBufferOption( buffer_object, option ):
# NOTE: We used to check for the 'options' property on the buffer_object which
# is available in recent versions of Vim and would then use:
#
# buffer_object.options[ option ]
#
# to read the value, BUT this caused annoying flickering when the
# buffer_object was a hidden buffer (with option = 'ft'). This was all due to
# a Vim bug. Until this is fixed, we won't use it.
to_eval = 'getbufvar({0}, "&{1}")'.format( buffer_object.number, option )
return GetVariableValue( to_eval )
def BufferModified( buffer_object ):
return bool( int( GetBufferOption( buffer_object, 'mod' ) ) )
def GetUnsavedAndCurrentBufferData():
buffers_data = {}
for buffer_object in vim.buffers:
if not ( BufferModified( buffer_object ) or
buffer_object == vim.current.buffer ):
continue
buffers_data[ GetBufferFilepath( buffer_object ) ] = {
'contents': '\n'.join( buffer_object ),
'filetypes': FiletypesForBuffer( buffer_object )
}
return buffers_data
def GetBufferNumberForFilename( filename, open_file_if_needed = True ):
return GetIntValue( u"bufnr('{0}', {1})".format(
EscapeForVim( os.path.realpath( filename ) ),
int( open_file_if_needed ) ) )
def GetCurrentBufferFilepath():
return GetBufferFilepath( vim.current.buffer )
def BufferIsVisible( buffer_number ):
if buffer_number < 0:
return False
window_number = GetIntValue( "bufwinnr({0})".format( buffer_number ) )
return window_number != -1
def GetBufferFilepath( buffer_object ):
if buffer_object.name:
return buffer_object.name
# Buffers that have just been created by a command like :enew don't have any
# buffer name so we use the buffer number for that. Also, os.getcwd() throws
# an exception when the CWD has been deleted so we handle that.
try:
folder_path = os.getcwd()
except OSError:
folder_path = tempfile.gettempdir()
return os.path.join( folder_path, str( buffer_object.number ) )
def UnplaceSignInBuffer( buffer_number, sign_id ):
if buffer_number < 0:
return
vim.command(
'try | exec "sign unplace {0} buffer={1}" | catch /E158/ | endtry'.format(
sign_id, buffer_number ) )
def PlaceSign( sign_id, line_num, buffer_num, is_error = True ):
# libclang can give us diagnostics that point "outside" the file; Vim borks
# on these.
if line_num < 1:
line_num = 1
sign_name = 'YcmError' if is_error else 'YcmWarning'
vim.command( 'sign place {0} line={1} name={2} buffer={3}'.format(
sign_id, line_num, sign_name, buffer_num ) )
def PlaceDummySign( sign_id, buffer_num, line_num ):
if buffer_num < 0 or line_num < 0:
return
vim.command( 'sign define ycm_dummy_sign' )
vim.command(
'sign place {0} name=ycm_dummy_sign line={1} buffer={2}'.format(
sign_id,
line_num,
buffer_num,
)
)
def UnPlaceDummySign( sign_id, buffer_num ):
if buffer_num < 0:
return
vim.command( 'sign undefine ycm_dummy_sign' )
vim.command( 'sign unplace {0} buffer={1}'.format( sign_id, buffer_num ) )
def ClearYcmSyntaxMatches():
matches = VimExpressionToPythonType( 'getmatches()' )
for match in matches:
if match[ 'group' ].startswith( 'Ycm' ):
vim.eval( 'matchdelete({0})'.format( match[ 'id' ] ) )
# Returns the ID of the newly added match
# Both line and column numbers are 1-based
def AddDiagnosticSyntaxMatch( line_num,
column_num,
line_end_num = None,
column_end_num = None,
is_error = True ):
group = 'YcmErrorSection' if is_error else 'YcmWarningSection'
if not line_end_num:
line_end_num = line_num
line_num, column_num = LineAndColumnNumbersClamped( line_num, column_num )
line_end_num, column_end_num = LineAndColumnNumbersClamped( line_end_num,
column_end_num )
if not column_end_num:
return GetIntValue(
"matchadd('{0}', '\%{1}l\%{2}c')".format( group, line_num, column_num ) )
else:
return GetIntValue(
"matchadd('{0}', '\%{1}l\%{2}c\_.\\{{-}}\%{3}l\%{4}c')".format(
group, line_num, column_num, line_end_num, column_end_num ) )
# Clamps the line and column numbers so that they are not past the contents of
# the buffer. Numbers are 1-based.
def LineAndColumnNumbersClamped( line_num, column_num ):
new_line_num = line_num
new_column_num = column_num
max_line = len( vim.current.buffer )
if line_num and line_num > max_line:
new_line_num = max_line
max_column = len( vim.current.buffer[ new_line_num - 1 ] )
if column_num and column_num > max_column:
new_column_num = max_column
return new_line_num, new_column_num
def SetLocationList( diagnostics ):
"""Diagnostics should be in qflist format; see ":h setqflist" for details."""
vim.eval( 'setloclist( 0, {0} )'.format( json.dumps( diagnostics ) ) )
def ConvertDiagnosticsToQfList( diagnostics ):
def ConvertDiagnosticToQfFormat( diagnostic ):
# see :h getqflist for a description of the dictionary fields
# Note that, as usual, Vim is completely inconsistent about whether
# line/column numbers are 1 or 0 based in its various APIs. Here, it wants
# them to be 1-based.
location = diagnostic[ 'location' ]
line_num = location[ 'line_num' ]
# libclang can give us diagnostics that point "outside" the file; Vim borks
# on these.
if line_num < 1:
line_num = 1
return {
'bufnr' : GetBufferNumberForFilename( location[ 'filepath' ] ),
'lnum' : line_num,
'col' : location[ 'column_num' ],
'text' : ToUtf8IfNeeded( diagnostic[ 'text' ] ),
'type' : diagnostic[ 'kind' ][ 0 ],
'valid' : 1
}
return [ ConvertDiagnosticToQfFormat( x ) for x in diagnostics ]
# Given a dict like {'a': 1}, loads it into Vim as if you ran 'let g:a = 1'
# When |overwrite| is True, overwrites the existing value in Vim.
def LoadDictIntoVimGlobals( new_globals, overwrite = True ):
extend_option = '"force"' if overwrite else '"keep"'
# We need to use json.dumps because that won't use the 'u' prefix on strings
# which Vim would bork on.
vim.eval( 'extend( g:, {0}, {1})'.format( json.dumps( new_globals ),
extend_option ) )
# Changing the returned dict will NOT change the value in Vim.
def GetReadOnlyVimGlobals( force_python_objects = False ):
if force_python_objects:
return vim.eval( 'g:' )
try:
# vim.vars is fairly new so it might not exist
return vim.vars
except:
return vim.eval( 'g:' )
def VimExpressionToPythonType( vim_expression ):
result = vim.eval( vim_expression )
if not isinstance( result, basestring ):
return result
try:
return int( result )
except ValueError:
return result
def HiddenEnabled( buffer_object ):
return bool( int( GetBufferOption( buffer_object, 'hid' ) ) )
def BufferIsUsable( buffer_object ):
return not BufferModified( buffer_object ) or HiddenEnabled( buffer_object )
def EscapedFilepath( filepath ):
return filepath.replace( ' ' , r'\ ' )
# Both |line| and |column| need to be 1-based
def JumpToLocation( filename, line, column ):
# Add an entry to the jumplist
vim.command( "normal! m'" )
if filename != GetCurrentBufferFilepath():
# We prefix the command with 'keepjumps' so that opening the file is not
# recorded in the jumplist. So when we open the file and move the cursor to
# a location in it, the user can use CTRL-O to jump back to the original
# location, not to the start of the newly opened file.
# Sadly this fails on random occasions and the undesired jump remains in the
# jumplist.
user_command = user_options_store.Value( 'goto_buffer_command' )
command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
if command == 'edit' and not BufferIsUsable( vim.current.buffer ):
command = 'split'
vim.command( 'keepjumps {0} {1}'.format( command,
EscapedFilepath( filename ) ) )
vim.current.window.cursor = ( line, column - 1 )
# Center the screen on the jumped-to location
vim.command( 'normal! zz' )
def NumLinesInBuffer( buffer_object ):
# This is actually less than obvious, that's why it's wrapped in a function
return len( buffer_object )
# Calling this function from the non-GUI thread will sometimes crash Vim. At the
# time of writing, YCM only uses the GUI thread inside Vim (this used to not be
# the case).
def PostVimMessage( message ):
vim.command( "echohl WarningMsg | echom '{0}' | echohl None"
.format( EscapeForVim( str( message ) ) ) )
# Unlike PostVimMesasge, this supports messages with newlines in them because it
# uses 'echo' instead of 'echomsg'. This also means that the message will NOT
# appear in Vim's message log.
def PostMultiLineNotice( message ):
vim.command( "echohl WarningMsg | echo '{0}' | echohl None"
.format( EscapeForVim( str( message ) ) ) )
def PresentDialog( message, choices, default_choice_index = 0 ):
"""Presents the user with a dialog where a choice can be made.
This will be a dialog for gvim users or a question in the message buffer
for vim users or if `set guioptions+=c` was used.
choices is list of alternatives.
default_choice_index is the 0-based index of the default element
that will get choosen if the user hits <CR>. Use -1 for no default.
PresentDialog will return a 0-based index into the list
or -1 if the dialog was dismissed by using <Esc>, Ctrl-C, etc.
See also:
:help confirm() in vim (Note that vim uses 1-based indexes)
Example call:
PresentDialog("Is this a nice example?", ["Yes", "No", "May&be"])
Is this a nice example?
[Y]es, (N)o, May(b)e:"""
to_eval = "confirm('{0}', '{1}', {2})".format( EscapeForVim( message ),
EscapeForVim( "\n" .join( choices ) ), default_choice_index + 1 )
return int( vim.eval( to_eval ) ) - 1
def Confirm( message ):
return bool( PresentDialog( message, [ "Ok", "Cancel" ] ) == 0 )
def EchoText( text, log_as_message = True ):
def EchoLine( text ):
command = 'echom' if log_as_message else 'echo'
vim.command( "{0} '{1}'".format( command, EscapeForVim( text ) ) )
for line in str( text ).split( '\n' ):
EchoLine( line )
# Echos text but truncates it so that it all fits on one line
def EchoTextVimWidth( text ):
vim_width = GetIntValue( '&columns' )
truncated_text = ToUtf8IfNeeded( text )[ : int( vim_width * 0.9 ) ]
truncated_text.replace( '\n', ' ' )
old_ruler = GetIntValue( '&ruler' )
old_showcmd = GetIntValue( '&showcmd' )
vim.command( 'set noruler noshowcmd' )
EchoText( truncated_text, False )
vim.command( 'let &ruler = {0}'.format( old_ruler ) )
vim.command( 'let &showcmd = {0}'.format( old_showcmd ) )
def EscapeForVim( text ):
return text.replace( "'", "''" )
def CurrentFiletypes():
return vim.eval( "&filetype" ).split( '.' )
def FiletypesForBuffer( buffer_object ):
# NOTE: Getting &ft for other buffers only works when the buffer has been
# visited by the user at least once, which is true for modified buffers
return GetBufferOption( buffer_object, 'ft' ).split( '.' )
def GetVariableValue( variable ):
return vim.eval( variable )
def GetBoolValue( variable ):
return bool( int( vim.eval( variable ) ) )
def GetIntValue( variable ):
return int( vim.eval( variable ) )

View file

@ -1,406 +0,0 @@
#!/usr/bin/env python
#
# Copyright (C) 2011, 2012 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import os
import vim
import tempfile
import json
import signal
import base64
from subprocess import PIPE
from ycm import vimsupport
from ycmd import utils
from ycmd.request_wrap import RequestWrap
from ycm.diagnostic_interface import DiagnosticInterface
from ycm.omni_completer import OmniCompleter
from ycm import syntax_parse
from ycmd.completers.completer_utils import FiletypeCompleterExistsForFiletype
from ycm.client.ycmd_keepalive import YcmdKeepalive
from ycm.client.base_request import BaseRequest, BuildRequestData
from ycm.client.command_request import SendCommandRequest
from ycm.client.completion_request import CompletionRequest
from ycm.client.omni_completion_request import OmniCompletionRequest
from ycm.client.event_notification import ( SendEventNotificationAsync,
EventNotification )
from ycmd.responses import ServerError
try:
from UltiSnips import UltiSnips_Manager
USE_ULTISNIPS_DATA = True
except ImportError:
USE_ULTISNIPS_DATA = False
def PatchNoProxy():
current_value = os.environ.get('no_proxy', '')
additions = '127.0.0.1,localhost'
os.environ['no_proxy'] = ( additions if not current_value
else current_value + ',' + additions )
# We need this so that Requests doesn't end up using the local HTTP proxy when
# talking to ycmd. Users should actually be setting this themselves when
# configuring a proxy server on their machine, but most don't know they need to
# or how to do it, so we do it for them.
# Relevant issues:
# https://github.com/Valloric/YouCompleteMe/issues/641
# https://github.com/kennethreitz/requests/issues/879
PatchNoProxy()
# Force the Python interpreter embedded in Vim (in which we are running) to
# ignore the SIGINT signal. This helps reduce the fallout of a user pressing
# Ctrl-C in Vim.
signal.signal( signal.SIGINT, signal.SIG_IGN )
HMAC_SECRET_LENGTH = 16
NUM_YCMD_STDERR_LINES_ON_CRASH = 30
SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED = (
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). '
'Logfile was deleted; set g:ycm_server_keep_logfiles to see errors '
'in the future.' )
SERVER_CRASH_MESSAGE_STDERR_FILE = (
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). ' +
'Stderr (last {0} lines):\n\n'.format( NUM_YCMD_STDERR_LINES_ON_CRASH ) )
SERVER_CRASH_MESSAGE_SAME_STDERR = (
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). '
' check console output for logs!' )
SERVER_IDLE_SUICIDE_SECONDS = 10800 # 3 hours
class YouCompleteMe( object ):
def __init__( self, user_options ):
self._user_options = user_options
self._user_notified_about_crash = False
self._diag_interface = DiagnosticInterface( user_options )
self._omnicomp = OmniCompleter( user_options )
self._latest_file_parse_request = None
self._latest_completion_request = None
self._server_stdout = None
self._server_stderr = None
self._server_popen = None
self._filetypes_with_keywords_loaded = set()
self._ycmd_keepalive = YcmdKeepalive()
self._SetupServer()
self._ycmd_keepalive.Start()
def _SetupServer( self ):
server_port = utils.GetUnusedLocalhostPort()
# The temp options file is deleted by ycmd during startup
with tempfile.NamedTemporaryFile( delete = False ) as options_file:
hmac_secret = os.urandom( HMAC_SECRET_LENGTH )
options_dict = dict( self._user_options )
options_dict[ 'hmac_secret' ] = base64.b64encode( hmac_secret )
json.dump( options_dict, options_file )
options_file.flush()
args = [ utils.PathToPythonInterpreter(),
_PathToServerScript(),
'--port={0}'.format( server_port ),
'--options_file={0}'.format( options_file.name ),
'--log={0}'.format( self._user_options[ 'server_log_level' ] ),
'--idle_suicide_seconds={0}'.format(
SERVER_IDLE_SUICIDE_SECONDS )]
if not self._user_options[ 'server_use_vim_stdout' ]:
filename_format = os.path.join( utils.PathToTempDir(),
'server_{port}_{std}.log' )
self._server_stdout = filename_format.format( port = server_port,
std = 'stdout' )
self._server_stderr = filename_format.format( port = server_port,
std = 'stderr' )
args.append('--stdout={0}'.format( self._server_stdout ))
args.append('--stderr={0}'.format( self._server_stderr ))
if self._user_options[ 'server_keep_logfiles' ]:
args.append('--keep_logfiles')
self._server_popen = utils.SafePopen( args, stdout = PIPE, stderr = PIPE)
BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port )
BaseRequest.hmac_secret = hmac_secret
self._NotifyUserIfServerCrashed()
def IsServerAlive( self ):
returncode = self._server_popen.poll()
# When the process hasn't finished yet, poll() returns None.
return returncode is None
def _NotifyUserIfServerCrashed( self ):
if self._user_notified_about_crash or self.IsServerAlive():
return
self._user_notified_about_crash = True
if self._server_stderr:
try:
with open( self._server_stderr, 'r' ) as server_stderr_file:
error_output = ''.join( server_stderr_file.readlines()[
: - NUM_YCMD_STDERR_LINES_ON_CRASH ] )
vimsupport.PostMultiLineNotice( SERVER_CRASH_MESSAGE_STDERR_FILE +
error_output )
except IOError:
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED )
else:
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_SAME_STDERR )
def ServerPid( self ):
if not self._server_popen:
return -1
return self._server_popen.pid
def _ServerCleanup( self ):
if self.IsServerAlive():
self._server_popen.terminate()
def RestartServer( self ):
vimsupport.PostVimMessage( 'Restarting ycmd server...' )
self._user_notified_about_crash = False
self._ServerCleanup()
self._SetupServer()
def CreateCompletionRequest( self, force_semantic = False ):
request_data = BuildRequestData()
if ( not self.NativeFiletypeCompletionAvailable() and
self.CurrentFiletypeCompletionEnabled() ):
wrapped_request_data = RequestWrap( request_data )
if self._omnicomp.ShouldUseNow( wrapped_request_data ):
self._latest_completion_request = OmniCompletionRequest(
self._omnicomp, wrapped_request_data )
return self._latest_completion_request
self._AddExtraConfDataIfNeeded( request_data )
if force_semantic:
request_data[ 'force_semantic' ] = True
self._latest_completion_request = CompletionRequest( request_data )
return self._latest_completion_request
def SendCommandRequest( self, arguments, completer ):
if self.IsServerAlive():
return SendCommandRequest( arguments, completer )
def GetDefinedSubcommands( self ):
if self.IsServerAlive():
try:
return BaseRequest.PostDataToHandler( BuildRequestData(),
'defined_subcommands' )
except ServerError:
return []
else:
return []
def GetCurrentCompletionRequest( self ):
return self._latest_completion_request
def GetOmniCompleter( self ):
return self._omnicomp
def NativeFiletypeCompletionAvailable( self ):
return any( [ FiletypeCompleterExistsForFiletype( x ) for x in
vimsupport.CurrentFiletypes() ] )
def NativeFiletypeCompletionUsable( self ):
return ( self.CurrentFiletypeCompletionEnabled() and
self.NativeFiletypeCompletionAvailable() )
def OnFileReadyToParse( self ):
self._omnicomp.OnFileReadyToParse( None )
if not self.IsServerAlive():
self._NotifyUserIfServerCrashed()
extra_data = {}
self._AddTagsFilesIfNeeded( extra_data )
self._AddSyntaxDataIfNeeded( extra_data )
self._AddExtraConfDataIfNeeded( extra_data )
self._latest_file_parse_request = EventNotification( 'FileReadyToParse',
extra_data )
self._latest_file_parse_request.Start()
def OnBufferUnload( self, deleted_buffer_file ):
if not self.IsServerAlive():
return
SendEventNotificationAsync( 'BufferUnload',
{ 'unloaded_buffer': deleted_buffer_file } )
def OnBufferVisit( self ):
if not self.IsServerAlive():
return
extra_data = {}
_AddUltiSnipsDataIfNeeded( extra_data )
SendEventNotificationAsync( 'BufferVisit', extra_data )
def OnInsertLeave( self ):
if not self.IsServerAlive():
return
SendEventNotificationAsync( 'InsertLeave' )
def OnCursorMoved( self ):
self._diag_interface.OnCursorMoved()
def OnVimLeave( self ):
self._ServerCleanup()
def OnCurrentIdentifierFinished( self ):
if not self.IsServerAlive():
return
SendEventNotificationAsync( 'CurrentIdentifierFinished' )
def DiagnosticsForCurrentFileReady( self ):
return bool( self._latest_file_parse_request and
self._latest_file_parse_request.Done() )
def GetDiagnosticsFromStoredRequest( self, qflist_format = False ):
if self.DiagnosticsForCurrentFileReady():
diagnostics = self._latest_file_parse_request.Response()
# We set the diagnostics request to None because we want to prevent
# repeated refreshing of the buffer with the same diags. Setting this to
# None makes DiagnosticsForCurrentFileReady return False until the next
# request is created.
self._latest_file_parse_request = None
if qflist_format:
return vimsupport.ConvertDiagnosticsToQfList( diagnostics )
else:
return diagnostics
return []
def UpdateDiagnosticInterface( self ):
if not self.DiagnosticsForCurrentFileReady():
return
self._diag_interface.UpdateWithNewDiagnostics(
self.GetDiagnosticsFromStoredRequest() )
def ShowDetailedDiagnostic( self ):
if not self.IsServerAlive():
return
try:
debug_info = BaseRequest.PostDataToHandler( BuildRequestData(),
'detailed_diagnostic' )
if 'message' in debug_info:
vimsupport.EchoText( debug_info[ 'message' ] )
except ServerError as e:
vimsupport.PostVimMessage( str( e ) )
def DebugInfo( self ):
if self.IsServerAlive():
debug_info = BaseRequest.PostDataToHandler( BuildRequestData(),
'debug_info' )
else:
debug_info = 'Server crashed, no debug info from server'
debug_info += '\nServer running at: {0}'.format(
BaseRequest.server_location )
debug_info += '\nServer process ID: {0}'.format( self._server_popen.pid )
if self._server_stderr or self._server_stdout:
debug_info += '\nServer logfiles:\n {0}\n {1}'.format(
self._server_stdout,
self._server_stderr )
return debug_info
def CurrentFiletypeCompletionEnabled( self ):
filetypes = vimsupport.CurrentFiletypes()
filetype_to_disable = self._user_options[
'filetype_specific_completion_to_disable' ]
if '*' in filetype_to_disable:
return False
else:
return not all([ x in filetype_to_disable for x in filetypes ])
def _AddSyntaxDataIfNeeded( self, extra_data ):
if not self._user_options[ 'seed_identifiers_with_syntax' ]:
return
filetype = vimsupport.CurrentFiletypes()[ 0 ]
if filetype in self._filetypes_with_keywords_loaded:
return
self._filetypes_with_keywords_loaded.add( filetype )
extra_data[ 'syntax_keywords' ] = list(
syntax_parse.SyntaxKeywordsForCurrentBuffer() )
def _AddTagsFilesIfNeeded( self, extra_data ):
def GetTagFiles():
tag_files = vim.eval( 'tagfiles()' )
# getcwd() throws an exception when the CWD has been deleted.
try:
current_working_directory = os.getcwd()
except OSError:
return []
return [ os.path.join( current_working_directory, x ) for x in tag_files ]
if not self._user_options[ 'collect_identifiers_from_tags_files' ]:
return
extra_data[ 'tag_files' ] = GetTagFiles()
def _AddExtraConfDataIfNeeded( self, extra_data ):
def BuildExtraConfData( extra_conf_vim_data ):
return dict( ( expr, vimsupport.VimExpressionToPythonType( expr ) )
for expr in extra_conf_vim_data )
extra_conf_vim_data = self._user_options[ 'extra_conf_vim_data' ]
if extra_conf_vim_data:
extra_data[ 'extra_conf_data' ] = BuildExtraConfData(
extra_conf_vim_data )
def _PathToServerScript():
dir_of_current_script = os.path.dirname( os.path.abspath( __file__ ) )
return os.path.join( dir_of_current_script, '../../third_party/ycmd/ycmd' )
def _AddUltiSnipsDataIfNeeded( extra_data ):
if not USE_ULTISNIPS_DATA:
return
try:
rawsnips = UltiSnips_Manager._snips( '', 1 )
except:
return
# UltiSnips_Manager._snips() returns a class instance where:
# class.trigger - name of snippet trigger word ( e.g. defn or testcase )
# class.description - description of the snippet
extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger,
'description': x.description
} for x in rawsnips ]

View file

@ -1,24 +0,0 @@
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
"${SCRIPT_DIR}/third_party/ycmd/build.sh"
flake8 --select=F,C9 --max-complexity=10 "${SCRIPT_DIR}/python"
for directory in "${SCRIPT_DIR}"/third_party/*; do
if [ -d "${directory}" ]; then
export PYTHONPATH=${directory}:$PYTHONPATH
fi
done
for directory in "${SCRIPT_DIR}"/third_party/ycmd/third_party/*; do
if [ -d "${directory}" ]; then
export PYTHONPATH=${directory}:$PYTHONPATH
fi
done
nosetests -v "${SCRIPT_DIR}/python"

View file

@ -1,44 +0,0 @@
2.1.4
=====
- Ported the library again from Python 3.2.5 to get the latest bug fixes
2.1.3
=====
- Fixed race condition in wait(return_when=ALL_COMPLETED)
(http://bugs.python.org/issue14406) -- thanks Ralf Schmitt
- Added missing setUp() methods to several test classes
2.1.2
=====
- Fixed installation problem on Python 3.1
2.1.1
=====
- Fixed missing 'concurrent' package declaration in setup.py
2.1
===
- Moved the code from the 'futures' package to 'concurrent.futures' to provide
a drop in backport that matches the code in Python 3.2 standard library
- Deprecated the old 'futures' package
2.0
===
- Changed implementation to match PEP 3148
1.0
===
Initial release.

View file

@ -1,21 +0,0 @@
Copyright 2009 Brian Quinlan. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY BRIAN QUINLAN "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
HALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,3 +0,0 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View file

@ -1,18 +0,0 @@
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Execute computations asynchronously using threads or processes."""
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
from concurrent.futures._base import (FIRST_COMPLETED,
FIRST_EXCEPTION,
ALL_COMPLETED,
CancelledError,
TimeoutError,
Future,
Executor,
wait,
as_completed)
from concurrent.futures.process import ProcessPoolExecutor
from concurrent.futures.thread import ThreadPoolExecutor

View file

@ -1,574 +0,0 @@
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
from __future__ import with_statement
import logging
import threading
import time
try:
from collections import namedtuple
except ImportError:
from concurrent.futures._compat import namedtuple
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
FIRST_COMPLETED = 'FIRST_COMPLETED'
FIRST_EXCEPTION = 'FIRST_EXCEPTION'
ALL_COMPLETED = 'ALL_COMPLETED'
_AS_COMPLETED = '_AS_COMPLETED'
# Possible future states (for internal use by the futures package).
PENDING = 'PENDING'
RUNNING = 'RUNNING'
# The future was cancelled by the user...
CANCELLED = 'CANCELLED'
# ...and _Waiter.add_cancelled() was called by a worker.
CANCELLED_AND_NOTIFIED = 'CANCELLED_AND_NOTIFIED'
FINISHED = 'FINISHED'
_FUTURE_STATES = [
PENDING,
RUNNING,
CANCELLED,
CANCELLED_AND_NOTIFIED,
FINISHED
]
_STATE_TO_DESCRIPTION_MAP = {
PENDING: "pending",
RUNNING: "running",
CANCELLED: "cancelled",
CANCELLED_AND_NOTIFIED: "cancelled",
FINISHED: "finished"
}
# Logger for internal use by the futures package.
LOGGER = logging.getLogger("concurrent.futures")
class Error(Exception):
"""Base class for all future-related exceptions."""
pass
class CancelledError(Error):
"""The Future was cancelled."""
pass
class TimeoutError(Error):
"""The operation exceeded the given deadline."""
pass
class _Waiter(object):
"""Provides the event that wait() and as_completed() block on."""
def __init__(self):
self.event = threading.Event()
self.finished_futures = []
def add_result(self, future):
self.finished_futures.append(future)
def add_exception(self, future):
self.finished_futures.append(future)
def add_cancelled(self, future):
self.finished_futures.append(future)
class _AsCompletedWaiter(_Waiter):
"""Used by as_completed()."""
def __init__(self):
super(_AsCompletedWaiter, self).__init__()
self.lock = threading.Lock()
def add_result(self, future):
with self.lock:
super(_AsCompletedWaiter, self).add_result(future)
self.event.set()
def add_exception(self, future):
with self.lock:
super(_AsCompletedWaiter, self).add_exception(future)
self.event.set()
def add_cancelled(self, future):
with self.lock:
super(_AsCompletedWaiter, self).add_cancelled(future)
self.event.set()
class _FirstCompletedWaiter(_Waiter):
"""Used by wait(return_when=FIRST_COMPLETED)."""
def add_result(self, future):
super(_FirstCompletedWaiter, self).add_result(future)
self.event.set()
def add_exception(self, future):
super(_FirstCompletedWaiter, self).add_exception(future)
self.event.set()
def add_cancelled(self, future):
super(_FirstCompletedWaiter, self).add_cancelled(future)
self.event.set()
class _AllCompletedWaiter(_Waiter):
"""Used by wait(return_when=FIRST_EXCEPTION and ALL_COMPLETED)."""
def __init__(self, num_pending_calls, stop_on_exception):
self.num_pending_calls = num_pending_calls
self.stop_on_exception = stop_on_exception
self.lock = threading.Lock()
super(_AllCompletedWaiter, self).__init__()
def _decrement_pending_calls(self):
with self.lock:
self.num_pending_calls -= 1
if not self.num_pending_calls:
self.event.set()
def add_result(self, future):
super(_AllCompletedWaiter, self).add_result(future)
self._decrement_pending_calls()
def add_exception(self, future):
super(_AllCompletedWaiter, self).add_exception(future)
if self.stop_on_exception:
self.event.set()
else:
self._decrement_pending_calls()
def add_cancelled(self, future):
super(_AllCompletedWaiter, self).add_cancelled(future)
self._decrement_pending_calls()
class _AcquireFutures(object):
"""A context manager that does an ordered acquire of Future conditions."""
def __init__(self, futures):
self.futures = sorted(futures, key=id)
def __enter__(self):
for future in self.futures:
future._condition.acquire()
def __exit__(self, *args):
for future in self.futures:
future._condition.release()
def _create_and_install_waiters(fs, return_when):
if return_when == _AS_COMPLETED:
waiter = _AsCompletedWaiter()
elif return_when == FIRST_COMPLETED:
waiter = _FirstCompletedWaiter()
else:
pending_count = sum(
f._state not in [CANCELLED_AND_NOTIFIED, FINISHED] for f in fs)
if return_when == FIRST_EXCEPTION:
waiter = _AllCompletedWaiter(pending_count, stop_on_exception=True)
elif return_when == ALL_COMPLETED:
waiter = _AllCompletedWaiter(pending_count, stop_on_exception=False)
else:
raise ValueError("Invalid return condition: %r" % return_when)
for f in fs:
f._waiters.append(waiter)
return waiter
def as_completed(fs, timeout=None):
"""An iterator over the given futures that yields each as it completes.
Args:
fs: The sequence of Futures (possibly created by different Executors) to
iterate over.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
Returns:
An iterator that yields the given Futures as they complete (finished or
cancelled).
Raises:
TimeoutError: If the entire result iterator could not be generated
before the given timeout.
"""
if timeout is not None:
end_time = timeout + time.time()
with _AcquireFutures(fs):
finished = set(
f for f in fs
if f._state in [CANCELLED_AND_NOTIFIED, FINISHED])
pending = set(fs) - finished
waiter = _create_and_install_waiters(fs, _AS_COMPLETED)
try:
for future in finished:
yield future
while pending:
if timeout is None:
wait_timeout = None
else:
wait_timeout = end_time - time.time()
if wait_timeout < 0:
raise TimeoutError(
'%d (of %d) futures unfinished' % (
len(pending), len(fs)))
waiter.event.wait(wait_timeout)
with waiter.lock:
finished = waiter.finished_futures
waiter.finished_futures = []
waiter.event.clear()
for future in finished:
yield future
pending.remove(future)
finally:
for f in fs:
f._waiters.remove(waiter)
DoneAndNotDoneFutures = namedtuple(
'DoneAndNotDoneFutures', 'done not_done')
def wait(fs, timeout=None, return_when=ALL_COMPLETED):
"""Wait for the futures in the given sequence to complete.
Args:
fs: The sequence of Futures (possibly created by different Executors) to
wait upon.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
return_when: Indicates when this function should return. The options
are:
FIRST_COMPLETED - Return when any future finishes or is
cancelled.
FIRST_EXCEPTION - Return when any future finishes by raising an
exception. If no future raises an exception
then it is equivalent to ALL_COMPLETED.
ALL_COMPLETED - Return when all futures finish or are cancelled.
Returns:
A named 2-tuple of sets. The first set, named 'done', contains the
futures that completed (is finished or cancelled) before the wait
completed. The second set, named 'not_done', contains uncompleted
futures.
"""
with _AcquireFutures(fs):
done = set(f for f in fs
if f._state in [CANCELLED_AND_NOTIFIED, FINISHED])
not_done = set(fs) - done
if (return_when == FIRST_COMPLETED) and done:
return DoneAndNotDoneFutures(done, not_done)
elif (return_when == FIRST_EXCEPTION) and done:
if any(f for f in done
if not f.cancelled() and f.exception() is not None):
return DoneAndNotDoneFutures(done, not_done)
if len(done) == len(fs):
return DoneAndNotDoneFutures(done, not_done)
waiter = _create_and_install_waiters(fs, return_when)
waiter.event.wait(timeout)
for f in fs:
f._waiters.remove(waiter)
done.update(waiter.finished_futures)
return DoneAndNotDoneFutures(done, set(fs) - done)
class Future(object):
"""Represents the result of an asynchronous computation."""
def __init__(self):
"""Initializes the future. Should not be called by clients."""
self._condition = threading.Condition()
self._state = PENDING
self._result = None
self._exception = None
self._waiters = []
self._done_callbacks = []
def _invoke_callbacks(self):
for callback in self._done_callbacks:
try:
callback(self)
except Exception:
LOGGER.exception('exception calling callback for %r', self)
def __repr__(self):
with self._condition:
if self._state == FINISHED:
if self._exception:
return '<Future at %s state=%s raised %s>' % (
hex(id(self)),
_STATE_TO_DESCRIPTION_MAP[self._state],
self._exception.__class__.__name__)
else:
return '<Future at %s state=%s returned %s>' % (
hex(id(self)),
_STATE_TO_DESCRIPTION_MAP[self._state],
self._result.__class__.__name__)
return '<Future at %s state=%s>' % (
hex(id(self)),
_STATE_TO_DESCRIPTION_MAP[self._state])
def cancel(self):
"""Cancel the future if possible.
Returns True if the future was cancelled, False otherwise. A future
cannot be cancelled if it is running or has already completed.
"""
with self._condition:
if self._state in [RUNNING, FINISHED]:
return False
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
return True
self._state = CANCELLED
self._condition.notify_all()
self._invoke_callbacks()
return True
def cancelled(self):
"""Return True if the future has cancelled."""
with self._condition:
return self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]
def running(self):
"""Return True if the future is currently executing."""
with self._condition:
return self._state == RUNNING
def done(self):
"""Return True of the future was cancelled or finished executing."""
with self._condition:
return self._state in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]
def __get_result(self):
if self._exception:
raise self._exception
else:
return self._result
def add_done_callback(self, fn):
"""Attaches a callable that will be called when the future finishes.
Args:
fn: A callable that will be called with this future as its only
argument when the future completes or is cancelled. The callable
will always be called by a thread in the same process in which
it was added. If the future has already completed or been
cancelled then the callable will be called immediately. These
callables are called in the order that they were added.
"""
with self._condition:
if self._state not in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]:
self._done_callbacks.append(fn)
return
fn(self)
def result(self, timeout=None):
"""Return the result of the call that the future represents.
Args:
timeout: The number of seconds to wait for the result if the future
isn't done. If None, then there is no limit on the wait time.
Returns:
The result of the call that the future represents.
Raises:
CancelledError: If the future was cancelled.
TimeoutError: If the future didn't finish executing before the given
timeout.
Exception: If the call raised then that exception will be raised.
"""
with self._condition:
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
raise CancelledError()
elif self._state == FINISHED:
return self.__get_result()
self._condition.wait(timeout)
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
raise CancelledError()
elif self._state == FINISHED:
return self.__get_result()
else:
raise TimeoutError()
def exception(self, timeout=None):
"""Return the exception raised by the call that the future represents.
Args:
timeout: The number of seconds to wait for the exception if the
future isn't done. If None, then there is no limit on the wait
time.
Returns:
The exception raised by the call that the future represents or None
if the call completed without raising.
Raises:
CancelledError: If the future was cancelled.
TimeoutError: If the future didn't finish executing before the given
timeout.
"""
with self._condition:
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
raise CancelledError()
elif self._state == FINISHED:
return self._exception
self._condition.wait(timeout)
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
raise CancelledError()
elif self._state == FINISHED:
return self._exception
else:
raise TimeoutError()
# The following methods should only be used by Executors and in tests.
def set_running_or_notify_cancel(self):
"""Mark the future as running or process any cancel notifications.
Should only be used by Executor implementations and unit tests.
If the future has been cancelled (cancel() was called and returned
True) then any threads waiting on the future completing (though calls
to as_completed() or wait()) are notified and False is returned.
If the future was not cancelled then it is put in the running state
(future calls to running() will return True) and True is returned.
This method should be called by Executor implementations before
executing the work associated with this future. If this method returns
False then the work should not be executed.
Returns:
False if the Future was cancelled, True otherwise.
Raises:
RuntimeError: if this method was already called or if set_result()
or set_exception() was called.
"""
with self._condition:
if self._state == CANCELLED:
self._state = CANCELLED_AND_NOTIFIED
for waiter in self._waiters:
waiter.add_cancelled(self)
# self._condition.notify_all() is not necessary because
# self.cancel() triggers a notification.
return False
elif self._state == PENDING:
self._state = RUNNING
return True
else:
LOGGER.critical('Future %s in unexpected state: %s',
id(self.future),
self.future._state)
raise RuntimeError('Future in unexpected state')
def set_result(self, result):
"""Sets the return value of work associated with the future.
Should only be used by Executor implementations and unit tests.
"""
with self._condition:
self._result = result
self._state = FINISHED
for waiter in self._waiters:
waiter.add_result(self)
self._condition.notify_all()
self._invoke_callbacks()
def set_exception(self, exception):
"""Sets the result of the future as being the given exception.
Should only be used by Executor implementations and unit tests.
"""
with self._condition:
self._exception = exception
self._state = FINISHED
for waiter in self._waiters:
waiter.add_exception(self)
self._condition.notify_all()
self._invoke_callbacks()
class Executor(object):
"""This is an abstract base class for concrete asynchronous executors."""
def submit(self, fn, *args, **kwargs):
"""Submits a callable to be executed with the given arguments.
Schedules the callable to be executed as fn(*args, **kwargs) and returns
a Future instance representing the execution of the callable.
Returns:
A Future representing the given call.
"""
raise NotImplementedError()
def map(self, fn, *iterables, **kwargs):
"""Returns a iterator equivalent to map(fn, iter).
Args:
fn: A callable that will take as many arguments as there are
passed iterables.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
Returns:
An iterator equivalent to: map(func, *iterables) but the calls may
be evaluated out-of-order.
Raises:
TimeoutError: If the entire result iterator could not be generated
before the given timeout.
Exception: If fn(*args) raises for any values.
"""
timeout = kwargs.get('timeout')
if timeout is not None:
end_time = timeout + time.time()
fs = [self.submit(fn, *args) for args in zip(*iterables)]
try:
for future in fs:
if timeout is None:
yield future.result()
else:
yield future.result(end_time - time.time())
finally:
for future in fs:
future.cancel()
def shutdown(self, wait=True):
"""Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other
methods can be called after this one.
Args:
wait: If True then shutdown will not return until all running
futures have finished executing and the resources used by the
executor have been reclaimed.
"""
pass
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.shutdown(wait=True)
return False

View file

@ -1,101 +0,0 @@
from keyword import iskeyword as _iskeyword
from operator import itemgetter as _itemgetter
import sys as _sys
def namedtuple(typename, field_names):
"""Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', 'x y')
>>> Point.__doc__ # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22) # instantiate with positional args or keywords
>>> p[0] + p[1] # indexable like a plain tuple
33
>>> x, y = p # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y # fields also accessable by name
33
>>> d = p._asdict() # convert to a dictionary
>>> d['x']
11
>>> Point(**d) # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
"""
# Parse and validate the field names. Validation serves two purposes,
# generating informative error messages and preventing template injection attacks.
if isinstance(field_names, basestring):
field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
field_names = tuple(map(str, field_names))
for name in (typename,) + field_names:
if not all(c.isalnum() or c=='_' for c in name):
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
if _iskeyword(name):
raise ValueError('Type names and field names cannot be a keyword: %r' % name)
if name[0].isdigit():
raise ValueError('Type names and field names cannot start with a number: %r' % name)
seen_names = set()
for name in field_names:
if name.startswith('_'):
raise ValueError('Field names cannot start with an underscore: %r' % name)
if name in seen_names:
raise ValueError('Encountered duplicate field name: %r' % name)
seen_names.add(name)
# Create and fill-in the class template
numfields = len(field_names)
argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
dicttxt = ', '.join('%r: t[%d]' % (name, pos) for pos, name in enumerate(field_names))
template = '''class %(typename)s(tuple):
'%(typename)s(%(argtxt)s)' \n
__slots__ = () \n
_fields = %(field_names)r \n
def __new__(_cls, %(argtxt)s):
return _tuple.__new__(_cls, (%(argtxt)s)) \n
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
'Make a new %(typename)s object from a sequence or iterable'
result = new(cls, iterable)
if len(result) != %(numfields)d:
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
return result \n
def __repr__(self):
return '%(typename)s(%(reprtxt)s)' %% self \n
def _asdict(t):
'Return a new dict which maps field names to their values'
return {%(dicttxt)s} \n
def _replace(_self, **kwds):
'Return a new %(typename)s object replacing specified fields with new values'
result = _self._make(map(kwds.pop, %(field_names)r, _self))
if kwds:
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
return result \n
def __getnewargs__(self):
return tuple(self) \n\n''' % locals()
for i, name in enumerate(field_names):
template += ' %s = _property(_itemgetter(%d))\n' % (name, i)
# Execute the template string in a temporary namespace and
# support tracing utilities by setting a value for frame.f_globals['__name__']
namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
_property=property, _tuple=tuple)
try:
exec(template, namespace)
except SyntaxError:
e = _sys.exc_info()[1]
raise SyntaxError(e.message + ':\n' + template)
result = namespace[typename]
# For pickling to work, the __module__ variable needs to be set to the frame
# where the named tuple is created. Bypass this step in enviroments where
# sys._getframe is not defined (Jython for example).
if hasattr(_sys, '_getframe'):
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
return result

View file

@ -1,363 +0,0 @@
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Implements ProcessPoolExecutor.
The follow diagram and text describe the data-flow through the system:
|======================= In-process =====================|== Out-of-process ==|
+----------+ +----------+ +--------+ +-----------+ +---------+
| | => | Work Ids | => | | => | Call Q | => | |
| | +----------+ | | +-----------+ | |
| | | ... | | | | ... | | |
| | | 6 | | | | 5, call() | | |
| | | 7 | | | | ... | | |
| Process | | ... | | Local | +-----------+ | Process |
| Pool | +----------+ | Worker | | #1..n |
| Executor | | Thread | | |
| | +----------- + | | +-----------+ | |
| | <=> | Work Items | <=> | | <= | Result Q | <= | |
| | +------------+ | | +-----------+ | |
| | | 6: call() | | | | ... | | |
| | | future | | | | 4, result | | |
| | | ... | | | | 3, except | | |
+----------+ +------------+ +--------+ +-----------+ +---------+
Executor.submit() called:
- creates a uniquely numbered _WorkItem and adds it to the "Work Items" dict
- adds the id of the _WorkItem to the "Work Ids" queue
Local worker thread:
- reads work ids from the "Work Ids" queue and looks up the corresponding
WorkItem from the "Work Items" dict: if the work item has been cancelled then
it is simply removed from the dict, otherwise it is repackaged as a
_CallItem and put in the "Call Q". New _CallItems are put in the "Call Q"
until "Call Q" is full. NOTE: the size of the "Call Q" is kept small because
calls placed in the "Call Q" can no longer be cancelled with Future.cancel().
- reads _ResultItems from "Result Q", updates the future stored in the
"Work Items" dict and deletes the dict entry
Process #1..n:
- reads _CallItems from "Call Q", executes the calls, and puts the resulting
_ResultItems in "Request Q"
"""
from __future__ import with_statement
import atexit
import multiprocessing
import threading
import weakref
import sys
from concurrent.futures import _base
try:
import queue
except ImportError:
import Queue as queue
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
# Workers are created as daemon threads and processes. This is done to allow the
# interpreter to exit when there are still idle processes in a
# ProcessPoolExecutor's process pool (i.e. shutdown() was not called). However,
# allowing workers to die with the interpreter has two undesirable properties:
# - The workers would still be running during interpretor shutdown,
# meaning that they would fail in unpredictable ways.
# - The workers could be killed while evaluating a work item, which could
# be bad if the callable being evaluated has external side-effects e.g.
# writing to a file.
#
# To work around this problem, an exit handler is installed which tells the
# workers to exit when their work queues are empty and then waits until the
# threads/processes finish.
_threads_queues = weakref.WeakKeyDictionary()
_shutdown = False
def _python_exit():
global _shutdown
_shutdown = True
items = list(_threads_queues.items())
for t, q in items:
q.put(None)
for t, q in items:
t.join()
# Controls how many more calls than processes will be queued in the call queue.
# A smaller number will mean that processes spend more time idle waiting for
# work while a larger number will make Future.cancel() succeed less frequently
# (Futures in the call queue cannot be cancelled).
EXTRA_QUEUED_CALLS = 1
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):
self.future = future
self.fn = fn
self.args = args
self.kwargs = kwargs
class _ResultItem(object):
def __init__(self, work_id, exception=None, result=None):
self.work_id = work_id
self.exception = exception
self.result = result
class _CallItem(object):
def __init__(self, work_id, fn, args, kwargs):
self.work_id = work_id
self.fn = fn
self.args = args
self.kwargs = kwargs
def _process_worker(call_queue, result_queue):
"""Evaluates calls from call_queue and places the results in result_queue.
This worker is run in a separate process.
Args:
call_queue: A multiprocessing.Queue of _CallItems that will be read and
evaluated by the worker.
result_queue: A multiprocessing.Queue of _ResultItems that will written
to by the worker.
shutdown: A multiprocessing.Event that will be set as a signal to the
worker that it should exit when call_queue is empty.
"""
while True:
call_item = call_queue.get(block=True)
if call_item is None:
# Wake up queue management thread
result_queue.put(None)
return
try:
r = call_item.fn(*call_item.args, **call_item.kwargs)
except BaseException:
e = sys.exc_info()[1]
result_queue.put(_ResultItem(call_item.work_id,
exception=e))
else:
result_queue.put(_ResultItem(call_item.work_id,
result=r))
def _add_call_item_to_queue(pending_work_items,
work_ids,
call_queue):
"""Fills call_queue with _WorkItems from pending_work_items.
This function never blocks.
Args:
pending_work_items: A dict mapping work ids to _WorkItems e.g.
{5: <_WorkItem...>, 6: <_WorkItem...>, ...}
work_ids: A queue.Queue of work ids e.g. Queue([5, 6, ...]). Work ids
are consumed and the corresponding _WorkItems from
pending_work_items are transformed into _CallItems and put in
call_queue.
call_queue: A multiprocessing.Queue that will be filled with _CallItems
derived from _WorkItems.
"""
while True:
if call_queue.full():
return
try:
work_id = work_ids.get(block=False)
except queue.Empty:
return
else:
work_item = pending_work_items[work_id]
if work_item.future.set_running_or_notify_cancel():
call_queue.put(_CallItem(work_id,
work_item.fn,
work_item.args,
work_item.kwargs),
block=True)
else:
del pending_work_items[work_id]
continue
def _queue_management_worker(executor_reference,
processes,
pending_work_items,
work_ids_queue,
call_queue,
result_queue):
"""Manages the communication between this process and the worker processes.
This function is run in a local thread.
Args:
executor_reference: A weakref.ref to the ProcessPoolExecutor that owns
this thread. Used to determine if the ProcessPoolExecutor has been
garbage collected and that this function can exit.
process: A list of the multiprocessing.Process instances used as
workers.
pending_work_items: A dict mapping work ids to _WorkItems e.g.
{5: <_WorkItem...>, 6: <_WorkItem...>, ...}
work_ids_queue: A queue.Queue of work ids e.g. Queue([5, 6, ...]).
call_queue: A multiprocessing.Queue that will be filled with _CallItems
derived from _WorkItems for processing by the process workers.
result_queue: A multiprocessing.Queue of _ResultItems generated by the
process workers.
"""
nb_shutdown_processes = [0]
def shutdown_one_process():
"""Tell a worker to terminate, which will in turn wake us again"""
call_queue.put(None)
nb_shutdown_processes[0] += 1
while True:
_add_call_item_to_queue(pending_work_items,
work_ids_queue,
call_queue)
result_item = result_queue.get(block=True)
if result_item is not None:
work_item = pending_work_items[result_item.work_id]
del pending_work_items[result_item.work_id]
if result_item.exception:
work_item.future.set_exception(result_item.exception)
else:
work_item.future.set_result(result_item.result)
# Check whether we should start shutting down.
executor = executor_reference()
# No more work items can be added if:
# - The interpreter is shutting down OR
# - The executor that owns this worker has been collected OR
# - The executor that owns this worker has been shutdown.
if _shutdown or executor is None or executor._shutdown_thread:
# Since no new work items can be added, it is safe to shutdown
# this thread if there are no pending work items.
if not pending_work_items:
while nb_shutdown_processes[0] < len(processes):
shutdown_one_process()
# If .join() is not called on the created processes then
# some multiprocessing.Queue methods may deadlock on Mac OS
# X.
for p in processes:
p.join()
call_queue.close()
return
del executor
_system_limits_checked = False
_system_limited = None
def _check_system_limits():
global _system_limits_checked, _system_limited
if _system_limits_checked:
if _system_limited:
raise NotImplementedError(_system_limited)
_system_limits_checked = True
try:
import os
nsems_max = os.sysconf("SC_SEM_NSEMS_MAX")
except (AttributeError, ValueError):
# sysconf not available or setting not available
return
if nsems_max == -1:
# indetermine limit, assume that limit is determined
# by available memory only
return
if nsems_max >= 256:
# minimum number of semaphores available
# according to POSIX
return
_system_limited = "system provides too few semaphores (%d available, 256 necessary)" % nsems_max
raise NotImplementedError(_system_limited)
class ProcessPoolExecutor(_base.Executor):
def __init__(self, max_workers=None):
"""Initializes a new ProcessPoolExecutor instance.
Args:
max_workers: The maximum number of processes that can be used to
execute the given calls. If None or not given then as many
worker processes will be created as the machine has processors.
"""
_check_system_limits()
if max_workers is None:
self._max_workers = multiprocessing.cpu_count()
else:
self._max_workers = max_workers
# Make the call queue slightly larger than the number of processes to
# prevent the worker processes from idling. But don't make it too big
# because futures in the call queue cannot be cancelled.
self._call_queue = multiprocessing.Queue(self._max_workers +
EXTRA_QUEUED_CALLS)
self._result_queue = multiprocessing.Queue()
self._work_ids = queue.Queue()
self._queue_management_thread = None
self._processes = set()
# Shutdown is a two-step process.
self._shutdown_thread = False
self._shutdown_lock = threading.Lock()
self._queue_count = 0
self._pending_work_items = {}
def _start_queue_management_thread(self):
# When the executor gets lost, the weakref callback will wake up
# the queue management thread.
def weakref_cb(_, q=self._result_queue):
q.put(None)
if self._queue_management_thread is None:
self._queue_management_thread = threading.Thread(
target=_queue_management_worker,
args=(weakref.ref(self, weakref_cb),
self._processes,
self._pending_work_items,
self._work_ids,
self._call_queue,
self._result_queue))
self._queue_management_thread.daemon = True
self._queue_management_thread.start()
_threads_queues[self._queue_management_thread] = self._result_queue
def _adjust_process_count(self):
for _ in range(len(self._processes), self._max_workers):
p = multiprocessing.Process(
target=_process_worker,
args=(self._call_queue,
self._result_queue))
p.start()
self._processes.add(p)
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
if self._shutdown_thread:
raise RuntimeError('cannot schedule new futures after shutdown')
f = _base.Future()
w = _WorkItem(f, fn, args, kwargs)
self._pending_work_items[self._queue_count] = w
self._work_ids.put(self._queue_count)
self._queue_count += 1
# Wake up queue management thread
self._result_queue.put(None)
self._start_queue_management_thread()
self._adjust_process_count()
return f
submit.__doc__ = _base.Executor.submit.__doc__
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown_thread = True
if self._queue_management_thread:
# Wake up queue management thread
self._result_queue.put(None)
if wait:
self._queue_management_thread.join()
# To reduce the risk of openning too many files, remove references to
# objects that use file descriptors.
self._queue_management_thread = None
self._call_queue = None
self._result_queue = None
self._processes = None
shutdown.__doc__ = _base.Executor.shutdown.__doc__
atexit.register(_python_exit)

View file

@ -1,138 +0,0 @@
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Implements ThreadPoolExecutor."""
from __future__ import with_statement
import atexit
import threading
import weakref
import sys
from concurrent.futures import _base
try:
import queue
except ImportError:
import Queue as queue
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
# Workers are created as daemon threads. This is done to allow the interpreter
# to exit when there are still idle threads in a ThreadPoolExecutor's thread
# pool (i.e. shutdown() was not called). However, allowing workers to die with
# the interpreter has two undesirable properties:
# - The workers would still be running during interpretor shutdown,
# meaning that they would fail in unpredictable ways.
# - The workers could be killed while evaluating a work item, which could
# be bad if the callable being evaluated has external side-effects e.g.
# writing to a file.
#
# To work around this problem, an exit handler is installed which tells the
# workers to exit when their work queues are empty and then waits until the
# threads finish.
_threads_queues = weakref.WeakKeyDictionary()
_shutdown = False
def _python_exit():
global _shutdown
_shutdown = True
items = list(_threads_queues.items())
for t, q in items:
q.put(None)
for t, q in items:
t.join()
atexit.register(_python_exit)
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):
self.future = future
self.fn = fn
self.args = args
self.kwargs = kwargs
def run(self):
if not self.future.set_running_or_notify_cancel():
return
try:
result = self.fn(*self.args, **self.kwargs)
except BaseException:
e = sys.exc_info()[1]
self.future.set_exception(e)
else:
self.future.set_result(result)
def _worker(executor_reference, work_queue):
try:
while True:
work_item = work_queue.get(block=True)
if work_item is not None:
work_item.run()
continue
executor = executor_reference()
# Exit if:
# - The interpreter is shutting down OR
# - The executor that owns the worker has been collected OR
# - The executor that owns the worker has been shutdown.
if _shutdown or executor is None or executor._shutdown:
# Notice other workers
work_queue.put(None)
return
del executor
except BaseException:
_base.LOGGER.critical('Exception in worker', exc_info=True)
class ThreadPoolExecutor(_base.Executor):
def __init__(self, max_workers):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
"""
self._max_workers = max_workers
self._work_queue = queue.Queue()
self._threads = set()
self._shutdown = False
self._shutdown_lock = threading.Lock()
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
if self._shutdown:
raise RuntimeError('cannot schedule new futures after shutdown')
f = _base.Future()
w = _WorkItem(f, fn, args, kwargs)
self._work_queue.put(w)
self._adjust_thread_count()
return f
submit.__doc__ = _base.Executor.submit.__doc__
def _adjust_thread_count(self):
# When the executor gets lost, the weakref callback will wake up
# the worker threads.
def weakref_cb(_, q=self._work_queue):
q.put(None)
# TODO(bquinlan): Should avoid creating new threads if there are more
# idle threads than items in the work queue.
if len(self._threads) < self._max_workers:
t = threading.Thread(target=_worker,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
t.daemon = True
t.start()
self._threads.add(t)
_threads_queues[t] = self._work_queue
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown = True
self._work_queue.put(None)
if wait:
for t in self._threads:
t.join()
shutdown.__doc__ = _base.Executor.shutdown.__doc__

View file

@ -1,74 +0,0 @@
"""Compare the speed of downloading URLs sequentially vs. using futures."""
import functools
import time
import timeit
import sys
try:
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
from concurrent.futures import (as_completed, ThreadPoolExecutor,
ProcessPoolExecutor)
URLS = ['http://www.google.com/',
'http://www.apple.com/',
'http://www.ibm.com',
'http://www.thisurlprobablydoesnotexist.com',
'http://www.slashdot.org/',
'http://www.python.org/',
'http://www.bing.com/',
'http://www.facebook.com/',
'http://www.yahoo.com/',
'http://www.youtube.com/',
'http://www.blogger.com/']
def load_url(url, timeout):
kwargs = {'timeout': timeout} if sys.version_info >= (2, 6) else {}
return urlopen(url, **kwargs).read()
def download_urls_sequential(urls, timeout=60):
url_to_content = {}
for url in urls:
try:
url_to_content[url] = load_url(url, timeout=timeout)
except:
pass
return url_to_content
def download_urls_with_executor(urls, executor, timeout=60):
try:
url_to_content = {}
future_to_url = dict((executor.submit(load_url, url, timeout), url)
for url in urls)
for future in as_completed(future_to_url):
try:
url_to_content[future_to_url[future]] = future.result()
except:
pass
return url_to_content
finally:
executor.shutdown()
def main():
for name, fn in [('sequential',
functools.partial(download_urls_sequential, URLS)),
('processes',
functools.partial(download_urls_with_executor,
URLS,
ProcessPoolExecutor(10))),
('threads',
functools.partial(download_urls_with_executor,
URLS,
ThreadPoolExecutor(10)))]:
sys.stdout.write('%s: ' % name.ljust(12))
start = time.time()
url_map = fn()
sys.stdout.write('%.2f seconds (%d of %d downloaded)\n' %
(time.time() - start, len(url_map), len(URLS)))
if __name__ == '__main__':
main()

View file

@ -1,194 +0,0 @@
# -*- coding: utf-8 -*-
#
# futures documentation build configuration file, created by
# sphinx-quickstart on Wed Jun 3 19:35:34 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.append(os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'futures'
copyright = u'2009-2011, Brian Quinlan'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.1.3'
# The full version, including alpha/beta/rc tags.
release = '2.1.3'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'futuresdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'futures.tex', u'futures Documentation',
u'Brian Quinlan', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True

View file

@ -1,345 +0,0 @@
:mod:`concurrent.futures` --- Asynchronous computation
======================================================
.. module:: concurrent.futures
:synopsis: Execute computations asynchronously using threads or processes.
The :mod:`concurrent.futures` module provides a high-level interface for
asynchronously executing callables.
The asynchronous execution can be be performed by threads using
:class:`ThreadPoolExecutor` or seperate processes using
:class:`ProcessPoolExecutor`. Both implement the same interface, which is
defined by the abstract :class:`Executor` class.
Executor Objects
----------------
:class:`Executor` is an abstract class that provides methods to execute calls
asynchronously. It should not be used directly, but through its two
subclasses: :class:`ThreadPoolExecutor` and :class:`ProcessPoolExecutor`.
.. method:: Executor.submit(fn, *args, **kwargs)
Schedules the callable to be executed as *fn*(*\*args*, *\*\*kwargs*) and
returns a :class:`Future` representing the execution of the callable.
::
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(pow, 323, 1235)
print(future.result())
.. method:: Executor.map(func, *iterables, timeout=None)
Equivalent to map(*func*, *\*iterables*) but func is executed asynchronously
and several calls to *func* may be made concurrently. The returned iterator
raises a :exc:`TimeoutError` if :meth:`__next__()` is called and the result
isn't available after *timeout* seconds from the original call to
:meth:`map()`. *timeout* can be an int or float. If *timeout* is not
specified or ``None`` then there is no limit to the wait time. If a call
raises an exception then that exception will be raised when its value is
retrieved from the iterator.
.. method:: Executor.shutdown(wait=True)
Signal the executor that it should free any resources that it is using when
the currently pending futures are done executing. Calls to
:meth:`Executor.submit` and :meth:`Executor.map` made after shutdown will
raise :exc:`RuntimeError`.
If *wait* is `True` then this method will not return until all the pending
futures are done executing and the resources associated with the executor
have been freed. If *wait* is `False` then this method will return
immediately and the resources associated with the executor will be freed
when all pending futures are done executing. Regardless of the value of
*wait*, the entire Python program will not exit until all pending futures
are done executing.
You can avoid having to call this method explicitly if you use the `with`
statement, which will shutdown the `Executor` (waiting as if
`Executor.shutdown` were called with *wait* set to `True`):
::
import shutil
with ThreadPoolExecutor(max_workers=4) as e:
e.submit(shutil.copy, 'src1.txt', 'dest1.txt')
e.submit(shutil.copy, 'src2.txt', 'dest2.txt')
e.submit(shutil.copy, 'src3.txt', 'dest3.txt')
e.submit(shutil.copy, 'src3.txt', 'dest4.txt')
ThreadPoolExecutor Objects
--------------------------
The :class:`ThreadPoolExecutor` class is an :class:`Executor` subclass that uses
a pool of threads to execute calls asynchronously.
Deadlock can occur when the callable associated with a :class:`Future` waits on
the results of another :class:`Future`. For example:
::
import time
def wait_on_b():
time.sleep(5)
print(b.result()) # b will never complete because it is waiting on a.
return 5
def wait_on_a():
time.sleep(5)
print(a.result()) # a will never complete because it is waiting on b.
return 6
executor = ThreadPoolExecutor(max_workers=2)
a = executor.submit(wait_on_b)
b = executor.submit(wait_on_a)
And:
::
def wait_on_future():
f = executor.submit(pow, 5, 2)
# This will never complete because there is only one worker thread and
# it is executing this function.
print(f.result())
executor = ThreadPoolExecutor(max_workers=1)
executor.submit(wait_on_future)
.. class:: ThreadPoolExecutor(max_workers)
Executes calls asynchronously using at pool of at most *max_workers* threads.
.. _threadpoolexecutor-example:
ThreadPoolExecutor Example
^^^^^^^^^^^^^^^^^^^^^^^^^^
::
from concurrent import futures
import urllib.request
URLS = ['http://www.foxnews.com/',
'http://www.cnn.com/',
'http://europe.wsj.com/',
'http://www.bbc.co.uk/',
'http://some-made-up-domain.com/']
def load_url(url, timeout):
return urllib.request.urlopen(url, timeout=timeout).read()
with futures.ThreadPoolExecutor(max_workers=5) as executor:
future_to_url = dict((executor.submit(load_url, url, 60), url)
for url in URLS)
for future in futures.as_completed(future_to_url):
url = future_to_url[future]
if future.exception() is not None:
print('%r generated an exception: %s' % (url,
future.exception()))
else:
print('%r page is %d bytes' % (url, len(future.result())))
ProcessPoolExecutor Objects
---------------------------
The :class:`ProcessPoolExecutor` class is an :class:`Executor` subclass that
uses a pool of processes to execute calls asynchronously.
:class:`ProcessPoolExecutor` uses the :mod:`multiprocessing` module, which
allows it to side-step the :term:`Global Interpreter Lock` but also means that
only picklable objects can be executed and returned.
Calling :class:`Executor` or :class:`Future` methods from a callable submitted
to a :class:`ProcessPoolExecutor` will result in deadlock.
.. class:: ProcessPoolExecutor(max_workers=None)
Executes calls asynchronously using a pool of at most *max_workers*
processes. If *max_workers* is ``None`` or not given then as many worker
processes will be created as the machine has processors.
.. _processpoolexecutor-example:
ProcessPoolExecutor Example
^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
import math
PRIMES = [
112272535095293,
112582705942171,
112272535095293,
115280095190773,
115797848077099,
1099726899285419]
def is_prime(n):
if n % 2 == 0:
return False
sqrt_n = int(math.floor(math.sqrt(n)))
for i in range(3, sqrt_n + 1, 2):
if n % i == 0:
return False
return True
def main():
with futures.ProcessPoolExecutor() as executor:
for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)):
print('%d is prime: %s' % (number, prime))
if __name__ == '__main__':
main()
Future Objects
--------------
The :class:`Future` class encapulates the asynchronous execution of a callable.
:class:`Future` instances are created by :meth:`Executor.submit`.
.. method:: Future.cancel()
Attempt to cancel the call. If the call is currently being executed then
it cannot be cancelled and the method will return `False`, otherwise the call
will be cancelled and the method will return `True`.
.. method:: Future.cancelled()
Return `True` if the call was successfully cancelled.
.. method:: Future.running()
Return `True` if the call is currently being executed and cannot be
cancelled.
.. method:: Future.done()
Return `True` if the call was successfully cancelled or finished running.
.. method:: Future.result(timeout=None)
Return the value returned by the call. If the call hasn't yet completed then
this method will wait up to *timeout* seconds. If the call hasn't completed
in *timeout* seconds then a :exc:`TimeoutError` will be raised. *timeout* can
be an int or float.If *timeout* is not specified or ``None`` then there is no
limit to the wait time.
If the future is cancelled before completing then :exc:`CancelledError` will
be raised.
If the call raised then this method will raise the same exception.
.. method:: Future.exception(timeout=None)
Return the exception raised by the call. If the call hasn't yet completed
then this method will wait up to *timeout* seconds. If the call hasn't
completed in *timeout* seconds then a :exc:`TimeoutError` will be raised.
*timeout* can be an int or float. If *timeout* is not specified or ``None``
then there is no limit to the wait time.
If the future is cancelled before completing then :exc:`CancelledError` will
be raised.
If the call completed without raising then ``None`` is returned.
.. method:: Future.add_done_callback(fn)
Attaches the callable *fn* to the future. *fn* will be called, with the
future as its only argument, when the future is cancelled or finishes
running.
Added callables are called in the order that they were added and are always
called in a thread belonging to the process that added them. If the callable
raises an :exc:`Exception` then it will be logged and ignored. If the
callable raises another :exc:`BaseException` then the behavior is not
defined.
If the future has already completed or been cancelled then *fn* will be
called immediately.
Internal Future Methods
^^^^^^^^^^^^^^^^^^^^^^^
The following :class:`Future` methods are meant for use in unit tests and
:class:`Executor` implementations.
.. method:: Future.set_running_or_notify_cancel()
This method should only be called by :class:`Executor` implementations before
executing the work associated with the :class:`Future` and by unit tests.
If the method returns `False` then the :class:`Future` was cancelled i.e.
:meth:`Future.cancel` was called and returned `True`. Any threads waiting
on the :class:`Future` completing (i.e. through :func:`as_completed` or
:func:`wait`) will be woken up.
If the method returns `True` then the :class:`Future` was not cancelled
and has been put in the running state i.e. calls to
:meth:`Future.running` will return `True`.
This method can only be called once and cannot be called after
:meth:`Future.set_result` or :meth:`Future.set_exception` have been
called.
.. method:: Future.set_result(result)
Sets the result of the work associated with the :class:`Future` to *result*.
This method should only be used by Executor implementations and unit tests.
.. method:: Future.set_exception(exception)
Sets the result of the work associated with the :class:`Future` to the
:class:`Exception` *exception*.
This method should only be used by Executor implementations and unit tests.
Module Functions
----------------
.. function:: wait(fs, timeout=None, return_when=ALL_COMPLETED)
Wait for the :class:`Future` instances (possibly created by different
:class:`Executor` instances) given by *fs* to complete. Returns a named
2-tuple of sets. The first set, named "done", contains the futures that
completed (finished or were cancelled) before the wait completed. The second
set, named "not_done", contains uncompleted futures.
*timeout* can be used to control the maximum number of seconds to wait before
returning. *timeout* can be an int or float. If *timeout* is not specified or
``None`` then there is no limit to the wait time.
*return_when* indicates when this function should return. It must be one of
the following constants:
+-----------------------------+----------------------------------------+
| Constant | Description |
+=============================+========================================+
| :const:`FIRST_COMPLETED` | The function will return when any |
| | future finishes or is cancelled. |
+-----------------------------+----------------------------------------+
| :const:`FIRST_EXCEPTION` | The function will return when any |
| | future finishes by raising an |
| | exception. If no future raises an |
| | exception then it is equivalent to |
| | `ALL_COMPLETED`. |
+-----------------------------+----------------------------------------+
| :const:`ALL_COMPLETED` | The function will return when all |
| | futures finish or are cancelled. |
+-----------------------------+----------------------------------------+
.. function:: as_completed(fs, timeout=None)
Returns an iterator over the :class:`Future` instances (possibly created
by different :class:`Executor` instances) given by *fs* that yields futures
as they complete (finished or were cancelled). Any futures that completed
before :func:`as_completed()` was called will be yielded first. The returned
iterator raises a :exc:`TimeoutError` if :meth:`__next__()` is called and
the result isn't available after *timeout* seconds from the original call
to :func:`as_completed()`. *timeout* can be an int or float. If *timeout*
is not specified or ``None`` then there is no limit to the wait time.

View file

@ -1,112 +0,0 @@
@ECHO OFF
REM Command file for Sphinx documentation
set SPHINXBUILD=sphinx-build
set ALLSPHINXOPTS=-d _build/doctrees %SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. changes to make an overview over all changed/added/deprecated items
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (_build\*) do rmdir /q /s %%i
del /q /s _build\*
goto end
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% _build/html
echo.
echo.Build finished. The HTML pages are in _build/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% _build/dirhtml
echo.
echo.Build finished. The HTML pages are in _build/dirhtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% _build/pickle
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% _build/json
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% _build/htmlhelp
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in _build/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% _build/qthelp
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in _build/qthelp, like this:
echo.^> qcollectiongenerator _build\qthelp\futures.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile _build\qthelp\futures.ghc
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% _build/latex
echo.
echo.Build finished; the LaTeX files are in _build/latex.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% _build/changes
echo.
echo.The overview file is in _build/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% _build/linkcheck
echo.
echo.Link check complete; look for any errors in the above output ^
or in _build/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% _build/doctest
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in _build/doctest/output.txt.
goto end
)
:end

View file

@ -1,24 +0,0 @@
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Execute computations asynchronously using threads or processes."""
import warnings
from concurrent.futures import (FIRST_COMPLETED,
FIRST_EXCEPTION,
ALL_COMPLETED,
CancelledError,
TimeoutError,
Future,
Executor,
wait,
as_completed,
ProcessPoolExecutor,
ThreadPoolExecutor)
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
warnings.warn('The futures package has been deprecated. '
'Use the concurrent.futures package instead.',
DeprecationWarning)

View file

@ -1 +0,0 @@
from concurrent.futures import ProcessPoolExecutor

View file

@ -1 +0,0 @@
from concurrent.futures import ThreadPoolExecutor

View file

@ -1,50 +0,0 @@
from __future__ import with_statement
import math
import time
import sys
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
PRIMES = [
112272535095293,
112582705942171,
112272535095293,
115280095190773,
115797848077099,
117450548693743,
993960000099397]
def is_prime(n):
if n % 2 == 0:
return False
sqrt_n = int(math.floor(math.sqrt(n)))
for i in range(3, sqrt_n + 1, 2):
if n % i == 0:
return False
return True
def sequential():
return list(map(is_prime, PRIMES))
def with_process_pool_executor():
with ProcessPoolExecutor(10) as executor:
return list(executor.map(is_prime, PRIMES))
def with_thread_pool_executor():
with ThreadPoolExecutor(10) as executor:
return list(executor.map(is_prime, PRIMES))
def main():
for name, fn in [('sequential', sequential),
('processes', with_process_pool_executor),
('threads', with_thread_pool_executor)]:
sys.stdout.write('%s: ' % name.ljust(12))
start = time.time()
if fn() != [True] * len(PRIMES):
sys.stdout.write('failed\n')
else:
sys.stdout.write('%.2f seconds\n' % (time.time() - start))
if __name__ == '__main__':
main()

View file

@ -1,6 +0,0 @@
[build_sphinx]
source-dir = docs
build-dir = build/sphinx
[upload_docs]
upload-dir = build/sphinx/html

View file

@ -1,33 +0,0 @@
#!/usr/bin/env python
import sys
extras = {}
try:
from setuptools import setup
extras['zip_safe'] = False
if sys.version_info < (2, 6):
extras['install_requires'] = ['multiprocessing']
except ImportError:
from distutils.core import setup
setup(name='futures',
version='2.1.4',
description='Backport of the concurrent.futures package from Python 3.2',
author='Brian Quinlan',
author_email='brian@sweetapp.com',
maintainer='Alex Gronholm',
maintainer_email='alex.gronholm+pypi@nextday.fi',
url='http://code.google.com/p/pythonfutures',
download_url='http://pypi.python.org/pypi/futures/',
packages=['futures', 'concurrent', 'concurrent.futures'],
license='BSD',
classifiers=['License :: OSI Approved :: BSD License',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1'],
**extras
)

View file

@ -1,723 +0,0 @@
from __future__ import with_statement
import os
import subprocess
import sys
import threading
import functools
import contextlib
import logging
import re
import time
from concurrent import futures
from concurrent.futures._base import (
PENDING, RUNNING, CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED, Future)
try:
import unittest2 as unittest
except ImportError:
import unittest
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
try:
from test import test_support
except ImportError:
from test import support as test_support
try:
next
except NameError:
next = lambda x: x.next()
def reap_threads(func):
"""Use this function when threads are being used. This will
ensure that the threads are cleaned up even when the test fails.
If threading is unavailable this function does nothing.
"""
@functools.wraps(func)
def decorator(*args):
key = test_support.threading_setup()
try:
return func(*args)
finally:
test_support.threading_cleanup(*key)
return decorator
# Executing the interpreter in a subprocess
def _assert_python(expected_success, *args, **env_vars):
cmd_line = [sys.executable]
if not env_vars:
cmd_line.append('-E')
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
# But a special flag that can be set to override -- in this case, the
# caller is responsible to pass the full environment.
if env_vars.pop('__cleanenv', None):
env = {}
env.update(env_vars)
cmd_line.extend(args)
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
try:
out, err = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
err = strip_python_stderr(err)
if (rc and expected_success) or (not rc and not expected_success):
raise AssertionError(
"Process return code is %d, "
"stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
return rc, out, err
def assert_python_ok(*args, **env_vars):
"""
Assert that running the interpreter with `args` and optional environment
variables `env_vars` is ok and return a (return code, stdout, stderr) tuple.
"""
return _assert_python(True, *args, **env_vars)
def strip_python_stderr(stderr):
"""Strip the stderr of a Python process from potential debug output
emitted by the interpreter.
This will typically be run on the result of the communicate() method
of a subprocess.Popen object.
"""
stderr = re.sub(r"\[\d+ refs\]\r?\n?$".encode(), "".encode(), stderr).strip()
return stderr
@contextlib.contextmanager
def captured_stderr():
"""Return a context manager used by captured_stdout/stdin/stderr
that temporarily replaces the sys stream *stream_name* with a StringIO."""
logging_stream = StringIO()
handler = logging.StreamHandler(logging_stream)
logging.root.addHandler(handler)
try:
yield logging_stream
finally:
logging.root.removeHandler(handler)
def create_future(state=PENDING, exception=None, result=None):
f = Future()
f._state = state
f._exception = exception
f._result = result
return f
PENDING_FUTURE = create_future(state=PENDING)
RUNNING_FUTURE = create_future(state=RUNNING)
CANCELLED_FUTURE = create_future(state=CANCELLED)
CANCELLED_AND_NOTIFIED_FUTURE = create_future(state=CANCELLED_AND_NOTIFIED)
EXCEPTION_FUTURE = create_future(state=FINISHED, exception=IOError())
SUCCESSFUL_FUTURE = create_future(state=FINISHED, result=42)
def mul(x, y):
return x * y
def sleep_and_raise(t):
time.sleep(t)
raise Exception('this is an exception')
def sleep_and_print(t, msg):
time.sleep(t)
print(msg)
sys.stdout.flush()
class ExecutorMixin:
worker_count = 5
def setUp(self):
self.t1 = time.time()
try:
self.executor = self.executor_type(max_workers=self.worker_count)
except NotImplementedError:
e = sys.exc_info()[1]
self.skipTest(str(e))
self._prime_executor()
def tearDown(self):
self.executor.shutdown(wait=True)
dt = time.time() - self.t1
if test_support.verbose:
print("%.2fs" % dt)
self.assertLess(dt, 60, "synchronization issue: test lasted too long")
def _prime_executor(self):
# Make sure that the executor is ready to do work before running the
# tests. This should reduce the probability of timeouts in the tests.
futures = [self.executor.submit(time.sleep, 0.1)
for _ in range(self.worker_count)]
for f in futures:
f.result()
class ThreadPoolMixin(ExecutorMixin):
executor_type = futures.ThreadPoolExecutor
class ProcessPoolMixin(ExecutorMixin):
executor_type = futures.ProcessPoolExecutor
class ExecutorShutdownTest(unittest.TestCase):
def test_run_after_shutdown(self):
self.executor.shutdown()
self.assertRaises(RuntimeError,
self.executor.submit,
pow, 2, 5)
def test_interpreter_shutdown(self):
# Test the atexit hook for shutdown of worker threads and processes
rc, out, err = assert_python_ok('-c', """if 1:
from concurrent.futures import %s
from time import sleep
from test_futures import sleep_and_print
t = %s(5)
t.submit(sleep_and_print, 1.0, "apple")
""" % (self.executor_type.__name__, self.executor_type.__name__))
# Errors in atexit hooks don't change the process exit code, check
# stderr manually.
self.assertFalse(err)
self.assertEqual(out.strip(), "apple".encode())
def test_hang_issue12364(self):
fs = [self.executor.submit(time.sleep, 0.1) for _ in range(50)]
self.executor.shutdown()
for f in fs:
f.result()
class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest):
def _prime_executor(self):
pass
def test_threads_terminate(self):
self.executor.submit(mul, 21, 2)
self.executor.submit(mul, 6, 7)
self.executor.submit(mul, 3, 14)
self.assertEqual(len(self.executor._threads), 3)
self.executor.shutdown()
for t in self.executor._threads:
t.join()
def test_context_manager_shutdown(self):
with futures.ThreadPoolExecutor(max_workers=5) as e:
executor = e
self.assertEqual(list(e.map(abs, range(-5, 5))),
[5, 4, 3, 2, 1, 0, 1, 2, 3, 4])
for t in executor._threads:
t.join()
def test_del_shutdown(self):
executor = futures.ThreadPoolExecutor(max_workers=5)
executor.map(abs, range(-5, 5))
threads = executor._threads
del executor
for t in threads:
t.join()
class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest):
def _prime_executor(self):
pass
def test_processes_terminate(self):
self.executor.submit(mul, 21, 2)
self.executor.submit(mul, 6, 7)
self.executor.submit(mul, 3, 14)
self.assertEqual(len(self.executor._processes), 5)
processes = self.executor._processes
self.executor.shutdown()
for p in processes:
p.join()
def test_context_manager_shutdown(self):
with futures.ProcessPoolExecutor(max_workers=5) as e:
processes = e._processes
self.assertEqual(list(e.map(abs, range(-5, 5))),
[5, 4, 3, 2, 1, 0, 1, 2, 3, 4])
for p in processes:
p.join()
def test_del_shutdown(self):
executor = futures.ProcessPoolExecutor(max_workers=5)
list(executor.map(abs, range(-5, 5)))
queue_management_thread = executor._queue_management_thread
processes = executor._processes
del executor
queue_management_thread.join()
for p in processes:
p.join()
class WaitTests(unittest.TestCase):
def test_first_completed(self):
future1 = self.executor.submit(mul, 21, 2)
future2 = self.executor.submit(time.sleep, 1.5)
done, not_done = futures.wait(
[CANCELLED_FUTURE, future1, future2],
return_when=futures.FIRST_COMPLETED)
self.assertEqual(set([future1]), done)
self.assertEqual(set([CANCELLED_FUTURE, future2]), not_done)
def test_first_completed_some_already_completed(self):
future1 = self.executor.submit(time.sleep, 1.5)
finished, pending = futures.wait(
[CANCELLED_AND_NOTIFIED_FUTURE, SUCCESSFUL_FUTURE, future1],
return_when=futures.FIRST_COMPLETED)
self.assertEqual(
set([CANCELLED_AND_NOTIFIED_FUTURE, SUCCESSFUL_FUTURE]),
finished)
self.assertEqual(set([future1]), pending)
def test_first_exception(self):
future1 = self.executor.submit(mul, 2, 21)
future2 = self.executor.submit(sleep_and_raise, 1.5)
future3 = self.executor.submit(time.sleep, 3)
finished, pending = futures.wait(
[future1, future2, future3],
return_when=futures.FIRST_EXCEPTION)
self.assertEqual(set([future1, future2]), finished)
self.assertEqual(set([future3]), pending)
def test_first_exception_some_already_complete(self):
future1 = self.executor.submit(divmod, 21, 0)
future2 = self.executor.submit(time.sleep, 1.5)
finished, pending = futures.wait(
[SUCCESSFUL_FUTURE,
CANCELLED_FUTURE,
CANCELLED_AND_NOTIFIED_FUTURE,
future1, future2],
return_when=futures.FIRST_EXCEPTION)
self.assertEqual(set([SUCCESSFUL_FUTURE,
CANCELLED_AND_NOTIFIED_FUTURE,
future1]), finished)
self.assertEqual(set([CANCELLED_FUTURE, future2]), pending)
def test_first_exception_one_already_failed(self):
future1 = self.executor.submit(time.sleep, 2)
finished, pending = futures.wait(
[EXCEPTION_FUTURE, future1],
return_when=futures.FIRST_EXCEPTION)
self.assertEqual(set([EXCEPTION_FUTURE]), finished)
self.assertEqual(set([future1]), pending)
def test_all_completed(self):
future1 = self.executor.submit(divmod, 2, 0)
future2 = self.executor.submit(mul, 2, 21)
finished, pending = futures.wait(
[SUCCESSFUL_FUTURE,
CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
future1,
future2],
return_when=futures.ALL_COMPLETED)
self.assertEqual(set([SUCCESSFUL_FUTURE,
CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
future1,
future2]), finished)
self.assertEqual(set(), pending)
def test_timeout(self):
future1 = self.executor.submit(mul, 6, 7)
future2 = self.executor.submit(time.sleep, 3)
finished, pending = futures.wait(
[CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1, future2],
timeout=1.5,
return_when=futures.ALL_COMPLETED)
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1]), finished)
self.assertEqual(set([future2]), pending)
class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests):
def test_pending_calls_race(self):
# Issue #14406: multi-threaded race condition when waiting on all
# futures.
event = threading.Event()
def future_func():
event.wait()
oldswitchinterval = sys.getcheckinterval()
sys.setcheckinterval(1)
try:
fs = set(self.executor.submit(future_func) for i in range(100))
event.set()
futures.wait(fs, return_when=futures.ALL_COMPLETED)
finally:
sys.setcheckinterval(oldswitchinterval)
class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests):
pass
class AsCompletedTests(unittest.TestCase):
# TODO(brian@sweetapp.com): Should have a test with a non-zero timeout.
def test_no_timeout(self):
future1 = self.executor.submit(mul, 2, 21)
future2 = self.executor.submit(mul, 7, 6)
completed = set(futures.as_completed(
[CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1, future2]))
self.assertEqual(set(
[CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1, future2]),
completed)
def test_zero_timeout(self):
future1 = self.executor.submit(time.sleep, 2)
completed_futures = set()
try:
for future in futures.as_completed(
[CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1],
timeout=0):
completed_futures.add(future)
except futures.TimeoutError:
pass
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE]),
completed_futures)
class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests):
pass
class ProcessPoolAsCompletedTests(ProcessPoolMixin, AsCompletedTests):
pass
class ExecutorTest(unittest.TestCase):
# Executor.shutdown() and context manager usage is tested by
# ExecutorShutdownTest.
def test_submit(self):
future = self.executor.submit(pow, 2, 8)
self.assertEqual(256, future.result())
def test_submit_keyword(self):
future = self.executor.submit(mul, 2, y=8)
self.assertEqual(16, future.result())
def test_map(self):
self.assertEqual(
list(self.executor.map(pow, range(10), range(10))),
list(map(pow, range(10), range(10))))
def test_map_exception(self):
i = self.executor.map(divmod, [1, 1, 1, 1], [2, 3, 0, 5])
self.assertEqual(next(i), (0, 1))
self.assertEqual(next(i), (0, 1))
self.assertRaises(ZeroDivisionError, next, i)
def test_map_timeout(self):
results = []
try:
for i in self.executor.map(time.sleep,
[0, 0, 3],
timeout=1.5):
results.append(i)
except futures.TimeoutError:
pass
else:
self.fail('expected TimeoutError')
self.assertEqual([None, None], results)
class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest):
pass
class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest):
pass
class FutureTests(unittest.TestCase):
def test_done_callback_with_result(self):
callback_result = [None]
def fn(callback_future):
callback_result[0] = callback_future.result()
f = Future()
f.add_done_callback(fn)
f.set_result(5)
self.assertEqual(5, callback_result[0])
def test_done_callback_with_exception(self):
callback_exception = [None]
def fn(callback_future):
callback_exception[0] = callback_future.exception()
f = Future()
f.add_done_callback(fn)
f.set_exception(Exception('test'))
self.assertEqual(('test',), callback_exception[0].args)
def test_done_callback_with_cancel(self):
was_cancelled = [None]
def fn(callback_future):
was_cancelled[0] = callback_future.cancelled()
f = Future()
f.add_done_callback(fn)
self.assertTrue(f.cancel())
self.assertTrue(was_cancelled[0])
def test_done_callback_raises(self):
with captured_stderr() as stderr:
raising_was_called = [False]
fn_was_called = [False]
def raising_fn(callback_future):
raising_was_called[0] = True
raise Exception('doh!')
def fn(callback_future):
fn_was_called[0] = True
f = Future()
f.add_done_callback(raising_fn)
f.add_done_callback(fn)
f.set_result(5)
self.assertTrue(raising_was_called)
self.assertTrue(fn_was_called)
self.assertIn('Exception: doh!', stderr.getvalue())
def test_done_callback_already_successful(self):
callback_result = [None]
def fn(callback_future):
callback_result[0] = callback_future.result()
f = Future()
f.set_result(5)
f.add_done_callback(fn)
self.assertEqual(5, callback_result[0])
def test_done_callback_already_failed(self):
callback_exception = [None]
def fn(callback_future):
callback_exception[0] = callback_future.exception()
f = Future()
f.set_exception(Exception('test'))
f.add_done_callback(fn)
self.assertEqual(('test',), callback_exception[0].args)
def test_done_callback_already_cancelled(self):
was_cancelled = [None]
def fn(callback_future):
was_cancelled[0] = callback_future.cancelled()
f = Future()
self.assertTrue(f.cancel())
f.add_done_callback(fn)
self.assertTrue(was_cancelled[0])
def test_repr(self):
self.assertRegexpMatches(repr(PENDING_FUTURE),
'<Future at 0x[0-9a-f]+ state=pending>')
self.assertRegexpMatches(repr(RUNNING_FUTURE),
'<Future at 0x[0-9a-f]+ state=running>')
self.assertRegexpMatches(repr(CANCELLED_FUTURE),
'<Future at 0x[0-9a-f]+ state=cancelled>')
self.assertRegexpMatches(repr(CANCELLED_AND_NOTIFIED_FUTURE),
'<Future at 0x[0-9a-f]+ state=cancelled>')
self.assertRegexpMatches(
repr(EXCEPTION_FUTURE),
'<Future at 0x[0-9a-f]+ state=finished raised IOError>')
self.assertRegexpMatches(
repr(SUCCESSFUL_FUTURE),
'<Future at 0x[0-9a-f]+ state=finished returned int>')
def test_cancel(self):
f1 = create_future(state=PENDING)
f2 = create_future(state=RUNNING)
f3 = create_future(state=CANCELLED)
f4 = create_future(state=CANCELLED_AND_NOTIFIED)
f5 = create_future(state=FINISHED, exception=IOError())
f6 = create_future(state=FINISHED, result=5)
self.assertTrue(f1.cancel())
self.assertEqual(f1._state, CANCELLED)
self.assertFalse(f2.cancel())
self.assertEqual(f2._state, RUNNING)
self.assertTrue(f3.cancel())
self.assertEqual(f3._state, CANCELLED)
self.assertTrue(f4.cancel())
self.assertEqual(f4._state, CANCELLED_AND_NOTIFIED)
self.assertFalse(f5.cancel())
self.assertEqual(f5._state, FINISHED)
self.assertFalse(f6.cancel())
self.assertEqual(f6._state, FINISHED)
def test_cancelled(self):
self.assertFalse(PENDING_FUTURE.cancelled())
self.assertFalse(RUNNING_FUTURE.cancelled())
self.assertTrue(CANCELLED_FUTURE.cancelled())
self.assertTrue(CANCELLED_AND_NOTIFIED_FUTURE.cancelled())
self.assertFalse(EXCEPTION_FUTURE.cancelled())
self.assertFalse(SUCCESSFUL_FUTURE.cancelled())
def test_done(self):
self.assertFalse(PENDING_FUTURE.done())
self.assertFalse(RUNNING_FUTURE.done())
self.assertTrue(CANCELLED_FUTURE.done())
self.assertTrue(CANCELLED_AND_NOTIFIED_FUTURE.done())
self.assertTrue(EXCEPTION_FUTURE.done())
self.assertTrue(SUCCESSFUL_FUTURE.done())
def test_running(self):
self.assertFalse(PENDING_FUTURE.running())
self.assertTrue(RUNNING_FUTURE.running())
self.assertFalse(CANCELLED_FUTURE.running())
self.assertFalse(CANCELLED_AND_NOTIFIED_FUTURE.running())
self.assertFalse(EXCEPTION_FUTURE.running())
self.assertFalse(SUCCESSFUL_FUTURE.running())
def test_result_with_timeout(self):
self.assertRaises(futures.TimeoutError,
PENDING_FUTURE.result, timeout=0)
self.assertRaises(futures.TimeoutError,
RUNNING_FUTURE.result, timeout=0)
self.assertRaises(futures.CancelledError,
CANCELLED_FUTURE.result, timeout=0)
self.assertRaises(futures.CancelledError,
CANCELLED_AND_NOTIFIED_FUTURE.result, timeout=0)
self.assertRaises(IOError, EXCEPTION_FUTURE.result, timeout=0)
self.assertEqual(SUCCESSFUL_FUTURE.result(timeout=0), 42)
def test_result_with_success(self):
# TODO(brian@sweetapp.com): This test is timing dependant.
def notification():
# Wait until the main thread is waiting for the result.
time.sleep(1)
f1.set_result(42)
f1 = create_future(state=PENDING)
t = threading.Thread(target=notification)
t.start()
self.assertEqual(f1.result(timeout=5), 42)
def test_result_with_cancel(self):
# TODO(brian@sweetapp.com): This test is timing dependant.
def notification():
# Wait until the main thread is waiting for the result.
time.sleep(1)
f1.cancel()
f1 = create_future(state=PENDING)
t = threading.Thread(target=notification)
t.start()
self.assertRaises(futures.CancelledError, f1.result, timeout=5)
def test_exception_with_timeout(self):
self.assertRaises(futures.TimeoutError,
PENDING_FUTURE.exception, timeout=0)
self.assertRaises(futures.TimeoutError,
RUNNING_FUTURE.exception, timeout=0)
self.assertRaises(futures.CancelledError,
CANCELLED_FUTURE.exception, timeout=0)
self.assertRaises(futures.CancelledError,
CANCELLED_AND_NOTIFIED_FUTURE.exception, timeout=0)
self.assertTrue(isinstance(EXCEPTION_FUTURE.exception(timeout=0),
IOError))
self.assertEqual(SUCCESSFUL_FUTURE.exception(timeout=0), None)
def test_exception_with_success(self):
def notification():
# Wait until the main thread is waiting for the exception.
time.sleep(1)
with f1._condition:
f1._state = FINISHED
f1._exception = IOError()
f1._condition.notify_all()
f1 = create_future(state=PENDING)
t = threading.Thread(target=notification)
t.start()
self.assertTrue(isinstance(f1.exception(timeout=5), IOError))
@reap_threads
def test_main():
try:
test_support.run_unittest(ProcessPoolExecutorTest,
ThreadPoolExecutorTest,
ProcessPoolWaitTests,
ThreadPoolWaitTests,
ProcessPoolAsCompletedTests,
ThreadPoolAsCompletedTests,
FutureTests,
ProcessPoolShutdownTest,
ThreadPoolShutdownTest)
finally:
test_support.reap_children()
if __name__ == "__main__":
test_main()

View file

@ -1,8 +0,0 @@
[tox]
envlist = py26,py27,py31
[testenv]
commands={envpython} test_futures.py []
[testenv:py26]
deps=unittest2

@ -1 +0,0 @@
Subproject commit 33735480f77891754304e7f13e3cdf83aaaa76aa

@ -1 +0,0 @@
Subproject commit 98712e7d0f6be2a090b6fda2a925f85e63656b58

View file

@ -1,80 +0,0 @@
#!/usr/bin/env python
#
# Copyright 2012 by Jeff Laughlin Consulting LLC
#
# 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:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# 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.
import sys
from time import sleep
# Source: https://gist.github.com/n1ywb/2570004
def example_exc_handler(tries_remaining, exception, delay):
"""Example exception handler; prints a warning to stderr.
tries_remaining: The number of tries remaining.
exception: The exception instance which was raised.
"""
print >> sys.stderr, "Caught '%s', %d tries remaining, sleeping for %s seconds" % (exception, tries_remaining, delay)
def retries(max_tries, delay=1, backoff=2, exceptions=(Exception,), hook=None):
"""Function decorator implementing retrying logic.
delay: Sleep this many seconds * backoff * try number after failure
backoff: Multiply delay by this factor after each failure
exceptions: A tuple of exception classes; default (Exception,)
hook: A function with the signature myhook(tries_remaining, exception);
default None
The decorator will call the function up to max_tries times if it raises
an exception.
By default it catches instances of the Exception class and subclasses.
This will recover after all but the most fatal errors. You may specify a
custom tuple of exception classes with the 'exceptions' argument; the
function will only be retried if it raises one of the specified
exceptions.
Additionally you may specify a hook function which will be called prior
to retrying with the number of remaining tries and the exception instance;
see given example. This is primarily intended to give the opportunity to
log the failure. Hook is not called after failure if no retries remain.
"""
def dec(func):
def f2(*args, **kwargs):
mydelay = delay
tries = range(max_tries)
tries.reverse()
for tries_remaining in tries:
try:
return func(*args, **kwargs)
except exceptions as e:
if tries_remaining > 0:
if hook is not None:
hook(tries_remaining, e, mydelay)
sleep(mydelay)
mydelay = mydelay * backoff
else:
raise
else:
break
return f2
return dec

@ -1 +0,0 @@
Subproject commit 0f2d919d55f2bb94b70db8d75302c8a07a741a88

@ -0,0 +1 @@
Subproject commit 2376d1233e7d1db8157fdc3157278dda7a2c796f

@ -0,0 +1 @@
Subproject commit 0c5612fa31ee434ba055e21c76f456244b3b5109