[READY] Do not cache Python interpreter path
Once YCM is installed through a plugin manager in Vim (e.g. using the `:PluginInstall` command with Vundle), it picks a Python interpreter (most likely the one used to run YCM inside Vim), caches it, and starts the server with it. This fails since the `ycm_core` library is not yet compiled and the following message is displayed on the status line:
```
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation.
```
After reading the documentation, the user may then build the library directly from Vim:
```
:!/path/to/YCM/install.py
```
or by opening a new terminal and calling the `install.py` script without leaving Vim. Once the compilation is done, he will restart the server with the `:YcmRestartServer` command. However, since the Python interpreter used to start the server is already cached, YCM will not pick the one from the `PYTHON_USED_DURING_BUILDING` file generated by the `install.py` script. If these Pythons are different (e.g. Python 2 versus Python 3), YCM will fail to start the server again. This doesn't happen if we don't cache the Python interpreter path.
I suspect this is the issue experienced in #2431 and often reported by users on Ubuntu 16.04 where Vim is compiled with Python 3 support but default Python is Python 2. See https://github.com/Valloric/YouCompleteMe/pull/2140#issuecomment-273495342 and https://github.com/Valloric/YouCompleteMe/issues/35#issuecomment-290877053.
Fixes#2431.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2598)
<!-- Reviewable:end -->
[READY] Split the OnBufferVisit function again
We can't use `VisitedBufferRequiresReparse` for the `FileType` autocommand event because ycmd may parse a buffer differently depending on its filetype. We have to use `AllowedToCompleteInCurrentBuffer` for this event (we can also use it for the `BufRead` one).
Fixes https://github.com/Valloric/ycmd/issues/731.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2595)
<!-- Reviewable:end -->
Send extra_conf_vim_data in requests from :YcmCompleter and :YcmDebugInfo commands
Send extra_conf_vim_data in requests from :YcmCompleter and :YcmDebugInfo commands. It's needed for passing compile_commands.json directory to every call of FlagsForFile in client_data argument.
# PR Prelude
Thank you for working on YCM! :)
**Please complete these steps and check these boxes (by putting an `x` inside
the brackets) _before_ filing your PR:**
- [ x] I have read and understood YCM's [CONTRIBUTING][cont] document.
- [ x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- [ x] I have included tests for the changes in my PR. If not, I have included a
rationale for why I haven't.
- [x ] **I understand my PR may be closed if it becomes obvious I didn't
actually perform all of these steps.**
# Why this change is necessary and useful
Directory of compile_commands.json may be different for different configurations. And there is needed a way for passing it to every call of FlagsForFile in client_data argument.
[Please explain **in detail** why the changes in this PR are needed.]
[cont]: https://github.com/Valloric/YouCompleteMe/blob/master/CONTRIBUTING.md
[code]: https://github.com/Valloric/YouCompleteMe/blob/master/CODE_OF_CONDUCT.md
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2570)
<!-- Reviewable:end -->
[READY] Prioritize errors over warnings on the same line
When multiple diagnostics are on the same line, warnings may have higher priority than errors. See #2141 for an example. This happens for several reasons:
- we sort diagnostics by column and then by kind. We should do the opposite;
- we place all signs; each sign overriding the previous one. Since only one sign is visible by line, we should just insert the first one (which has the highest priority);
- we draw highlighting matches (squiggles) in the same order as diagnostics; each match being drawn over the previous ones. We should draw them in reverse order (from lowest to highest priority).
Fixes#2141.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2592)
<!-- Reviewable:end -->
[READY] Merge back OnBufferRead and OnBufferEnter into OnBufferVisit
PR #2312 introduced an issue where the `completeopt`, `completefunc`, and `omnifunc` options are not set for buffers opened before the plugin is loaded. The `OnBufferVisit` function was split into `OnBufferRead` and `OnBufferEnter` but `SetUpCompleteopt`, `SetCompleteFunc`, and `SetOmnicompleteFunc` were not copied to `OnBufferEnter`.
Since the result of `VisitedBufferRequiresReparse` is identical to `AllowedToCompleteInCurrentBuffer` for a new buffer (its buffer number is necessarily new), we merge back the two functions into `OnBufferVisit` to fix the issue. Also, we change the `DisableOnLargeFile` function to include it in `AllowedToCompleteInCurrentBuffer`. This reduces duplication of code.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2589)
<!-- Reviewable:end -->
[READY] Accept capitalized name for Python executable
I was looking at `PathToPythonInterpreter` coverage and was surprised to see [that line](
01570aac03/python/ycm/paths.py (L84)) covered. This shouldn't be the case since we are supposed to use the Python from `PYTHON_USED_DURING_BUILDING`. This happens because the Python executable used in our Travis builds on macOS is named `Python` (with a capital letter) and so we don't accept it.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2590)
<!-- Reviewable:end -->
[READY] Remove Python version check
Even with the `-S` option (see PR https://github.com/Valloric/YouCompleteMe/pull/2502), starting the Python interpreter to check its version can be slow. For instance, on my machine (in PowerShell):
```ps
> Measure-Command -Expression {python -S -c "pass"}
...
TotalMilliseconds : 25,4387
```
It's also not particularly useful because, in the typical case, the Python used to start ycmd will be the one from `PYTHON_USED_DURING_BUILDING` which is necessarily a supported version. In the cases where the `g:ycm_server_python_interpreter` option is specified or a Python is found in the PATH, it's up to the user to provide a supported version. If they don't, the ycmd server will probably fail to start and the following error will be displayed to them:
```
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). Unexpected exit code 1. Use the ':YcmToggleLogs' command to check the logs.
```
They can then look at the logs to understand what went wrong.
Finally, the last case is when the Python is the one used by YCM itself. In that case, if the Python version is not supported, it will fail before doing the check so it doesn't matter.
As always, here are the improvements on startup time:
<table>
<tr>
<th rowspan="2">Platform</th>
<th colspan="2">First run (ms)</th>
<th colspan="2">Subsequent runs (ms)</th>
</tr>
<tr>
<td>Before</td>
<td>After</td>
<td>Before</td>
<td>After</td>
</tr>
<tr>
<td>Ubuntu 16.04 64-bit</td>
<td>147</td>
<td>134</td>
<td>74</td>
<td>65</td>
</tr>
<tr>
<td>macOS 10.12</td>
<td>189</td>
<td>165</td>
<td>127</td>
<td>107</td>
</tr>
<tr>
<td>Windows 10 64-bit</td>
<td>242</td>
<td>200</td>
<td>147</td>
<td>115</td>
</tr>
</table>
*Results obtained by running the `prof.py` script from [this branch](https://github.com/micbou/YouCompleteMe/tree/profiling-startup) on Python 3.6.*
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2585)
<!-- Reviewable:end -->
Typescript diagnostics
# PR Prelude
Thank you for working on YCM! :)
**Please complete these steps and check these boxes (by putting an `x` inside
the brackets) _before_ filing your PR:**
- [x] I have read and understood YCM's [CONTRIBUTING][cont] document.
- [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- [x] I have included tests for the changes in my PR. If not, I have included a
rationale for why I haven't.
- [x] **I understand my PR may be closed if it becomes obvious I didn't
actually perform all of these steps.**
# Why this change is necessary and useful
This just makes use of [these changes](https://github.com/Valloric/ycmd/pull/718) to ycmd.
It adds TypeScript to the list of filetypes that diagnostics are supported for and reflects that in the README. (And updates ycmd.)
No tests are included, since the only code that changed is the hard-coded list of filetypes. The new ycmd functionality is tested in that project.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2584)
<!-- Reviewable:end -->
Indents added in Ubuntu and Fedora sections
# PR Prelude
Thank you for working on YCM! :)
**Please complete these steps and check these boxes (by putting an `x` inside
the brackets) _before_ filing your PR:**
- [x] I have read and understood YCM's [CONTRIBUTING][cont] document.
- [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- [x] I have included tests for the changes in my PR. If not, I have included a
rationale for why I haven't.
- [x] **I understand my PR may be closed if it becomes obvious I didn't
actually perform all of these steps.**
# Why this change is necessary and useful
Indents added in Ubuntu section (for easier copy&pasting).
PS. Tests are not included - minor documentation change.
[cont]: https://github.com/Valloric/YouCompleteMe/blob/master/CONTRIBUTING.md
[code]: https://github.com/Valloric/YouCompleteMe/blob/master/CODE_OF_CONDUCT.md
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2565)
<!-- Reviewable:end -->
[READY] Prefer Python 3 over Python 2
When both versions are available, we should use Python 3 over Python 2 for the following reasons:
- faster startup:
<table>
<tr>
<th rowspan="2">Platform</th>
<th colspan="2">First run (ms)</th>
<th colspan="2">Subsequent runs (ms)</th>
</tr>
<tr>
<td>Python 2</td>
<td>Python 3</td>
<td>Python 2</td>
<td>Python 3</td>
</tr>
<tr>
<td>Ubuntu 16.04 64-bit</td>
<td>197</td>
<td>110</td>
<td>117</td>
<td>84</td>
</tr>
<tr>
<td>macOS 10.12</td>
<td>322</td>
<td>186</td>
<td>210</td>
<td>124</td>
</tr>
<tr>
<td>Windows 10 64-bit</td>
<td>601</td>
<td>295</td>
<td>251</td>
<td>144</td>
</tr>
</table>
*Results obtained by running the `prof.py` script from [this branch](https://github.com/micbou/YouCompleteMe/tree/profiling-startup). The difference between first run and subsequent runs is Python bytecode generation (`*.pyc` files).*
These differences are due to `python-future` monkey-patching a lot of stuff on Python 2 but not on Python 3;
- better Windows support. For instance, [the `tempfile` module returns temporary paths in all lowercase on Python 2](https://bugs.python.org/issue14255) (we use it to create our logfiles). This is fixed on Python 3.
- [Python 2 support will be dropped in 2020](https://docs.python.org/devguide/index.html#branchstatus).
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2566)
<!-- Reviewable:end -->
When both versions are available, we prefer Python 3 over Python 2:
- faster startup (no monkey-patching from python-future);
- better Windows support (e.g. temporary paths are not returned in all
lowercase);
- Python 2 support will eventually be dropped.
[READY] Always defer loading at VimEnter
YCM should start the same whether Vim is running in GUI or not. Otherwise, this makes it difficult for other plugins to interact with YCM at startup because they can't predict how YCM will start unless they also check if Vim is running in GUI which is unreasonable. Since we can't load it at Vim startup because of [a deadlock issue](https://github.com/Valloric/YouCompleteMe/pull/2473#issuecomment-267716136), we should always defer it at the VimEnter event.
See discussion in 39659caf34 for more details.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2561)
<!-- Reviewable:end -->
[READY] Import the requests module lazily
The requests module is slow to import. See https://github.com/kennethreitz/requests/issues/3213. We should lazy load it to improve startup time. We do that by adding two methods to the `BaseRequest` class: one that returns the requests module and another the session object since it depends on the `request-futures` module and `requests-futures` imports `requests`. In addition, we make sure that no requests are sent at startup otherwise there would be no point to lazy load these. These requests would fail anyway since the server can't be ready yet.
Here are the improvements on startup time:
<table>
<tr>
<th rowspan="2">Platform</th>
<th colspan="2">First run (ms)</th>
<th colspan="2">Subsequent runs (ms)</th>
</tr>
<tr>
<td>Before</td>
<td>After</td>
<td>Before</td>
<td>After</td>
</tr>
<tr>
<td>Ubuntu 16.04 64-bit</td>
<td>240</td>
<td>131</td>
<td>173</td>
<td>74</td>
</tr>
<tr>
<td>macOS 10.12</td>
<td>435</td>
<td>315</td>
<td>261</td>
<td>208</td>
</tr>
<tr>
<td>Windows 10 64-bit</td>
<td>894</td>
<td>594</td>
<td>359</td>
<td>247</td>
</tr>
</table>
*Results obtained by running the `prof.py` script from [this branch](https://github.com/micbou/YouCompleteMe/tree/profiling-startup). The difference between first run and subsequent runs is Python bytecode generation (`*.pyc` files).*
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2563)
<!-- Reviewable:end -->
YCM should start the same whether Vim is running in GUI or not. Otherwise, this
makes it difficult for other plugins to interact with YCM at startup because
they can't predict how YCM will start unless they also check if Vim is running
in GUI which is unreasonable. Since we can't load it at Vim startup because of
a deadlock issue, we should always defer it at the VimEnter event.
[READY] Refactor diagnostic commands
This PR moves the logic of the `YcmDiags` and `YcmForceCompileAndDiagnostics` commands to the Python layer. It replaces the `echo` calls by `PostVimMessage` ones to display message on the status line and it always prints `Diagnostics refreshed` once compilation is done. This has the benefit of clearing the message `Forcing compilation, this will block Vim until done.` and avoiding the `Press Enter or type command to continue` prompt.
This also adds the `YcmLocationOpened` autocommand which is the same as `YcmQuickFixOpened` but for the location list window.
Fixes#2543.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2548)
<!-- Reviewable:end -->