Commit Graph

164 Commits

Author SHA1 Message Date
Ben Jackson
dc52b73048 Don't open the quickfix window after fixit 2018-02-22 23:02:10 +00:00
zzbot
54a4ecf2d9
Auto merge of #2922 - micbou:improve-diagnostic-match, r=bstaletic
[READY] Improve diagnostic matches display

There are two issues with how we display diagnostic matches. The first issue is that if the current buffer contains diagnostic matches and is split in a new window, all the matches are cleared and only matches in the new window are shown. The second issue is that if a new buffer with no diagnostic support is open in the current window and that window already contained matches then the matches are still displayed. Here's an illustration of both issues (signs are disabled):

![diagnostic-matches-issue](https://user-images.githubusercontent.com/10026824/36352338-bfeb2092-14b7-11e8-88f4-ae8cf6903304.gif)

The solution is to add an autocommand that updates matches on the `BufEnter` and `WinEnter` events. Here's the result:

![diagnostic-matches-fix](https://user-images.githubusercontent.com/10026824/36352340-c2a64a8c-14b7-11e8-8db2-4f1f54448c65.gif)

Note that it's not perfect as multiple windows of the same buffer won't be updated simultaneously. Supporting that scenario is rather tricky because we would need to go through all the windows to update the matches and switching windows can lead to a lot of issues (like interrupting visual mode) so we don't.

This PR also improves how we update matches by only displaying matches that are not already present and then clearing the remaining ones (similarly to what we do with signs; see PR https://github.com/Valloric/YouCompleteMe/pull/2915) instead of always clearing all the matches then displaying the new ones.

<!-- 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/2922)
<!-- Reviewable:end -->
2018-02-18 17:15:46 -08:00
micbou
c84e70737c
Improve diagnostic matches display 2018-02-18 21:32:00 +01:00
micbou
b182556804
Add function to capture Vim command output 2018-02-18 14:06:09 +01:00
micbou
5e98da5b09
Improve diagnostic sign placement 2018-02-18 10:46:19 +01:00
zzbot
02f117035e
Auto merge of #2910 - micbou:fix-typo-tests, r=puremourning
[READY] Fix typo in tests name

`:%s/YouCompelteMe/YouCompleteMe`.

<!-- 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/2910)
<!-- Reviewable:end -->
2018-02-12 13:06:31 -08:00
micbou
8ab3f73b4d
Fix typo in tests name 2018-02-12 02:03:05 +01:00
micbou
a13329fe94
Add range support to completer command 2018-02-12 01:50:08 +01:00
Ben Jackson
7989b7b0fd Support for additional FixIts on java completions
Java completer can include FixIts which are applied when a completion
entry is selected. We use the existing mechanism implemented for c-sharp
to perform these edits using the CompleteDone autocommand.

However, the existing mechanism relies on pattern matching the source to
work out which item was completed. Vim patch 8.0.1493 introduces support
for user_data on completion items, so when available we populate it with
the completion array index of the item and use that to get the exact
element that was selected. This is both a lot faster and a lot more
accirate.

Of course when applying these 'FixIts' we don't interrupt the user with
confirmation or the quickfix list as this would just be annoying. If the
server reports that an edit must be made, we just make the edit. This is
achieved by adding a silent flag to ReplaceChunks.
2018-02-11 18:11:34 +00:00
zzbot
39fe6d1f86
Auto merge of #2898 - micbou:line-overlapping-chunks, r=micbou
[READY] Apply chunks from bottom to top

Without the proposed fix, the test included in that PR fails as follows
```
FAIL: ycm.tests.vimsupport_test.ReplaceChunksInBuffer_LineOverlappingChunks_test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\nose\case.py", line 198, in runTest
    self.test(*self.arg)
  File "C:\Users\micbou\projects\YouCompleteMe\python\ycm\tests\vimsupport_test.py", line 768, in ReplaceChunksInBuffer_LineOverlappingChunks_test
    AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
  File "C:\Users\micbou\projects\YouCompleteMe\python\ycm\tests\vimsupport_test.py", line 86, in AssertBuffersAreEqualAsBytes
    eq_( ToBytes( result_line ), ToBytes( expected_line ) )
AssertionError: b'    third line' != b'    third '
```
Found the issue while trying to add code formatting support to the language server completer. The test is based on a real-world scenario when formatting with jdt.ls (for some reason, jdt.ls is including the newline of the previous line when fixing indentation).

<!-- 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/2898)
<!-- Reviewable:end -->
2018-02-10 15:20:24 -08:00
micbou
c692b48bc6
Apply chunks from bottom to top 2018-02-10 21:42:41 +01:00
zzbot
0d495578b5
Auto merge of #2863 - puremourning:java-async-diagnostics, r=micbou
[READY] Java support with asynchronous diagnostics and messages

# 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 change is required for a better user experience when using native
java support

This implements an asynchronous message system using a long-poll request
to the server.

The server provides an endpoint /receive_messages which blocks until
either a timeout occurs or we receive a batch of asynchronous messages.
We send this request asynchronously and poll it 4 times a second to see
if we have received any messages.

The messages may either be simply for display (such as startup progress)
or diagnostics, which override the diagnostics returned by
OnFileReqdyToParse.

In the former case, we simply display the message, accepting that this
might be overwritten by any other message (indeed, requiring this), and
for the latter we fan out diagnostics to any open buffer for the file in
question.

Unfortunately, Vim has bugs related to timers when there is something
displayed (such as a "confirm" prompt or other), so we suspend
background timers when doing subcommands to avoid vim bugs. NOTE: This
requires a new version of Vim (detected by the presence of the
particular functions used).

NOT_READY because:

- the submodule commit points at my repo and requires https://github.com/Valloric/ycmd/pull/857 to be merged
- my spider sense suggest i have more testing to do...

Notes:

- Part 3 (I think) of the Java support PRs. This one actually adds the minimal changes for working java support
- There are about 2 or 3 other PRs to come to add things like automatic module imports, etc.

[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/2863)
<!-- Reviewable:end -->
2018-02-10 12:37:57 -08:00
Ben Jackson
292de25c72 Add support for Java diagnostics and asynchronous messages
This implements an asynchronous message system using a long-poll request
to the server.

The server provides an endpoint /receive_messages which blocks until
either a timeout occurs or we receive a batch of asynchronous messages.
We send this request asynchronously and poll it 4 times a second to see
if we have received any messages.

The messages may either be simply for display (such as startup progress)
or diagnostics, which override the diagnostics returned by
OnFileReqdyToParse.

In the former case, we simply display the message, accepting that this
might be overwritten by any other message (indeed, requiring this), and
for the latter we fan out diagnostics to any open buffer for the file in
question.

Unfortunately, Vim has bugs related to timers when there is something
displayed (such as a "confirm" prompt or other), so we suspend
background timers when doing subcommands to avoid vim bugs. NOTE: This
requires a new version of Vim (detected by the presence of the
particular functions used).
2018-02-10 16:29:27 +00:00
micbou
6c326a1b5f
Avoid traceback when computing extra conf data
Evaluating the values of g:ycm_extra_conf_vim_data may raise a Python exception
(e.g. one of the values is not defined). Since that option is parsed each time
a request is sent, such exception makes the editor almost unusable as each key
press is printing a Python traceback to the user. Catch and log the exception.
2018-02-10 15:27:27 +01:00
Boris Staletic
605ef42cd6 Drop Python 2.6 and Python 3.3 2018-01-30 18:34:50 +01:00
micbou
43ebd5252d
Optimize request building
Reduce the time spent to build the request when there are a lot of buffers by:
 - using the options property on the buffer object to get the mod variable
instead of evaluating getbufvar;
 - not computing the buffer filepath if the buffer is not modified;
 - passing the number of the unloaded buffer instead of its filepath on the
   BufferUnload event. Getting the Python buffer object from its number is
   easier than from its filepath.
2018-01-09 01:40:07 +01:00
Ben Jackson
c2f26159f6 Use fake filetype for omni completion test
Now that the server supports Java natively, we need to use a
filetype that does not have native support to ensure that we call the
mocked omnifunc, but also one for which YCM has a semantic trigger.

Rather than picking another random languagse, which might break in the
future, we invent a language (ycmtest) and supply a manual trigger
mapping to the YouCompleteMe object.
2017-12-23 15:41:14 +00:00
zzbot
8aa617ec03 Auto merge of #2861 - puremourning:always-supply-wd, r=micbou
[READY] Always supply working directory

This allows completer servers to detect the correct directory to launch
no matter what request initialises the completer server.

# 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 change ensures that the client supplies the working directory to the server on each request, in particular, event notifications; the java and javascript completers use this to start the server in the `FileReadyToParse` event, rather than on construction of the completer. The subtle difference allows them to use the client's working directory, rather than the _server's_ working directory to do things like project detection.

