Add range support to completer command

This commit is contained in:
micbou 2018-02-07 19:57:45 +01:00
parent 74ee5d4011
commit a13329fe94
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
9 changed files with 288 additions and 96 deletions

View File

@ -835,6 +835,7 @@ Quick Feature Summary
* View documentation comments for identifiers (`GetDoc`) * View documentation comments for identifiers (`GetDoc`)
* Type information for identifiers (`GetType`) * Type information for identifiers (`GetType`)
* Automatically fix certain errors including code generation (`FixIt`) * Automatically fix certain errors including code generation (`FixIt`)
* Code formatting (`Format`)
* Detection of java projects * Detection of java projects
* Management of `jdt.ls` server instance * Management of `jdt.ls` server instance
@ -1500,6 +1501,12 @@ Technically the command invokes completer-specific commands. If the first
argument is of the form `ft=...` the completer for that file type will be used argument is of the form `ft=...` the completer for that file type will be used
(for example `ft=cpp`), else the native completer of the current buffer will be (for example `ft=cpp`), else the native completer of the current buffer will be
used. used.
This command also accepts a range that can either be specified through a
selection in one of Vim's visual modes (see `:h visual-use`) or on the command
line. For instance, `:2,5YcmCompleter` will apply the command from line 2 to
line 5. This is useful for [the `Format` subcommand](#the-format-subcommand).
Call `YcmCompleter` without further arguments for a list of the Call `YcmCompleter` without further arguments for a list of the
commands you can call for the current completer. commands you can call for the current completer.
@ -1699,7 +1706,7 @@ latency.
Supported in filetypes: `c, cpp, objc, objcpp` Supported in filetypes: `c, cpp, objc, objcpp`
### Refactoring and FixIt Commands ### Refactoring Commands
These commands make changes to your source code in order to perform refactoring These commands make changes to your source code in order to perform refactoring
or code correction. YouCompleteMe does not perform any action which cannot be or code correction. YouCompleteMe does not perform any action which cannot be
@ -1778,6 +1785,17 @@ be manually corrected using Vim's undo features. The quickfix list is *not*
populated in this case. Inspect `:buffers` or equivalent (see `:help buffers`) populated in this case. Inspect `:buffers` or equivalent (see `:help buffers`)
to see the buffers that were opened by the command. to see the buffers that were opened by the command.
#### The `Format` subcommand
This commands formats the whole buffer or some part of it according to the value
of the Vim options `shiftwidth` and `expandtab` (see `:h 'sw'` and `:h et`
respectively). To format a specific part of your document, you can either select
it in one of Vim's visual modes (see `:h visual-use`) and run the command or
directly enter the range on the command line, e.g. `:2,5YcmCompleter Format` to
format it from line 2 to line 5.
Supported in filetypes: `java`
### Miscellaneous Commands ### Miscellaneous Commands
These commands are for general administration, rather than IDE-like features. These commands are for general administration, rather than IDE-like features.

View File

@ -820,8 +820,11 @@ function! s:SetUpCommands()
command! YcmDebugInfo call s:DebugInfo() command! YcmDebugInfo call s:DebugInfo()
command! -nargs=* -complete=custom,youcompleteme#LogsComplete command! -nargs=* -complete=custom,youcompleteme#LogsComplete
\ YcmToggleLogs call s:ToggleLogs(<f-args>) \ YcmToggleLogs call s:ToggleLogs(<f-args>)
command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete -range
\ YcmCompleter call s:CompleterCommand(<f-args>) \ YcmCompleter call s:CompleterCommand(<range>,
\ <line1>,
\ <line2>,
\ <f-args>)
command! YcmDiags call s:ShowDiagnostics() command! YcmDiags call s:ShowDiagnostics()
command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic() command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic()
command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics() command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics()
@ -860,14 +863,14 @@ function! youcompleteme#LogsComplete( arglead, cmdline, cursorpos )
endfunction endfunction
function! s:CompleterCommand(...) function! s:CompleterCommand( range, line1, line2, ... )
" CompleterCommand will call the OnUserCommand function of a completer. If " 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 " 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 to use (for example "ft=cpp"). Else the native filetype completer
" completer of the current buffer is used. If no native filetype completer " of the current buffer is used. If no native filetype completer is found and
" is found and no completer was specified this throws an error. You can use " no completer was specified this throws an error. You can use "ft=ycm:ident"
" "ft=ycm:ident" to select the identifier completer. " to select the identifier completer. The remaining arguments will be passed
" The remaining arguments will be passed to the completer. " to the completer.
let arguments = copy(a:000) let arguments = copy(a:000)
let completer = '' let completer = ''
@ -879,7 +882,11 @@ function! s:CompleterCommand(...)
endif endif
exec s:python_command "ycm_state.SendCommandRequest(" . exec s:python_command "ycm_state.SendCommandRequest(" .
\ "vim.eval( 'l:arguments' ), vim.eval( 'l:completer' ) )" \ "vim.eval( 'l:arguments' )," .
\ "vim.eval( 'l:completer' )," .
\ "vimsupport.GetBoolValue( 'a:range' )," .
\ "vimsupport.GetIntValue( 'a:line1' )," .
\ "vimsupport.GetIntValue( 'a:line2' ) )"
endfunction endfunction

View File

@ -78,10 +78,11 @@ Contents ~
3. The |GetParent| subcommand 3. The |GetParent| subcommand
4. The |GetDoc| subcommand 4. The |GetDoc| subcommand
5. The |GetDocImprecise| subcommand 5. The |GetDocImprecise| subcommand
3. Refactoring and FixIt Commands |youcompleteme-refactoring-fixit-commands| 3. Refactoring Commands |youcompleteme-refactoring-commands|
1. The |FixIt| subcommand 1. The |FixIt| subcommand
2. The 'RefactorRename <new name>' subcommand |RefactorRename-new-name| 2. The 'RefactorRename <new name>' subcommand |RefactorRename-new-name|
3. Multi-file Refactor |youcompleteme-multi-file-refactor| 3. Multi-file Refactor |youcompleteme-multi-file-refactor|
4. The |Format| subcommand
4. Miscellaneous Commands |youcompleteme-miscellaneous-commands| 4. Miscellaneous Commands |youcompleteme-miscellaneous-commands|
1. The |RestartServer| subcommand 1. The |RestartServer| subcommand
2. The |ClearCompilationFlagCache| subcommand 2. The |ClearCompilationFlagCache| subcommand
@ -143,41 +144,41 @@ Contents ~
48. The |g:ycm_disable_for_files_larger_than_kb| option 48. The |g:ycm_disable_for_files_larger_than_kb| option
49. The |g:ycm_python_binary_path| option 49. The |g:ycm_python_binary_path| option
13. FAQ |youcompleteme-faq| 13. FAQ |youcompleteme-faq|
1. I used to be able to 'import vim' in '.ycm_extra_conf.py', but now can't |import-vim| 1. I used to be able to 'import vim' in '.ycm_extra_conf.py', but now can't |youcompleteme-i-used-to-be-able-to-import-vim-in-.ycm_extra_conf.py-but-now-cant|
2. I get |ImportError| exceptions that mention 'PyInit_ycm_core' or 'initycm_core' 2. I get 'ImportError' exceptions that mention 'PyInit_ycm_core' or 'initycm_core' |youcompleteme-i-get-importerror-exceptions-that-mention-pyinit_ycm_core-or-initycm_core|
3. I get a linker warning regarding |libpython| on Mac when compiling YCM 3. I get a linker warning regarding 'libpython' on Mac when compiling YCM |youcompleteme-i-get-linker-warning-regarding-libpython-on-mac-when-compiling-ycm|
4. I get a weird window at the top of my file when I use the semantic engine |youcompleteme-i-get-weird-window-at-top-of-my-file-when-i-use-semantic-engine| 4. I get a weird window at the top of my file when I use the semantic engine |youcompleteme-i-get-weird-window-at-top-of-my-file-when-i-use-semantic-engine|
5. It appears that YCM is not working |youcompleteme-it-appears-that-ycm-is-not-working| 5. It appears that YCM is not working |youcompleteme-it-appears-that-ycm-is-not-working|
6. Sometimes it takes much longer to get semantic completions than normal |youcompleteme-sometimes-it-takes-much-longer-to-get-semantic-completions-than-normal| 6. Sometimes it takes much longer to get semantic completions than normal |youcompleteme-sometimes-it-takes-much-longer-to-get-semantic-completions-than-normal|
7. YCM auto-inserts completion strings I don't want! |youcompleteme-ycm-auto-inserts-completion-strings-i-dont-want| 7. YCM auto-inserts completion strings I don't want! |youcompleteme-ycm-auto-inserts-completion-strings-i-dont-want|
8. I get a 'E227: mapping already exists for <blah>' error when I start Vim |E227:-mapping-already-exists-for-blah| 8. I get a 'E227: mapping already exists for <blah>' error when I start Vim |youcompleteme-i-get-e227-mapping-already-exists-for-blah-error-when-i-start-vim|
9. I get "'GLIBC_2.XX' not found (required by libclang.so)" when starting Vim |GLIBC_2.XX-not-found()| 9. I get "'GLIBC_2.XX' not found (required by libclang.so)" when starting Vim |youcompleteme-i-get-glibc_2.xx-not-found-when-starting-vim|
10. I'm trying to use a Homebrew Vim with YCM and I'm getting segfaults |youcompleteme-im-trying-to-use-homebrew-vim-with-ycm-im-getting-segfaults| 10. I'm trying to use a Homebrew Vim with YCM and I'm getting segfaults |youcompleteme-im-trying-to-use-homebrew-vim-with-ycm-im-getting-segfaults|
11. I have a Homebrew Python and/or MacVim; can't compile/SIGABRT when starting |youcompleteme-i-have-homebrew-python-and-or-macvim-cant-compile-sigabrt-when-starting| 11. I have a Homebrew Python and/or MacVim; can't compile/SIGABRT when starting |youcompleteme-i-have-homebrew-python-and-or-macvim-cant-compile-sigabrt-when-starting|
12. I get 'LONG_BIT definition appears wrong for platform' when compiling |LONG_BIT-definition-appears-wrong-for-platform| 12. I get 'LONG_BIT definition appears wrong for platform' when compiling |youcompleteme-i-get-long_bit-definition-appears-wrong-for-platform-when-compiling|
13. I get 'libpython2.7.a [...] relocation R_X86_64_32' when compiling |libpython2.7.a-...-relocation-R_X86_64_32| 13. I get 'libpython2.7.a [...] relocation R_X86_64_32' when compiling |youcompleteme-i-get-libpython2.7.a-...-relocation-r_x86_64_32-when-compiling|
14. I get 'Vim: Caught deadly signal SEGV' on Vim startup |Vim:-Caught-deadly-signal-SEGV| 14. I get 'Vim: Caught deadly signal SEGV' on Vim startup |youcompleteme-i-get-vim-caught-deadly-signal-segv-on-vim-startup|
15. I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup |Fatal-Python-error:-PyThreadState_Get:-no-current-thread| 15. I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup |youcompleteme-i-get-fatal-python-error-pythreadstate_get-no-current-thread-on-startup|
16. |install.py| says python must be compiled with '--enable-framework'. Wat? 16. 'install.py' says python must be compiled with '--enable-framework'. Wat? |youcompleteme-install.py-says-python-must-be-compiled-with-enable-framework-.-wat|
17. YCM does not read identifiers from my tags files |youcompleteme-ycm-does-not-read-identifiers-from-my-tags-files| 17. YCM does not read identifiers from my tags files |youcompleteme-ycm-does-not-read-identifiers-from-my-tags-files|
18. 'CTRL-U' in insert mode does not work while the completion menu is visible |CTRL-sub-U| 18. 'CTRL-U' in insert mode does not work while the completion menu is visible |youcompleteme-ctrl-u-in-insert-mode-does-not-work-while-completion-menu-is-visible|
19. YCM conflicts with UltiSnips TAB key usage |youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage| 19. YCM conflicts with UltiSnips TAB key usage |youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage|
20. Snippets added with |:UltiSnipsAddFiletypes| do not appear in the popup menu 20. Snippets added with ':UltiSnipsAddFiletypes' do not appear in the popup menu |youcompleteme-snippets-added-with-ultisnipsaddfiletypes-do-not-appear-in-popup-menu|
21. Why isn't YCM just written in plain VimScript, FFS? |youcompleteme-why-isnt-ycm-just-written-in-plain-vimscript-ffs| 21. Why isn't YCM just written in plain VimScript, FFS? |youcompleteme-why-isnt-ycm-just-written-in-plain-vimscript-ffs|
22. Why does YCM demand such a recent version of Vim? |youcompleteme-why-does-ycm-demand-such-recent-version-of-vim| 22. Why does YCM demand such a recent version of Vim? |youcompleteme-why-does-ycm-demand-such-recent-version-of-vim|
23. Nasty bugs happen if I have the 'vim-autoclose' plugin installed |vim-sub-autoclose| 23. Nasty bugs happen if I have the 'vim-autoclose' plugin installed |youcompleteme-nasty-bugs-happen-if-i-have-vim-autoclose-plugin-installed|
24. Is there some sort of YCM mailing list? I have questions |youcompleteme-is-there-sort-of-ycm-mailing-list-i-have-questions| 24. Is there some sort of YCM mailing list? I have questions |youcompleteme-is-there-sort-of-ycm-mailing-list-i-have-questions|
25. I get an internal compiler error when installing |youcompleteme-i-get-an-internal-compiler-error-when-installing| 25. I get an internal compiler error when installing |youcompleteme-i-get-an-internal-compiler-error-when-installing|
26. I get weird errors when I press 'Ctrl-C' in Vim |Ctrl-sub-C| 26. I get weird errors when I press 'Ctrl-C' in Vim |youcompleteme-i-get-weird-errors-when-i-press-ctrl-c-in-vim|
27. Why did YCM stop using Syntastic for diagnostics display? |youcompleteme-why-did-ycm-stop-using-syntastic-for-diagnostics-display| 27. Why did YCM stop using Syntastic for diagnostics display? |youcompleteme-why-did-ycm-stop-using-syntastic-for-diagnostics-display|
28. Completion doesn't work with the C++ standard library headers |youcompleteme-completion-doesnt-work-with-c-standard-library-headers| 28. Completion doesn't work with the C++ standard library headers |youcompleteme-completion-doesnt-work-with-c-standard-library-headers|
29. When I open a JavaScript file, I get an annoying warning about '.tern-project' 29. When I open a JavaScript file, I get an annoying warning about '.tern-project'
file |.tern-sub-project| file |youcompleteme-when-i-open-javascript-file-i-get-an-annoying-warning-about-.tern-project-file|
30. When I start vim I get a runtime error saying 'R6034 An application has made an 30. When I start vim I get a runtime error saying 'R6034 An application has made an
attempt to load the C runtime library incorrectly.' |R6034-An-application-has-made-an-attempt-to-load-the-C-runtime-library-incorrectly.| attempt to load the C runtime library incorrectly.' |youcompleteme-when-i-start-vim-i-get-runtime-error-saying-r6034-an-application-has-made-an-attempt-to-load-c-runtime-library-incorrectly.|
31. I hear that YCM only supports Python 2, is that true? |youcompleteme-i-hear-that-ycm-only-supports-python-2-is-that-true| 31. I hear that YCM only supports Python 2, is that true? |youcompleteme-i-hear-that-ycm-only-supports-python-2-is-that-true|
32. On Windows I get "E887: Sorry, this command is disabled, the Python's site 32. On Windows I get "E887: Sorry, this command is disabled, the Python's site
module could not be loaded" |E887:-Sorry-this-command-is-disabled-the-Python-s-site-module-could-not-be-loaded| module could not be loaded" |youcompleteme-on-windows-i-get-e887-sorry-this-command-is-disabled-pythons-site-module-could-not-be-loaded|
33. I can't complete python packages in a virtual environment. |youcompleteme-i-cant-complete-python-packages-in-virtual-environment.| 33. I can't complete python packages in a virtual environment. |youcompleteme-i-cant-complete-python-packages-in-virtual-environment.|
34. I want to defer loading of YouCompleteMe until after Vim finishes booting |i-want-to-defer-loading-of-youcompleteme-until-after-vim-finishes-booting| 34. I want to defer loading of YouCompleteMe until after Vim finishes booting |i-want-to-defer-loading-of-youcompleteme-until-after-vim-finishes-booting|
35. YCM does not shut down when I quit Vim |youcompleteme-ycm-does-not-shut-down-when-i-quit-vim| 35. YCM does not shut down when I quit Vim |youcompleteme-ycm-does-not-shut-down-when-i-quit-vim|
@ -200,7 +201,7 @@ Help, Advice, Support ~
Looking for help, advice or support? Having problems getting YCM to work? Looking for help, advice or support? Having problems getting YCM to work?
First carefully read the installation instructions for your OS. We recommend First carefully read the installation instructions for your OS. We recommend
you use the supplied |install.py|. you use the supplied 'install.py'.
Next check the User Guide section on the semantic completer that you are using. Next check the User Guide section on the semantic completer that you are using.
For C/C++/Objective C, you _must_ read this section. For C/C++/Objective C, you _must_ read this section.
@ -363,7 +364,7 @@ Installation ~
*youcompleteme-mac-os-x* *youcompleteme-mac-os-x*
Mac OS X ~ Mac OS X ~
These instructions (using |install.py|) are the quickest way to install These instructions (using 'install.py') are the quickest way to install
YouCompleteMe, however they may not work for everyone. If the following YouCompleteMe, however they may not work for everyone. If the following
instructions don't work for you, check out the full installation guide. instructions don't work for you, check out the full installation guide.
@ -444,7 +445,7 @@ that are conservatively turned off by default that you may want to turn on.
*youcompleteme-ubuntu-linux-x64* *youcompleteme-ubuntu-linux-x64*
Ubuntu Linux x64 ~ Ubuntu Linux x64 ~
These instructions (using |install.py|) are the quickest way to install These instructions (using 'install.py') are the quickest way to install
YouCompleteMe, however they may not work for everyone. If the following YouCompleteMe, however they may not work for everyone. If the following
instructions don't work for you, check out the full installation guide. instructions don't work for you, check out the full installation guide.
@ -523,7 +524,7 @@ that are conservatively turned off by default that you may want to turn on.
*youcompleteme-fedora-linux-x64* *youcompleteme-fedora-linux-x64*
Fedora Linux x64 ~ Fedora Linux x64 ~
These instructions (using |install.py|) are the quickest way to install These instructions (using 'install.py') are the quickest way to install
YouCompleteMe, however they may not work for everyone. If the following YouCompleteMe, however they may not work for everyone. If the following
instructions don't work for you, check out the full installation guide. instructions don't work for you, check out the full installation guide.
@ -597,7 +598,7 @@ that are conservatively turned off by default that you may want to turn on.
*youcompleteme-windows* *youcompleteme-windows*
Windows ~ Windows ~
These instructions (using |install.py|) are the quickest way to install These instructions (using 'install.py') are the quickest way to install
YouCompleteMe, however they may not work for everyone. If the following YouCompleteMe, however they may not work for everyone. If the following
instructions don't work for you, check out the full installation guide. instructions don't work for you, check out the full installation guide.
@ -661,20 +662,20 @@ Compiling YCM **without** semantic support for C-family languages:
< <
The following additional language support options are available: The following additional language support options are available:
- C# support: add '--cs-completer' when calling |install.py|. Be sure that - C# support: add '--cs-completer' when calling 'install.py'. Be sure that
the build utility 'msbuild' is in your PATH [42]. the build utility 'msbuild' is in your PATH [42].
- Go support: install Go [30] and add '--go-completer' when calling - Go support: install Go [30] and add '--go-completer' when calling
|install.py|. 'install.py'.
- TypeScript support: install Node.js and npm [31] then install the - TypeScript support: install Node.js and npm [31] then install the
TypeScript SDK with 'npm install -g typescript'. TypeScript SDK with 'npm install -g typescript'.
- JavaScript support: install Node.js and npm [31] and add '--js-completer' - JavaScript support: install Node.js and npm [31] and add '--js-completer'
when calling |install.py|. when calling 'install.py'.
- Rust support: install Rust [32] and add '--rust-completer' when calling - Rust support: install Rust [32] and add '--rust-completer' when calling
|install.py|. 'install.py'.
- Java support: install JDK8 (version 8 required) [33] and add '--java- - Java support: install JDK8 (version 8 required) [33] and add '--java-
completer' when calling './install.py'. completer' when calling './install.py'.
@ -703,7 +704,7 @@ that are conservatively turned off by default that you may want to turn on.
*youcompleteme-freebsd-openbsd* *youcompleteme-freebsd-openbsd*
FreeBSD/OpenBSD ~ FreeBSD/OpenBSD ~
These instructions (using |install.py|) are the quickest way to install These instructions (using 'install.py') are the quickest way to install
YouCompleteMe, however they may not work for everyone. If the following YouCompleteMe, however they may not work for everyone. If the following
instructions don't work for you, check out the full installation guide. instructions don't work for you, check out the full installation guide.
@ -970,7 +971,7 @@ will notify you to recompile it. You should then rerun the install process.
e/third_party/ycmd/third_party/eclipse.jdt.ls/target/repository'. e/third_party/ycmd/third_party/eclipse.jdt.ls/target/repository'.
Note: this approach is not recommended for most users and is Note: this approach is not recommended for most users and is
supported only for advanced users and developers of YCM on a best- supported only for advanced users and developers of YCM on a best-
efforts basis. Please use |install.py| to enable java support. efforts basis. Please use 'install.py' to enable java support.
That's it. You're done. Refer to the _User Guide_ section on how to use YCM. That's it. You're done. Refer to the _User Guide_ section on how to use YCM.
Don't forget that if you want the C-family semantic completion engine to work, Don't forget that if you want the C-family semantic completion engine to work,
@ -1083,6 +1084,7 @@ feedback.
- View documentation comments for identifiers (|GetDoc|) - View documentation comments for identifiers (|GetDoc|)
- Type information for identifiers (|GetType|) - Type information for identifiers (|GetType|)
- Automatically fix certain errors including code generation (|FixIt|) - Automatically fix certain errors including code generation (|FixIt|)
- Code formatting (|Format|)
- Detection of java projects - Detection of java projects
- Management of 'jdt.ls' server instance - Management of 'jdt.ls' server instance
@ -1785,8 +1787,15 @@ for things like semantic GoTo, type information, FixIt and refactoring.
Technically the command invokes completer-specific commands. If the first Technically the command invokes completer-specific commands. If the first
argument is of the form 'ft=...' the completer for that file type will be used argument is of the form 'ft=...' the completer for that file type will be used
(for example 'ft=cpp'), else the native completer of the current buffer will be (for example 'ft=cpp'), else the native completer of the current buffer will be
used. Call 'YcmCompleter' without further arguments for a list of the commands used.
you can call for the current completer.
This command also accepts a range that can either be specified through a
selection in one of Vim's visual modes (see ':h visual-use') or on the command
line. For instance, ':2,5YcmCompleter' will apply the command from line 2 to
line 5. This is useful for the |Format| subcommand.
Call 'YcmCompleter' without further arguments for a list of the commands you
can call for the current completer.
See the file type feature summary for an overview of the features available for See the file type feature summary for an overview of the features available for
each file type. See the _YcmCompleter subcommands_ section for more information each file type. See the _YcmCompleter subcommands_ section for more information
@ -1998,8 +2007,8 @@ bit of latency.
Supported in filetypes: 'c, cpp, objc, objcpp' Supported in filetypes: 'c, cpp, objc, objcpp'
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*youcompleteme-refactoring-fixit-commands* *youcompleteme-refactoring-commands*
Refactoring and FixIt Commands ~ Refactoring Commands ~
These commands make changes to your source code in order to perform refactoring These commands make changes to your source code in order to perform refactoring
or code correction. YouCompleteMe does not perform any action which cannot be or code correction. YouCompleteMe does not perform any action which cannot be
@ -2083,6 +2092,18 @@ must be manually corrected using Vim's undo features. The quickfix list is
_not_ populated in this case. Inspect ':buffers' or equivalent (see ':help _not_ populated in this case. Inspect ':buffers' or equivalent (see ':help
buffers') to see the buffers that were opened by the command. buffers') to see the buffers that were opened by the command.
-------------------------------------------------------------------------------
The *Format* subcommand
This commands formats the whole buffer or some part of it according to the
value of the Vim options 'shiftwidth' and 'expandtab' (see ":h 'sw'" and ':h
et' respectively). To format a specific part of your document, you can either
select it in one of Vim's visual modes (see ':h visual-use') and run the
command or directly enter the range on the command line, e.g. ':2,5YcmCompleter
Format' to format it from line 2 to line 5.
Supported in filetypes: 'java'
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*youcompleteme-miscellaneous-commands* *youcompleteme-miscellaneous-commands*
Miscellaneous Commands ~ Miscellaneous Commands ~
@ -3048,7 +3069,7 @@ found through the PATH.
FAQ ~ FAQ ~
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*import-vim* *youcompleteme-i-used-to-be-able-to-import-vim-in-.ycm_extra_conf.py-but-now-cant*
I used to be able to 'import vim' in '.ycm_extra_conf.py', but now can't ~ I used to be able to 'import vim' in '.ycm_extra_conf.py', but now can't ~
YCM was rewritten to use a client-server architecture where most of the logic YCM was rewritten to use a client-server architecture where most of the logic
@ -3064,7 +3085,9 @@ working by using the |g:ycm_extra_conf_vim_data| option. See the docs on that
option for details. option for details.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
I get *ImportError* exceptions that mention 'PyInit_ycm_core' or 'initycm_core' *youcompleteme-i-get-importerror-exceptions-that-mention-pyinit_ycm_core-or-initycm_core*
I get 'ImportError' exceptions that mention 'PyInit_ycm_core' or ~
'initycm_core' ~
These errors are caused by building the YCM native libraries for Python 2 and These errors are caused by building the YCM native libraries for Python 2 and
trying to load them into a Python 3 process (or the other way around). trying to load them into a Python 3 process (or the other way around).
@ -3083,7 +3106,8 @@ problem. Common values for that option are '/usr/bin/python' and
'/usr/bin/python3'. '/usr/bin/python3'.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
I get a linker warning regarding *libpython* on Mac when compiling YCM *youcompleteme-i-get-linker-warning-regarding-libpython-on-mac-when-compiling-ycm*
I get a linker warning regarding 'libpython' on Mac when compiling YCM ~
If the warning is "ld: warning: path '/usr/lib/libpython2.7.dylib' following -L If the warning is "ld: warning: path '/usr/lib/libpython2.7.dylib' following -L
not a directory", then feel free to ignore it; it's caused by a limitation of not a directory", then feel free to ignore it; it's caused by a limitation of
@ -3154,7 +3178,7 @@ has to explicitly select something. If something is being selected
automatically, this means there's a bug or a misconfiguration somewhere. automatically, this means there's a bug or a misconfiguration somewhere.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*E227:-mapping-already-exists-for-blah* *youcompleteme-i-get-e227-mapping-already-exists-for-blah-error-when-i-start-vim*
I get a 'E227: mapping already exists for <blah>' error when I start Vim ~ I get a 'E227: mapping already exists for <blah>' error when I start Vim ~
This means that YCM tried to set up a key mapping but failed because you This means that YCM tried to set up a key mapping but failed because you
@ -3166,7 +3190,7 @@ with your own. Then change that option value to something else so that the
conflict goes away. conflict goes away.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*GLIBC_2.XX-not-found()* *youcompleteme-i-get-glibc_2.xx-not-found-when-starting-vim*
I get "'GLIBC_2.XX' not found (required by libclang.so)" when starting Vim ~ I get "'GLIBC_2.XX' not found (required by libclang.so)" when starting Vim ~
Your system is too old for the precompiled binaries from llvm.org. Compile Your system is too old for the precompiled binaries from llvm.org. Compile
@ -3191,7 +3215,7 @@ fixes that should make YCM work with such a configuration. Also rebuild Macvim
then. If you still get problems with this, see issue #18 [73] for suggestions. then. If you still get problems with this, see issue #18 [73] for suggestions.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*LONG_BIT-definition-appears-wrong-for-platform* *youcompleteme-i-get-long_bit-definition-appears-wrong-for-platform-when-compiling*
I get 'LONG_BIT definition appears wrong for platform' when compiling ~ I get 'LONG_BIT definition appears wrong for platform' when compiling ~
Look at the output of your CMake call. There should be a line in it like the Look at the output of your CMake call. There should be a line in it like the
@ -3224,7 +3248,7 @@ to make sure you use the same version of Python that your Vim binary is built
against, which is highly likely to be the system's default Python. against, which is highly likely to be the system's default Python.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*libpython2.7.a-...-relocation-R_X86_64_32* *youcompleteme-i-get-libpython2.7.a-...-relocation-r_x86_64_32-when-compiling*
I get 'libpython2.7.a [...] relocation R_X86_64_32' when compiling ~ I get 'libpython2.7.a [...] relocation R_X86_64_32' when compiling ~
The error is usually encountered when compiling YCM on Centos or RHEL. The full The error is usually encountered when compiling YCM on Centos or RHEL. The full
@ -3242,7 +3266,7 @@ version of libpython on your machine (for instance,
to go through the full installation guide by hand. to go through the full installation guide by hand.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*Vim:-Caught-deadly-signal-SEGV* *youcompleteme-i-get-vim-caught-deadly-signal-segv-on-vim-startup*
I get 'Vim: Caught deadly signal SEGV' on Vim startup ~ I get 'Vim: Caught deadly signal SEGV' on Vim startup ~
This can happen on some Linux distros. If you encounter this situation, run Vim This can happen on some Linux distros. If you encounter this situation, run Vim
@ -3257,10 +3281,10 @@ you are using a correct 'libclang.so'. We recommend downloading prebuilt
binaries from llvm.org. binaries from llvm.org.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*Fatal-Python-error:-PyThreadState_Get:-no-current-thread* *youcompleteme-i-get-fatal-python-error-pythreadstate_get-no-current-thread-on-startup*
I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup ~ I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup ~
This is caused by linking a static version of |libpython| into ycmd's This is caused by linking a static version of 'libpython' into ycmd's
'ycm_core.so'. This leads to multiple copies of the python interpreter loaded 'ycm_core.so'. This leads to multiple copies of the python interpreter loaded
when 'python' loads 'ycmd_core.so' and this messes up python's global state. when 'python' loads 'ycmd_core.so' and this messes up python's global state.
The details aren't important. The details aren't important.
@ -3275,7 +3299,8 @@ achieved as follows (**NOTE:** for Mac, replace '--enable-shared' with
pyenv install {version}' pyenv install {version}'
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*install.py* says python must be compiled with '--enable-framework'. Wat? *youcompleteme-install.py-says-python-must-be-compiled-with-enable-framework-.-wat*
'install.py' says python must be compiled with '--enable-framework'. Wat? ~
See the previous answer for how to ensure your python is built to support See the previous answer for how to ensure your python is built to support
dynamic modules. dynamic modules.
@ -3307,7 +3332,7 @@ buffer, run ':echo tagfiles()' with the relevant buffer active. Note that that
function will only list tag files that already exist. function will only list tag files that already exist.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*CTRL-sub-U* *youcompleteme-ctrl-u-in-insert-mode-does-not-work-while-completion-menu-is-visible*
'CTRL-U' in insert mode does not work while the completion menu is visible ~ 'CTRL-U' in insert mode does not work while the completion menu is visible ~
YCM uses 'completefunc' completion mode to show suggestions and Vim disables YCM uses 'completefunc' completion mode to show suggestions and Vim disables
@ -3327,7 +3352,8 @@ options:
g:UltiSnipsJumpBackwardTrigger g:UltiSnipsJumpBackwardTrigger
< <
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Snippets added with *:UltiSnipsAddFiletypes* do not appear in the popup menu *youcompleteme-snippets-added-with-ultisnipsaddfiletypes-do-not-appear-in-popup-menu*
Snippets added with ':UltiSnipsAddFiletypes' do not appear in the popup menu ~
For efficiency, YCM only fetches UltiSnips snippets in specific scenarios like For efficiency, YCM only fetches UltiSnips snippets in specific scenarios like
visiting a buffer or setting its filetype. You can force YCM to retrieve them visiting a buffer or setting its filetype. You can force YCM to retrieve them
@ -3359,7 +3385,7 @@ YCM needs a version of Vim with the timers feature to achieve full
asynchronicity. This feature is available since Vim 7.4.1578. asynchronicity. This feature is available since Vim 7.4.1578.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*vim-sub-autoclose* *youcompleteme-nasty-bugs-happen-if-i-have-vim-autoclose-plugin-installed*
Nasty bugs happen if I have the 'vim-autoclose' plugin installed ~ Nasty bugs happen if I have the 'vim-autoclose' plugin installed ~
Use the delimitMate [75] plugin instead. It does the same thing without Use the delimitMate [75] plugin instead. It does the same thing without
@ -3385,7 +3411,7 @@ by setting the 'YCM_CORES' environment variable to '1'. Example:
YCM_CORES=1 ./install.py --clang-completer YCM_CORES=1 ./install.py --clang-completer
< <
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*Ctrl-sub-C* *youcompleteme-i-get-weird-errors-when-i-press-ctrl-c-in-vim*
I get weird errors when I press 'Ctrl-C' in Vim ~ I get weird errors when I press 'Ctrl-C' in Vim ~
_Never_ use 'Ctrl-C' in Vim. _Never_ use 'Ctrl-C' in Vim.
@ -3463,7 +3489,7 @@ list of flags you return from your 'FlagsForFile' function in your
See issue #303 [78] for details. See issue #303 [78] for details.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*.tern-sub-project* *youcompleteme-when-i-open-javascript-file-i-get-an-annoying-warning-about-.tern-project-file*
When I open a JavaScript file, I get an annoying warning about '.tern- ~ When I open a JavaScript file, I get an annoying warning about '.tern- ~
project' file ~ project' file ~
@ -3474,7 +3500,7 @@ If this is still really annoying, and you have a good reason not to have a
directory and YCM will stop complaining. directory and YCM will stop complaining.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*R6034-An-application-has-made-an-attempt-to-load-the-C-runtime-library-incorrectly.* *youcompleteme-when-i-start-vim-i-get-runtime-error-saying-r6034-an-application-has-made-an-attempt-to-load-c-runtime-library-incorrectly.*
When I start vim I get a runtime error saying 'R6034 An application has made ~ When I start vim I get a runtime error saying 'R6034 An application has made ~
an attempt to load the C runtime library incorrectly.' ~ an attempt to load the C runtime library incorrectly.' ~
@ -3510,7 +3536,7 @@ to the Python interpreter you use for your project to get completions for that
version of Python. version of Python.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*E887:-Sorry-this-command-is-disabled-the-Python-s-site-module-could-not-be-loaded* *youcompleteme-on-windows-i-get-e887-sorry-this-command-is-disabled-pythons-site-module-could-not-be-loaded*
On Windows I get "E887: Sorry, this command is disabled, the Python's site ~ On Windows I get "E887: Sorry, this command is disabled, the Python's site ~
module could not be loaded" ~ module could not be loaded" ~

View File

@ -38,6 +38,7 @@ class CommandRequest( BaseRequest ):
def __init__( self, arguments, completer_target = None, extra_data = None ): def __init__( self, arguments, completer_target = None, extra_data = None ):
super( CommandRequest, self ).__init__() super( CommandRequest, self ).__init__()
self._arguments = _EnsureBackwardsCompatibility( arguments ) self._arguments = _EnsureBackwardsCompatibility( arguments )
self._command = arguments and arguments[ 0 ]
self._completer_target = ( completer_target if completer_target self._completer_target = ( completer_target if completer_target
else 'filetype_default' ) else 'filetype_default' )
self._extra_data = extra_data self._extra_data = extra_data
@ -114,7 +115,8 @@ class CommandRequest( BaseRequest ):
[ fixit[ 'text' ] for fixit in self._response[ 'fixits' ] ] ) [ fixit[ 'text' ] for fixit in self._response[ 'fixits' ] ] )
vimsupport.ReplaceChunks( vimsupport.ReplaceChunks(
self._response[ 'fixits' ][ fixit_index ][ 'chunks' ] ) self._response[ 'fixits' ][ fixit_index ][ 'chunks' ],
silent = self._command == 'Format' )
except RuntimeError as e: except RuntimeError as e:
vimsupport.PostVimMessage( str( e ) ) vimsupport.PostVimMessage( str( e ) )

View File

@ -156,7 +156,7 @@ class Response_Detection_test( object ):
def FixIt_Response_test( self ): def FixIt_Response_test( self ):
# Ensures we recognise and handle fixit responses with some dummy chunk data # Ensures we recognise and handle fixit responses with some dummy chunk data
def FixItTest( command, response, chunks, selection ): def FixItTest( command, response, chunks, selection, silent ):
with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks: with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message: with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message:
with patch( 'ycm.vimsupport.SelectFromList', with patch( 'ycm.vimsupport.SelectFromList',
@ -165,7 +165,7 @@ class Response_Detection_test( object ):
request._response = response request._response = response
request.RunPostCommandActionsIfNeeded() request.RunPostCommandActionsIfNeeded()
replace_chunks.assert_called_with( chunks ) replace_chunks.assert_called_with( chunks, silent = silent )
post_vim_message.assert_not_called() post_vim_message.assert_not_called()
basic_fixit = { basic_fixit = {
@ -187,23 +187,31 @@ class Response_Detection_test( object ):
'text': 'second', 'text': 'second',
'chunks': [ { 'chunks': [ {
'dummy chunk contents': False 'dummy chunk contents': False
}] } ]
} ] } ]
} }
multi_fixit_first_chunks = multi_fixit[ 'fixits' ][ 0 ][ 'chunks' ] multi_fixit_first_chunks = multi_fixit[ 'fixits' ][ 0 ][ 'chunks' ]
multi_fixit_second_chunks = multi_fixit[ 'fixits' ][ 1 ][ 'chunks' ] multi_fixit_second_chunks = multi_fixit[ 'fixits' ][ 1 ][ 'chunks' ]
tests = [ tests = [
[ 'AnythingYouLike', basic_fixit, basic_fixit_chunks, 0 ], [ 'AnythingYouLike',
[ 'GoToEvenWorks', basic_fixit, basic_fixit_chunks, 0 ], basic_fixit, basic_fixit_chunks, 0, False ],
[ 'FixItWorks', basic_fixit, basic_fixit_chunks, 0 ], [ 'GoToEvenWorks',
[ 'and8434fd andy garbag!', basic_fixit, basic_fixit_chunks, 0 ], basic_fixit, basic_fixit_chunks, 0, False ],
[ 'select from multiple 1', multi_fixit, multi_fixit_first_chunks, 0 ], [ 'FixItWorks',
[ 'select from multiple 2', multi_fixit, multi_fixit_second_chunks, 1 ], basic_fixit, basic_fixit_chunks, 0, False ],
[ 'and8434fd andy garbag!',
basic_fixit, basic_fixit_chunks, 0, False ],
[ 'Format',
basic_fixit, basic_fixit_chunks, 0, True ],
[ 'select from multiple 1',
multi_fixit, multi_fixit_first_chunks, 0, False ],
[ 'select from multiple 2',
multi_fixit, multi_fixit_second_chunks, 1, False ],
] ]
for test in tests: for test in tests:
yield FixItTest, test[ 0 ], test[ 1 ], test[ 2 ], test[ 3 ] yield FixItTest, test[ 0 ], test[ 1 ], test[ 2 ], test[ 3 ], test[ 4 ]
def Message_Response_test( self ): def Message_Response_test( self ):

