Youcompleteme: Feature Request: RefactorRename support in C++ through clang-rename

Created on 31 Jul 2019  Â·  14Comments  Â·  Source: ycm-core/YouCompleteMe

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside
the brackets) _before_ filing your issue:

  • [x] I have read and understood YCM's CONTRIBUTING document.
  • [x] I have read and understood YCM's CODE_OF_CONDUCT document.
  • [x] I have read and understood YCM's README, especially the
    Frequently Asked Questions section.
  • [x] I have searched YCM's issue tracker to find issues similar to the one I'm
    about to report and couldn't find an answer to my problem. (Example Google
    search.
    )
  • [ ] If filing a bug report, I have included the output of vim --version.
  • [ ] If filing a bug report, I have included the output of :YcmDebugInfo.
  • [ ] If filing a bug report, I have attached the contents of the logfiles using
    the :YcmToggleLogs command.
  • [ ] If filing a bug report, I have included which OS (including specific OS
    version) I am using.
  • [ ] If filing a bug report, I have included a minimal test case that reproduces
    my issue, including what I expected to happen and what actually happened.
  • [ ] If filing a installation failure report, I have included the entire output
    of install.py (or cmake/make/ninja) including its invocation
  • [x] I understand this is an open-source project staffed by volunteers and
    that any help I receive is a selfless, heartfelt _gift_ of their free time. I
    know I am not entitled to anything and will be polite and courteous.
  • [x] I understand my issue may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Issue Details

I was wondering if RefactorRename would be supoorted in C++ projects using clang-rename.

There are two somewhat limited ways I could find for integrating it to vim currently: the integration provided by clang and third party vim-clang-rename plugin. Official integration replaces files inplace, therefore it requires saving buffers before and loading them after. Compiler flags are read from compilation database. This is somewhat limited compared to .ycm_extra_config (e.g. header files). The latter plugin has an option g:clang_rename#flags, but it didn't look like a convenient way for managing flags for multiple projects.

This would be a vastly helpful feature if it were to be included in YCM. Thanks.

Most helpful comment

For information:
To get multi-file refactor support the clangd's experimental cross-file-rename must be enabled with option --cross-file-rename, e.g. let g:ycm_clangd_args = ['-cross-file-rename']

All 14 comments

clangd has local-rename support. See the docs for how to use clangd.

Re-open because the docs don't actually say which features clangd supports vs libclang. Maybe we can improve that. Anyway let us know how you get on with clangd.

Thanks. I tried it with clangd, but it appears it doesn't recognize .ycm_extra_conf.py.

I tried it with this file:

  #include <variant>                                                                                     

  int main() {                                                                                           
      std::variant<int, double> myvar;                                                                   
      myvar = 3;                                                                                         
      myvar = 5.0;                                                                                       
      return 0;                                                                                          
  }              

It gives below errors:

rename.cpp|4 col 5 error| Use of undeclared identifier 'std' [undeclared_var_use]                        
rename.cpp|5 col 5 error| Use of undeclared identifier 'myvar' [undeclared_var_use]                      
rename.cpp|6 col 5 error| Use of undeclared identifier 'myvar' [undeclared_var_use]

Also tried with this and it gives error:

  #if __cplusplus == 201402L                                                                             
  #error "Using C++14"                                                                                   
  #endif

