Commit Graph

451 Commits

Author SHA1 Message Date
micbou
4835b49a89 Remove interpreter line from Python sources 2016-02-05 16:24:03 +01:00
Homu
1201115141 Auto merge of #1927 - micbou:event-notification-test, r=Valloric
[READY] Fix issue in EventNotification tests

While I was reviewing PR #1905, I found an issue with the `EventNotification` tests. It's easy to reproduce. You just need to comment [this line in `python/ycm/youcompleteme.py`](https://github.com/Valloric/YouCompleteMe/blob/master/python/ycm/youcompleteme.py#L508) and run the tests. With this change, the `EventNotification` tests should fail since the second call of `ValidateParseRequest` re-raises the warning. However, tests are still passing because `assert_has_calls` does not check if a call was not made. For example, if `functionA` is called twice, both `assert_has_calls( [ functionA ] )` and `assert_has_calls( [ functionA, functionA ] )` are successful.

To fix this, we just need to check the number of calls using `call_count`. This is done by creating a subclass of `MagicMock` implementing the `assert_has_exact_calls` method and using it in tests.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1927)
<!-- Reviewable:end -->
2016-01-25 08:26:15 +09:00
Homu
8d5f164feb Auto merge of #1896 - micbou:path-to-python-interpreter, r=Valloric
[READY] Implement new strategy to find the Python interpreter path

See discussion in issue #1891 for details.

Implement a new strategy to find the Python interpreter path:
  - if specified, use `g:ycm_path_to_python_interpreter` option.
  - on UNIX platforms, use `sys.executable` as the path to Python interpreter;
  - on Windows, deduce it from `os.__file__` path (it should always be in the parent folder).

In all cases, check the version (2.6 or 2.7) of the Python interpreter path by running it.

This PR may break things. It needs thorough testing.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1896)
<!-- Reviewable:end -->
2016-01-25 08:24:34 +09:00
micbou
a0943d5d31 Fall back to Python search in PATH 2016-01-23 16:59:13 +01:00
micbou
c92b4ac0ff Fix issue in EventNotification tests
assert_has_calls is not enough to check if a call didn't raise a
warning. We also need to check the number of calls. This is done by
creating a subclass of MagicMock implementing the
assert_has_exact_calls method.
2016-01-21 03:05:15 +01:00
Spencer G. Jones
c2d473c4ba Add missing implementation on OmniCompletionRequest
OmniCompletionRequest is missing the RawResponse method, so any attempt to call
it calls the base class method instead. However, since the data structures of
this class and base class are different, this causes an error.
2016-01-16 11:36:58 -07:00
Homu
ea3e207643 Auto merge of #1899 - oblitum:empty-insertion-text, r=oblitum
Allows empty insertion text.

This is useful for hints for example, whose purpose is information
display solely.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1899)
<!-- Reviewable:end -->
2016-01-13 11:24:41 +09:00
Francisco Lopes
9fdd465c26 Allows empty insertion text.
This is useful for hints for example, whose purpose is information
display solely.
2016-01-12 21:48:06 -02:00
Spencer G. Jones
1f868a8b47 fixup! Don't cache invalid completer check results 2016-01-12 15:15:29 -07:00
micbou
9a27c990db Fix typo in test 2016-01-12 22:51:15 +01:00
micbou
1cdbe4a770 Add python3 failing tests 2016-01-12 22:48:48 +01:00
micbou
a80846e35d Check Python interpreter pathname
Rename CheckPythonVersion to IsPythonVersionCorrect.
In embedders, sys.executable may contain a Vim path instead of a Python
one. To avoid starting a Vim instance in this case, we check that given
path ends with a Python 2.6 or 2.7 name using a regex.
Add tests for this regex.
2016-01-12 22:36:31 +01:00
Spencer G. Jones
e57178da00 Don't cache invalid completer check results
If the check for available completers isn't run because the server isn't
alive, or the check request erred or times out, don't cache the result. Only
cache valid returns.
2016-01-12 11:58:18 -07:00
micbou
c7e32b3600 Implement new strategy to find Python path 2016-01-12 01:56:29 +01:00
Homu
f8b3d6643c Auto merge of #1875 - micbou:server-crash-message, r=puremourning
[READY] Update notifications when ycmd server crashed

Instead of printing the last 30 lines of the `stderr` logfile if the server crashed, we tell the user to run the `:YcmToggleLogs stderr` command to check the logs.

Remove `SERVER_CRASH_MESSAGE_SAME_STDERR` message because we are always using the `stderr` logfile since PR #1753. Also, console ouput cannot be used to see the logs.

Simplify `_NotifyUserIfServerCrashed` method by using `CheckFilename` function from `vimsupport` module.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1875)
<!-- Reviewable:end -->
2016-01-12 05:15:22 +09:00
Ben Jackson
134b06b65e Fix GoTo lists arriving at the wrong column.
Vim's QuickFix lists require 1-based columns, which is what is returned
from ycmd's commands.

 As noted in the comments, the Vim documentation for setqflist is
somewhat vague about this "byte offset", but it is confirmed to mean
"1-based column number" both in testing and in :help getqflist.
2016-01-04 23:04:13 +00:00
micbou
7fda494026 Add quotes in notifications
Add quotes for Vim commands and options in notifications.
2016-01-03 12:13:00 +01:00
micbou
da095cb93b Update notifications when ycmd server crashed
Tell the user to run the YcmToggleLogs command if the server crashed.
2016-01-02 21:16:00 +01:00
micbou
f015d518a3 Fix traceback when v:completed_item is empty
Check if the Vim variable v:completed_item is not empty before
accessing one of its keys. Prevent a traceback when the ycmd server
crashed.
2015-12-27 18:46:05 +01:00
Ben Jackson
0b07b7467d Add tests for YouCompleteMe.ValidateParseRequest
Most of the code is mocking boilerplate but it shows that the behaviour is as
defined in the comments.
2015-12-24 21:06:44 +00:00
Ben Jackson
6029a672ee Prevent postcomplete_tests.py from leaving mock object lying around
Previously, running postcomplete_tests.py could lead to MagicMock objects being
left around within the ycm modules. This lead to random test failures in other
modules.

Further, by using mock.patch appropriately, tests withing postcomplete_tests.py
no longer rely on mocking performed by previous tests (and can be successfully
run individually)
2015-12-21 19:38:56 +00:00
Ben Jackson
861546fac0 Display errors raised by OnFileReadyToParse in non-diagnostics filetypes 2015-12-20 17:27:17 +00:00
Homu
14083d939d Auto merge of #1821 - micbou:ycm-issue-1818, r=vheon
Set buffer filetypes for UltiSnips

Currently, only `all` snippets are displayed by YCM because UltiSnips is called without setting the buffer filetypes. See issue #1818.