View File

@ -1,4 +1,4 @@
# Copyright (C) 2016 YouCompleteMe contributors # Copyright (C) 2016-2018 YouCompleteMe contributors
# #
# This file is part of YouCompleteMe. # This file is part of YouCompleteMe.
# #
@ -25,27 +25,34 @@ from builtins import * # noqa
from ycm.tests.test_utils import MockVimModule, MockVimBuffers, VimBuffer from ycm.tests.test_utils import MockVimModule, MockVimBuffers, VimBuffer
MockVimModule() MockVimModule()
from hamcrest import assert_that, equal_to from hamcrest import assert_that, contains, has_entries
from mock import patch from mock import patch
from ycm.tests import YouCompleteMeInstance from ycm.tests import YouCompleteMeInstance
@YouCompleteMeInstance( { 'extra_conf_vim_data': [ 'tempname()' ] } ) @YouCompleteMeInstance( { 'extra_conf_vim_data': [ 'tempname()' ] } )
def SendCommandRequest_ExtraConfData_Works_test( ycm ): def SendCommandRequest_ExtraConfVimData_Works_test( ycm ):
current_buffer = VimBuffer( 'buffer' ) current_buffer = VimBuffer( 'buffer' )
with MockVimBuffers( [ current_buffer ], current_buffer ): with MockVimBuffers( [ current_buffer ], current_buffer ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python' ) ycm.SendCommandRequest( [ 'GoTo' ], 'python', False, 1, 1 )
send_request.assert_called_once_with(
[ 'GoTo' ], 'python', { 'extra_conf_data': {
'tempname()': '_TEMP_FILE_' } }
)
with patch( 'ycm.client.base_request.JsonFromFuture',
return_value = 'Some response' ):
assert_that( assert_that(
ycm.SendCommandRequest( [ 'GoTo' ], 'python' ), # Positional arguments passed to SendCommandRequest.
equal_to( 'Some response' ) send_request.call_args[ 0 ],
contains(
contains( 'GoTo' ),
'python',
has_entries( {
'options': has_entries( {
'tab_size': 2,
'insert_spaces': True,
} ),
'extra_conf_data': has_entries( {
'tempname()': '_TEMP_FILE_'
} ),
} )
)
) )
@ -54,13 +61,79 @@ def SendCommandRequest_ExtraConfData_UndefinedValue_test( ycm ):
current_buffer = VimBuffer( 'buffer' ) current_buffer = VimBuffer( 'buffer' )
with MockVimBuffers( [ current_buffer ], current_buffer ): with MockVimBuffers( [ current_buffer ], current_buffer ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python' ) ycm.SendCommandRequest( [ 'GoTo' ], 'python', False, 1, 1 )
send_request.assert_called_once_with(
[ 'GoTo' ], 'python', { 'extra_conf_data': {} }
)
with patch( 'ycm.client.base_request.JsonFromFuture',
return_value = 'Some response' ):
assert_that( assert_that(
ycm.SendCommandRequest( [ 'GoTo' ], 'python' ), # Positional arguments passed to SendCommandRequest.
equal_to( 'Some response' ) send_request.call_args[ 0 ],
contains(
contains( 'GoTo' ),
'python',
has_entries( {
'options': has_entries( {
'tab_size': 2,
'insert_spaces': True,
} )
} )
)
)
@YouCompleteMeInstance()
def SendCommandRequest_BuildRange_NoVisualMarks_test( ycm, *args ):
current_buffer = VimBuffer( 'buffer', contents = [ 'first line',
'second line' ] )
with MockVimBuffers( [ current_buffer ], current_buffer ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python', True, 1, 2 )
send_request.assert_called_once_with(
[ 'GoTo' ],
'python',
{
'options': {
'tab_size': 2,
'insert_spaces': True
},
'range': {
'start': {
'line_num': 1,
'column_num': 1
},
'end': {
'line_num': 2,
'column_num': 12
}
}
}
)
@YouCompleteMeInstance()
def SendCommandRequest_BuildRange_VisualMarks_test( ycm, *args ):
current_buffer = VimBuffer( 'buffer',
contents = [ 'first line',
'second line' ],
visual_start = [ 1, 4 ],
visual_end = [ 2, 8 ] )
with MockVimBuffers( [ current_buffer ], current_buffer ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python', True, 1, 2 )
send_request.assert_called_once_with(
[ 'GoTo' ],
'python',
{
'options': {
'tab_size': 2,
'insert_spaces': True
},
'range': {
'start': {
'line_num': 1,
'column_num': 5
},
'end': {
'line_num': 2,
'column_num': 9
}
}
}
) )

View File

@ -152,6 +152,9 @@ def _MockVimOptionsEval( value ):
if value == '&hidden': if value == '&hidden':
return 0 return 0
if value == '&expandtab':
return 1
return None return None
@ -199,6 +202,9 @@ def _MockVimEval( value ):
if value == 'tagfiles()': if value == 'tagfiles()':
return [ 'tags' ] return [ 'tags' ]
if value == 'shiftwidth()':
return 2
result = _MockVimOptionsEval( value ) result = _MockVimOptionsEval( value )
if result is not None: if result is not None:
return result return result
@ -260,7 +266,9 @@ class VimBuffer( object ):
modified = False, modified = False,
bufhidden = '', bufhidden = '',
window = None, window = None,
omnifunc = None ): omnifunc = None,
visual_start = None,
visual_end = None ):
self.name = os.path.realpath( name ) if name else '' self.name = os.path.realpath( name ) if name else ''
self.number = number self.number = number
self.contents = contents self.contents = contents
@ -275,6 +283,8 @@ class VimBuffer( object ):
'mod': modified, 'mod': modified,
'bh': bufhidden 'bh': bufhidden
} }
self.visual_start = visual_start
self.visual_end = visual_end
def __getitem__( self, index ): def __getitem__( self, index ):
@ -295,6 +305,14 @@ class VimBuffer( object ):
return [ ToUnicode( x ) for x in self.contents ] return [ ToUnicode( x ) for x in self.contents ]
def mark( self, name ):
if name == '<':
return self.visual_start
if name == '>':
return self.visual_end
raise ValueError( 'Unexpected mark: {name}'.format( name = name ) )
class VimBuffers( object ): class VimBuffers( object ):
"""An object that looks like a vim.buffers object.""" """An object that looks like a vim.buffers object."""

View File

@ -1083,3 +1083,31 @@ def _SetUpLoadedBuffer( command, filename, fix, position, watch ):
if position == 'end': if position == 'end':
vim.command( 'silent! normal! Gzz' ) vim.command( 'silent! normal! Gzz' )
def BuildRange( start_line, end_line ):
# Vim only returns the starting and ending lines of the range of a command.
# Check if those lines correspond to a previous visual selection and if they
# do, use the columns of that selection to build the range.
start = vim.current.buffer.mark( '<' )
end = vim.current.buffer.mark( '>' )
if not start or not end or start_line != start[ 0 ] or end_line != end[ 0 ]:
start = [ start_line, 0 ]
end = [ end_line, len( vim.current.buffer[ end_line - 1 ] ) ]
# Vim Python API returns 1-based lines and 0-based columns while ycmd expects
# 1-based lines and columns.
return {
'range': {
'start': {
'line_num': start[ 0 ],
'column_num': start[ 1 ] + 1
},
'end': {
'line_num': end[ 0 ],
# Vim returns the maximum 32-bit integer value when a whole line is
# selected. Use the end of line instead.
'column_num': min( end[ 1 ],
len( vim.current.buffer[ end[ 0 ] - 1 ] ) ) + 1
}
}
}

View File

@ -327,8 +327,20 @@ class YouCompleteMe( object ):
return response return response
def SendCommandRequest( self, arguments, completer ): def SendCommandRequest( self,
extra_data = {} arguments,
completer,
has_range,
start_line,
end_line ):
extra_data = {
'options': {
'tab_size': vimsupport.GetIntValue( 'shiftwidth()' ),
'insert_spaces': vimsupport.GetBoolValue( '&expandtab' )
}
}
if has_range:
extra_data.update( vimsupport.BuildRange( start_line, end_line ) )
self._AddExtraConfDataIfNeeded( extra_data ) self._AddExtraConfDataIfNeeded( extra_data )
return SendCommandRequest( arguments, completer, extra_data ) return SendCommandRequest( arguments, completer, extra_data )