My .ycm_extra_conf is pretty much same with this except it uses C++17:

 ~/tmp/rename î‚° diff .ycm_extra_conf.py <(wget https://raw.githubusercontent.com/puremourning/ycmd-1/master/ycmd/default_ycm_extra_conf.py -O-)

Redirecting output to ‘wget-log’.
148c148
<     '-std=c++17',
---
>     '-std=c++11',
155c155
<     '-std=c11',
---
>     '-std=c99',

Some more debugging info:

Printing YouCompleteMe debug information...                                                              
-- Client logfile: /tmp/ycm_d19xl7kt.log                                                                 
-- Server Python interpreter: /usr/bin/python3                                                           
-- Server Python version: 3.7.3                                                                          
-- Server has Clang support compiled in: True                                                            
-- Clang version: clang version 7.0.0 (tags/RELEASE_700/final)                                           
-- Extra configuration file found and loaded                                                             
-- Extra configuration path: /home/omer/tmp/rename/.ycm_extra_conf.py                                    
-- C-family completer debug information:                                                                 
--   Clangd running                                                                                      
--   Clangd process ID: 26346                                                                            
--   Clangd executable: ['/usr/bin/clangd-9', '-header-insertion-decorators=0']                          
--   Clangd logfiles:                                                                                    
--     /tmp/clangd_stderrrxj5mzz2.log                                                                    
--   Clangd Server State: Initialized                                                                    
--   Clangd Project Directory: /home/omer/tmp/rename                                                     
--   Clangd Settings: {}                                                                                 
--   Clangd Compilation Command: False                                                                   
-- Server running at: http://127.0.0.1:50865                                                             
-- Server process ID: 26302                                                                              
-- Server logfiles:                                                                                      
--   /tmp/ycmd_50865_stdout_2rk5pd9i.log                                                                 
--   /tmp/ycmd_50865_stderr_xlw92ses.log

/tmp/ycm_d19xl7kt.log was empty

/tmp/clangd_stderrrxj5mzz2.log

I[15:25:00.320] <-- initialize("1")                                                                      
I[15:25:00.320] --> reply:initialize("1") 0 ms                                                           
I[15:25:00.320] <-- initialized                                                                          
I[15:25:00.320] unhandled notification initialized                                                       
I[15:25:00.320] <-- workspace/didChangeConfiguration                                                     
I[15:25:00.320] <-- textDocument/didOpen                                                                 
I[15:25:00.321] Failed to find compilation database for /home/omer/tmp/rename/rename.cpp                 
I[15:25:00.321] Updating file /home/omer/tmp/rename/rename.cpp with command clangd fallback              
[/home/omer/tmp/rename]                                                                                  
/usr/lib/llvm-9/bin/clang /home/omer/tmp/rename/rename.cpp -fsyntax-only -resource-dir=/usr/lib/llvm-9/lib/clang/9.0.0                                                                                            
I[15:25:00.328] --> textDocument/publishDiagnostics                                                      

/tmp/ycmd_50865_stdout_2rk5pd9i.log

serving on http://localhost:50865                                                                        

/tmp/ycmd_50865_stderr_xlw92ses.log

2019-07-31 15:25:00,275 - INFO - Received ready request                                                  
2019-07-31 15:25:00,277 - INFO - Received event notification                                             
2019-07-31 15:25:00,278 - INFO - Received event notification                                             
2019-07-31 15:25:00,278 - INFO - Adding buffer identifiers for file: /home/omer/tmp/rename/rename.cpp    
2019-07-31 15:25:00,308 - INFO - Using Clangd from /usr/bin/clangd-9                                     
2019-07-31 15:25:00,309 - INFO - Computed Clangd command: ['/usr/bin/clangd-9', '-header-insertion-decorators=0']                                                                                                 
2019-07-31 15:25:00,309 - INFO - Returning cached Clangd command: ['/usr/bin/clangd-9', '-header-insertion-decorators=0']                                                                                         
2019-07-31 15:25:00,310 - INFO - Starting Clangd: ['/usr/bin/clangd-9', '-header-insertion-decorators=0']2019-07-31 15:25:00,313 - INFO - Clangd started                                                          
2019-07-31 15:25:00,320 - INFO - Language server requires sync type of Incremental                       
2019-07-31 15:25:00,380 - INFO - Received filetype completion available request                          
2019-07-31 15:25:10,234 - INFO - Received debug info request                                             
2019-07-31 15:25:48,716 - INFO - Received debug info request                                             

vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 15 2019 16:41:15)                                       Included patches: 1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401                                      Modified by [email protected]                                                                  Compiled by [email protected]                                                                  Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static                                 +arabic            +farsi             +mouse_sgr         -tag_any_white                                  +autocmd           +file_in_path      -mouse_sysmouse    +tcl                                           
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors                                  -autoservername    +float             +mouse_xterm       +terminal                                       +balloon_eval      +folding           +multi_byte        +terminfo                                       +balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        +toolbar
+clientserver      +job               +perl              +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         +python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua               +ruby              +windows
+dialog_con_gui    +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             +X11
+digraphs          +modify_fname      +smartindent       -xfontset
+dnd               +mouse             +startuptime       +xim
-ebcdic            +mouseshape        +statusline        +xpm
+emacs_tags        +mouse_dec         -sun_workshop      +xsmp_interact
+eval              +mouse_gpm         +syntax            +xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-4Pursk/vim-8.1.0875=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.28/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu -lpython3.7m -lcrypt -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.5 -lpthread -lgmp -ldl -lcrypt -lm