See also:

* This is PR 1 of the set of changes related to #2827 - client changes required to support Java and other language-server protocols.
* ycmd change for javascript that makes use of this now: https://github.com/Valloric/ycmd/pull/886
* updated API doc: http://puremourning.github.io/ycmd-1

The ycmd API change is simply to allow `working_dir` on all requests.

cc for minor optional API change: @abingham @Qusic @LuckyGeck @mawww @richard1122 @jakeanq @orsonteodoro

[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/2861)
<!-- Reviewable:end -->
2017-12-22 17:36:34 -08:00
Ben Jackson
bc6ac461f3 Always supply working directory
This allows completer servers to detect the correct directory to launch
no matter what request initialises the completer server.
2017-12-23 00:51:21 +00:00
micbou
497a803188
Prompt the user to select a logfile with YcmToggleLogs
When no argument is given to the YcmToggleLogs command, instead of displaying
the list of available logfiles, prompt the user to open (or close if already
open) one of them.
2017-12-22 19:58:29 +01:00
micbou
c3859791ea
Use fnameescape to escape filepath 2017-12-01 17:54:45 +01:00
micbou
67d2a0fbf8
Fix error when filetype is a number
The VimExpressionToPythonType function automatically convert a number
represented as a string to an integer. This causes an error when used to
evaluate a filetype set to a number as the result is split on the dot character
to get a list of filetypes and an integer cannot be split. Use vim.eval and
ToUnicode instead.
2017-11-26 16:44:35 +01:00
micbou
664d2c99d9
Change GetBufferNumberForFilename default behavior
If no buffer exists for a given filename, the GetBufferNumberForFilename
function will create a buffer for that file by default. This behavior is
unexpected given the name of that function and may lead to performance issues
when ycmd returns diagnostics for a lot of files with no corresponding buffers.
The default behavior for that function should be to not create a buffer.
2017-11-17 00:52:40 +01:00
micbou
84998b5b5f
Fix bare except statement
Use Exception to catch all exceptions instead of a bare except statement.
2017-10-23 21:05:16 +02:00
micbou
2b8e86797c
Improve server crash notification at startup
Notify the user if the server crashed during server polling at startup.
2017-10-05 13:12:23 +02:00
micbou
880f8700b3
Echo diagnostic asynchronously 2017-10-04 16:59:47 +02:00
zzbot
712c417529 Auto merge of #2787 - micbou:improve-path-to-python-interpreter, r=puremourning
[READY] Improve path to python interpreter error handling

YCM returns the cryptic error `YouCompleteMe unavailable: [Errno 2] No such file or directory` when the Python interpreter path used to start the server doesn't exist. See issues https://github.com/Valloric/YouCompleteMe/issues/2773 and https://github.com/Valloric/YouCompleteMe/issues/2775.

This PR improves that by using the `FindExecutable` and `GetExecutable` functions from ycmd to check if the Python interpreter path exists (and is an executable) and by returning a much more helpful message if it doesn't. We use `FindExecutable` instead of `GetExecutable` on the `g:ycm_server_python_interpreter` option so that the user can specify a Python path with just the executable name (e.g. `python`, `python2`, `python3`).

This also fixes a Python traceback in Vim that occurs when, after successfully starting the server, the `g:ycm_server_python_interpreter` option is set to an invalid path and the server is restarted with `:YcmRestartServer`. Steps to reproduce are:
 - start Vim with a working YCM;
 - type `:let g:ycm_server_python_interpreter = '/invalid/python/path'`;
 - type `:YcmRestartServer`.