This is fixed by using UltiSnips methods `reset_buffer_filetypes` and `add_buffer_filetypes`.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1821)
<!-- Reviewable:end -->
2015-12-11 02:55:11 +09:00
micbou
aa73ea0175 Set buffer filetypes for UltiSnips
This fixes #1818.
2015-12-10 00:20:25 +01:00
Kenny Kaye
163238992c Document YcmGetErrorCount and YcmGetWarningCount functions 2015-12-05 09:12:28 -08:00
Kenny Kaye
dafc36ba37 Expose functions to get error and warning counts 2015-12-04 14:45:11 -08:00
micbou
37f3f1530e Handle scalar response from subcommands
When the ycmd server returns a scalar (boolean, number, string, etc.)
from a subcommand, print it to the user.
2015-11-29 20:03:02 +01:00
micbou
13aeaa37a8 Handle boolean responses from ycmd
Fix ServerReady, ServerRunning, and ServerTerminated subcommands from
C♯ completer.
2015-11-28 16:48:24 +01:00
micbou
6f36c3ff82 Improve :YcmToggleLogs behavior
If already opened logfiles are not visible (hidden buffers or in another
tab), close them and open new ones. It fixes the issue where the command
seems to do nothing even though it actually close the non-visible logfiles.
2015-11-11 14:32:01 +01:00
micbou
2eb75ced81 Update buffers-related tests
Mock buffers as a list of buffers where each buffer is represented
as a dictionary containing its filename, its number, and optionally
its associated window.
Test buffer visibility instead of existence.
Mock Vim wipeout command.
Refactor Vim mocks.
2015-11-11 14:18:26 +01:00
micbou
cbe3e04745 Add :YcmToggleLogs command 2015-11-08 18:43:52 +01:00
micbou
f23cbae2a8 Add tests for Vim file and buffer operations
Refactor Vim mocking.
2015-11-08 18:43:52 +01:00
micbou
186aa6b671 Remove g:ycm_server_use_vim_stdout option
This option does not work like expected. Logs are not written to the
console. It also makes the ycmd server unresponsive on Windows.
2015-10-27 18:19:22 +01:00
Davit Samvelyan
cb3325970e Refactoring 2015-10-14 11:37:33 +04:00
Davit Samvelyan
a0495a994e Fix for rare crash when trying to jump to file which has .swp 2015-10-13 18:46:20 +04:00
micbou
87854f0245 Move PathToPythonInterpreter function to YCM
Create a module for paths.
2015-10-09 18:53:24 +02:00
Ben Jackson
958d8f1eb5 Support subcommands which return detailed info
We display the detailed info text in the preview window. Vim's preview window is
designed to display actual files, not scratch data. Our approach is to open a
temporary file, even though that file is never written. This way, all of Vim's
existing settings for the preview window (and people's configured mappings) just
work. This is also consistent with showing the documentation in the preview
window during completion.

Other plugins have more complicated functions for this (such as eclim), or
Scratch.vim, but this approach is simple and doesn't require external
dependencies or additional settings.

Tests:

This required fixing a sort-of-bug in which the mock'd Vim module was always
only set once, and could not be changed outside of the module which created it.
This meant that it wasn't easy to have arbitrary tests, because it was dependent
on the order in which the tests execute as to whether the return from
MockVimModule() was actually the one in use.

The solution was to make the mock'd vim module a singleton, and use mock's
patch decorator to assign new MagicMock() instances to those methods in the vim
module which a particular test is interested in.
2015-09-20 21:30:23 +01:00
Spencer G. Jones
bb21150798 Fix merge test failure 2015-09-13 08:57:09 -06:00
Spencer G. Jones
2a41101955 Merge remote-tracking branch 'origin/master' into CsAddImport 2015-09-13 08:49:28 -06:00
Homu
a4f7d02a3b Auto merge of #1676 - micbou:fix-it-chunks-sorting, r=Valloric
Correct FixIt chunks sorting

While playing with FixIts in C++, I found the following issue. When fixing the third line in the code:
```cpp
template<int Value> struct CT { template<typename> struct Inner; };

CT<10 >> 2> ct; // expected-warning{{require parentheses}}
```
the following result is obtained:
```cpp
CT<1(0 >> 2)> ct; // expected-warning{{require parentheses}}
```
which is obviously wrong.

The issue is YouCompleteMe does not replace the chunks in the right order. It starts by adding the closing parenthesis, add one to the delta and inserts the opening parenthesis in the wrong place cause of the delta.

We actually use the expression `str(line) + ',' + str(column)` to sort the chunks by line then column whereas it should simply be `(line, column)`.

This PR fixes this issue, adds two tests which are failing in the current version, refactors the `_HandleFixitResponse` function and cleans up code.
2015-09-13 13:48:54 +09:00
Ben Jackson
5cfd6376c6 Show docs from clang completer in preview window
We add the detailed_info (which is the function definiton)
followed by the brief comment
2015-09-12 20:51:04 +01:00
micbou
8c17995bee Correct FixIt chunks sorting 2015-09-12 18:14:06 +02:00
micbou
17f5f20cd6 Add chunks sorting tests 2015-09-12 18:14:05 +02:00
micbou
2c72a3c598 Clean code in vimsupport tests 2015-09-12 18:14:04 +02:00
micbou
33316d8bf8 Refactor _HandleFixitResponse function 2015-09-12 18:13:54 +02:00
Spencer G. Jones
28e318c0bb fixup! To determine which completion prompted CompleteDone, look at the new variable if vim is recent enough. 2015-09-10 09:18:48 -06:00
Spencer G. Jones
af4aaa1d17 fixup! To determine which completion prompted CompleteDone, look at the new variable if vim is recent enough. 2015-09-09 09:08:41 -06:00
Spencer G. Jones
9f134c4dd0 To determine which completion prompted CompleteDone, look at the new variable if vim is recent enough. 2015-09-09 08:27:15 -06:00
Spencer G. Jones
9f568be39a fixup! Add CompleteDone hook, with namespace insertion for C# 2015-08-31 10:51:23 -06:00
Spencer G. Jones
dd27184970 Add CompleteDone hook, with namespace insertion for C#
Add a new vim hook on CompleteDone. This hook is called when a
completions is selected.

When forcing semantic completion with the keybind, C# completions can
return a list of importable types. These types are from namespaces which
havn't been imported, and thus are not valid to use without also adding
their namespace's import statement. This change makes YCM automatically
insert the necessary using statement to import that namespace on
completion completion. In the case there are multiple possible
namespaces, it prompts you to choose one.
2015-08-28 10:05:46 -06:00