git stuff:

 ~/.vim/plugged/YouCompleteMe î‚° î‚  master î‚° git --no-pager log -1 --pretty=oneline
afa2ea03d03e6793d34704e4c75f2846ecbffd52 (HEAD -> master, origin/master, origin/HEAD) Add link to compiledb to README
 ~/.vim/plugged/YouCompleteMe î‚° î‚  master î‚° git --no-pager submodule foreach git log -1 --pretty=oneline
Entering 'third_party/python-future'
a8114e48ce7dbc4cecbf6a764d73e83d03b0d6ba (HEAD, origin/master, origin/HEAD, master) Merge pull request #406 from jmadler/v0.17.x
Entering 'third_party/requests-futures'
98712e7d0f6be2a090b6fda2a925f85e63656b58 (HEAD) Merge pull request #10 from mkai/_max_workers_poolsize
Entering 'third_party/requests_deps/certifi'
5b9e05c06e69fe5c7835052cfc3ae1c899dfc8b1 (HEAD) Merge pull request #96 from adamchainz/https
Entering 'third_party/requests_deps/chardet'
9b8c5c2fb118d76c6beeab9affd01c332732a530 (HEAD, tag: 3.0.4, origin/stable) Bump version to 3.0.4
Entering 'third_party/requests_deps/idna'
0f50bdcea71e6602bf4cd22897970d71fc4074d9 (HEAD) Preliminary Unicode 11.0.0 data
Entering 'third_party/requests_deps/requests'
6cfbe1aedd56f8c2f9ff8b968efe65b22669795b (HEAD, tag: v2.20.1) v2.20.1
Entering 'third_party/requests_deps/urllib3'
a6ec68a5c5c5743c59fe5c62c635c929586c429b (HEAD, tag: 1.24.1, origin/release) Merging new release version: 1.24.1
Entering 'third_party/ycmd'
14a616c846f13a9ccb3003b04f390bd6071c7a95 (HEAD) Merge pull request #1276 from bstaletic/cs-no-debug-subs

Nevermind. It's stated in README that clangd doesn't support this. hmph.

are you using the latest ycm ? ycm supports extra conf with clangd but you have to use the Settings function rather than FlagsForFile

Yes. I tested it with up to date YCM. I was actually using something based on your default config, but I guess I need to add Settings to it. Let me try adding it.

Appending Settings solves it indeed:

def Settings( **kwargs ):                                                                                
    return FlagsForFile( kwargs[ 'filename' ], **kwargs)

:YcmCompleter RefactorRename also worked fine. Thanks!

Great!

Correction:

def Settings( **kwargs ):
    filename = kwargs.pop( 'filename' )
    return FlagsForFile( filename, **kwargs )

For information:
To get multi-file refactor support the clangd's experimental cross-file-rename must be enabled with option --cross-file-rename, e.g. let g:ycm_clangd_args = ['-cross-file-rename']

For information:
To get multi-file refactor support the clangd's experimental cross-file-rename must be enabled with option --cross-file-rename, e.g. let g:ycm_clangd_args = ['-cross-file-rename']

This should be added to the documentation, section "Multi-file Refactor" ...

For information:
To get multi-file refactor support the clangd's experimental cross-file-rename must be enabled with option --cross-file-rename, e.g. let g:ycm_clangd_args = ['-cross-file-rename']

This should be added to the documentation, section "Multi-file Refactor" ...

I believe this flag is no longer needed now that we're on clangd 11.

For information:
To get multi-file refactor support the clangd's experimental cross-file-rename must be enabled with option --cross-file-rename, e.g. let g:ycm_clangd_args = ['-cross-file-rename']

This should be added to the documentation, section "Multi-file Refactor" ...

I believe this flag is no longer needed now that we're on clangd 11.

Yesterday I installed YCM as a fresh installation and it installed clangd version 10. It took me a while to find this thread to make the RefactorRename feature work.

#:~/.vim/bundle/YouCompleteMe$ ./third_party/ycmd/third_party/clangd/output/bin/clangd --version
clangd version 10.0.0 (https://github.com/ycm-core/llvm 038587147cf2f97d1c3e677042f69560c65b5bea)

How to make it install clangd 11 ?

Oh maybe we didn’t update the ycmd submodule yet. It won’t be needed when we do that.

Was this page helpful?
0 / 5 - 0 ratings