<!-- 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/2787)
<!-- Reviewable:end -->
2017-09-21 14:07:27 -07:00
micbou
5d78e4c2c0
Improve path to python interpreter error handling 2017-09-21 21:17:32 +02:00
micbou
d61944098a
Do not open location list at the bottom of screen
The location list is specific to the current window so it should be opened
inside the current window, not to full width at the bottom of the screen.
2017-09-17 20:34:52 +02:00
micbou
c5bec8f690
Expect GetCompletions_Cache_List_Unicode test to fail
This test is expected to fail since we now filter and sort candidates on empty
query.
2017-09-10 16:33:24 +02:00
micbou
031edea89e
Improve error message when server crashes
Give the exact command that the user needs to type to open the server logfile
when the server unexpectedly crashes.
2017-08-18 18:15:20 +02:00
micbou
bdac8ed43e
Do not read server stderr
Reading ycmd stderr blocks Vim if a subserver process is still up even if ycmd
is not running.
2017-08-17 20:16:54 +02:00
micbou
2afc0d5f5f
Update BufferUnload test with Unicode paths 2017-07-08 14:19:27 +02:00
micbou
139e3fbaf9
Add omnifunc tests 2017-07-07 22:45:05 +02:00
micbou
600383fbac
Do not cache omnifunc on FileReadyToParse event 2017-07-07 21:39:27 +02:00
micbou
dec9c0f827
Add test with omnifunc moving cursor position 2017-07-07 13:59:57 +02:00
micbou
db0b9ab335
Rewrite omnifunc tests
The VimBuffer object now accepts a Python function as its omnifunc.
2017-07-05 23:21:36 +02:00
micbou
81546b901e
Fix HiddenEnabled function
The 'hidden' option is a global option, not a buffer one. If this option is
false, we should check if the 'bufhidden' option, which is local to the buffer,
is set to 'hide'. If so, the buffer can be hidden despite the 'hidden' option
being false.
2017-07-05 19:56:13 +02:00
micbou
e5457affd8
Add JumpToLocation unicode tests 2017-07-05 00:55:29 +02:00
micbou
f31102e317
Check if server is ready before running tests 2017-07-03 18:06:01 +02:00
Ben Jackson
5c98b69b6f Fix tests supplying findstart. It's 0-based. Known failure is no longer a known failure 2017-07-03 00:55:03 +01:00
micbou
223ae6ab9f
Rewrite completion system
Bring fully asynchronous completion by polling for completions with a timer
then calling completefunc once the completions are ready. Use the start column
returned by the server in completefunc. Immediately display the last completion
on the TextChangedI event to prevent the popup menu disappearing while waiting
for the completions. Handle the TextChangedI event not being triggered while
the completion menu is open by closing the menu when inserting a character
through the InsertCharPre event, and when deleting a character on the <BS> and
<C-h> keys.
2017-06-21 02:32:57 +02:00
zzbot
44d4f1d299 Auto merge of #2690 - micbou:identifier-functions-codepoint, r=Valloric
[READY] Use codepoint offsets in identifier functions

`CurrentIdentifierFinished` and `LastEnteredCharIsIdentifierChar` incorrectly use byte offsets with unicode lines (`CurrentColumn` returns a byte offset and `CurrentLineContents` a unicode string). This leads to weird bugs when there is a non-ASCII character on the current line:

![unicode-identifier-bug](https://user-images.githubusercontent.com/10026824/27256590-34b27c8c-53ba-11e7-8032-b98f0c7e0b14.gif)

This is fixed by converting byte offsets to codepoint ones through the `ByteOffsetToCodepointOffset` function.

This changes the behavior of these two functions when the current column position is invalid. Both functions returned false in that case. They now return as if the current column were at the end of the line. In practice, this doesn't really matter since the position of the current column should always be valid.

<!-- 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/2690)
<!-- Reviewable:end -->
2017-06-18 12:29:13 -07:00
micbou
eb3c0cd8c1
Use codepoint offsets in identifier functions
CurrentIdentifierFinished and LastEnteredCharIsIdentifierChar incorrectly use
byte offsets with unicode lines. Convert those offsets to codepoint offsets.
2017-06-18 20:41:30 +02:00
Davit Samvelyan
a70755aa40 Removed current buffer caching approach. 2017-06-12 15:23:14 +04:00
Davit Samvelyan
e5b0565d1a Fixed bug: current buffer was not set correctly.
Other minor fixes.
2017-06-10 09:53:18 +04:00
Davit Samvelyan
22be4e777d Refactored diag interface, removed dummy sign. 2017-06-05 22:20:57 +04:00
zzbot
c2906b6fef Auto merge of #2631 - davits:changedtick, r=bstaletic
[READY] Moved change tracking to python. Per buffer diagnostics

Thank you for working on YCM! :)

- [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.**

Adds an emulation of Vim buffer object and moves change tracking into python.
Now diagnostics are stored per buffer, which effectively solves #2165 .

<!-- 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/2631)
<!-- Reviewable:end -->
2017-06-05 03:21:41 -07:00
Davit Samvelyan
8c6efb4214 Cache current buffer on buffer visit. 2017-06-04 12:09:49 +04:00
Boris Staletic
3e77555905 Filepath space escaping 2017-05-24 17:30:15 +02:00