Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: GoToDefinition/Declaration does not work for macros #758

Closed
kubinux opened this issue Jan 5, 2014 · 10 comments
Closed

C++: GoToDefinition/Declaration does not work for macros #758

kubinux opened this issue Jan 5, 2014 · 10 comments

Comments

@kubinux
Copy link

kubinux commented Jan 5, 2014

Given the following translation unit:

//
// This comment is to make the file longer than 5 lines
//
#define FOO int

FOO a;

Positioning the cursor on the second FOO token and executing :YcmCompleter GoToDefinitionElseDeclaration gives the following error:
RuntimeError: Can't jump to definition or declaration.. This works in clang_complete.

Server logs:

2014-01-05 12:27:43,398 - DEBUG - Global extra conf not loaded or no function YcmCorePreload
serving on http://127.0.0.1:37517
2014-01-05 12:27:43,838 - INFO - Received event notification
2014-01-05 12:27:43,840 - DEBUG - Event name: BufferVisit
2014-01-05 12:27:43,845 - INFO - Received event notification
2014-01-05 12:27:43,846 - DEBUG - Event name: FileReadyToParse
2014-01-05 12:27:43,846 - INFO - Adding buffer identifiers for file: /home/kuba/cppgm/dev/test.cpp
2014-01-05 12:27:48,045 - INFO - Received health request
2014-01-05 12:27:48,054 - INFO - Received command request
Traceback (most recent call last):
  File "/home/kuba/.vim/bundle/YouCompleteMe/third_party/bottle/bottle.py", line 861, in _handle
    return route.call(**args)
  File "/home/kuba/.vim/bundle/YouCompleteMe/third_party/bottle/bottle.py", line 1725, in wrapper
    rv = callback(*a, **ka)
  File "/home/kuba/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/server/watchdog_plugin.py", line 76, in wrapper
    return callback( *args, **kwargs )
  File "/home/kuba/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/server/handlers.py", line 82, in RunCompleterCommand
    request_data ) )
  File "/home/kuba/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/completers/cpp/clang_completer.py", line 120, in OnUserCommand
    return self._GoToDefinitionElseDeclaration( request_data )
  File "/home/kuba/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/completers/cpp/clang_completer.py", line 171, in _GoToDefinitionElseDeclaration
    raise RuntimeError( 'Can\'t jump to definition or declaration.' )
RuntimeError: Can't jump to definition or declaration.
$ uname -a
Linux x301 3.11-2-amd64 #1 SMP Debian 3.11.10-1 (2013-12-04) x86_64 GNU/Linux
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct  9 2013 04:13:14)
Zadane łaty: 1-52
Zmieniony przez pkg-vim-maintainers@lists.alioth.debian.org
Skompilowany przez jamessan@debian.org
Olbrzymia wersja z GTK2-GNOME GUI.  Opcje włączone (+) lub nie (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
+balloon_eval    +float           +mouse_urxvt     -tag_any_white
+browse          +folding         +mouse_xterm     +tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
+clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      +toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con_gui  +lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      +X11
+dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     +xim
+emacs_tags      +mouseshape      -sniff           +xsmp_interact
+eval            +mouse_dec       +startuptime     +xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    +xpm
       vimrc systemu: "$VIM/vimrc"
   vimrc użytkownika: "$HOME/.vimrc"
 2-gi plik vimrc użytkownika: "~/.vim/vimrc"
    exrc użytkownika: "$HOME/.exrc"
     gvimrc systemu: "$VIM/gvimrc"
  gvimrc użytkownika: "$HOME/.gvimrc"
2-gi plik gvimrc użytkownika: "~/.vim/gvimrc"
 systemowy plik menu: "$VIMRUNTIME/menu.vim"
   odwet dla $VIM-a: "/usr/share/vim"
Kompilacja: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/libdrm -I/usr/include/harfbuzz   -pthread -DORBIT2=1 -D_REENTRANT -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-keyring-1 -I/usr/include/gtk-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libxml2 -I/usr/include/pango-1.0 -I/usr/include/gail-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/cairo -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/libdrm -I/usr/include/libgnomeui-2.0 -I/usr/include/libgnome-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/gnome-vfs-2.0/include -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1     -I/usr/include/tcl8.5  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_LARGEFILE64_SOURCE=1  
Konsolidacja: gcc   -L. -Wl,-z,relro -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-z,relro -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0     -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgconf-2 -lgthread-2.0 -lgmodule-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.1 -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.18/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  -L/usr/lib -ltcl8.5 -ldl -lpthread -lieee -lm -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib
@kubinux
Copy link
Author

kubinux commented Jan 5, 2014

I've managed to get it working by adding an extra CXTranslationUnit_DetailedPreprocessingRecord option to all parse/reparse calls in clang_completer.

@Valloric
Copy link
Member

Valloric commented Jan 5, 2014

I've managed to get it working by adding an extra CXTranslationUnit_DetailedPreprocessingRecord option to all parse/reparse calls in clang_completer.

I'm worried about the impact of that option on completion lookup speed. I'm going to have to run some benchmarks with and without the option.

@taoso
Copy link

taoso commented Jan 10, 2014

@kubus-puchatek Could you offser more details? Thank you :)

@kubinux
Copy link
Author

kubinux commented Jan 10, 2014

@jlyu Here's a diff of my changes:

diff --git a/cpp/ycm/ClangCompleter/TranslationUnit.cpp b/cpp/ycm/ClangCompleter/TranslationUnit.cpp
index 02dad2c..e544a83 100644
--- a/cpp/ycm/ClangCompleter/TranslationUnit.cpp
+++ b/cpp/ycm/ClangCompleter/TranslationUnit.cpp
@@ -66,6 +66,7 @@ TranslationUnit::TranslationUnit(
                               pointer_flags.size(),
                               const_cast<CXUnsavedFile *>( unsaved ),
                               cxunsaved_files.size(),
+                              CXTranslationUnit_DetailedPreprocessingRecord |
                               clang_defaultEditingTranslationUnitOptions() );

   if ( !clang_translation_unit_ )
@@ -249,7 +250,7 @@ void TranslationUnit::Reparse( std::vector< CXUnsavedFile > &unsaved_files,
     failure = clang_reparseTranslationUnit( clang_translation_unit_,
                                             unsaved_files.size(),
                                             unsaved,
-                                            parse_options );
+                                            CXTranslationUnit_DetailedPreprocessingRecord | parse_options );
   }

   if ( failure ) {

@Valloric
Copy link
Member

I'm up to my neck in work, so if you could run some benchmarks for before/after, that would be great. You should look into the LIBCLANG_TIMING env var (when set, you'll get timing data from libclang on ycmd stdout).

@marvin2k
Copy link

marvin2k commented Feb 1, 2014

While debugging an ultimately unrelated problem I ran the numbers. Throwing them away would be a pity. Opening TranslationUnit.cpp, going to line 256 column 18 and calling ":YcmCompleter DoToDefinition".

unchanged version
changed version

No interpretation. Repeated the run -- all numbers, text stripped away

Laptop with SSD

@hasufell
Copy link

hasufell commented Feb 5, 2014

patch works nicely

@daedric
Copy link

daedric commented Apr 4, 2014

Hum, The patch works so well that I've the feeling it is actually faster than before...

@kubinux
Copy link
Author

kubinux commented Apr 4, 2014

Maybe we could at least have a config option to turn it on/off? We would be able to enable it if we mainly work with code that is full of macros (like C).

@marvin2k
Copy link

marvin2k commented Apr 4, 2014

This is a compile time flag for a cpp library. Its not easy to change during runtime?

I would argue that having a better completion is "always" worth a speed-expense

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants