ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.45k stars 2.81k forks source link

Expected unqualified-id in C's header file #4255

Closed JoeAndMark closed 2 months ago

JoeAndMark commented 2 months ago

Issue Prelude

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

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

What did you do?

  1. touch object.h
  2. vim object.h
  3. Enter insert mode and type following C codes:
#ifndef __OBJECT_H__

void* new(const void* class, ...);
void delete(void* self);

#endif /*__OBJECT_H__  */

Description

I just work with my object-oriented library in C language. I want to implement these two functions, but YCM thinks they are wrong, and report Expected unqualified-id [expected_unqualified_id] error. I found it that Vim think .h is a CPP's header file, so I let Vim change its opinion with autocmd BufNewFile,BufRead *.h set filetype=c in my .vimrc. But this error still exists, I am confused because I have specified '-std=c99' and 'c' in flags in my .ycm_extra_config.py.

Diagnostic data

Output of vim --version

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Apr 25 2024 16:37:58)
Included patches: 1-369
Compiled by root@BFmHNO3
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term -gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     +perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3           +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          -ruby              +wildignore
+cursorbind        +lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      -sodium            -X11
+digraphs          +mouse             -sound             +xattr
-dnd               -mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        -mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
 3rd user vimrc file: "~/.config/vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/vim/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-E -L/usr/local/lib -Wl,--as-needed -o vim -lm -ltinfo -L/usr/lib -llua5.3 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.30/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm

Output of YcmDebugInfo

Printing YouCompleteMe debug information...
-- Resolve completions: Never
-- Client logfile: /tmp/ycm_82lcrxa3.log
-- Server Python interpreter: /opt/miniforge3/bin/python3
-- Server Python version: 3.10.14
-- Server has Clang support compiled in: False
-- Clang version: None
-- Extra configuration file found and loaded
-- Extra configuration path: /home/bfmhno3/.ycm_extra_conf.py
-- C-family completer debug information:
--   Clangd running
--   Clangd process ID: 52506
--   Clangd executable: ['/home/bfmhno3/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/home/bfmhno3/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/18.1.3', '-limit-results=500']
--   Clangd logfiles:
--     /tmp/clangd_stderrjd0t5rfe.log
--   Clangd Server State: Initialized
--   Clangd Project Directory: /home/bfmhno3
--   Clangd Open Workspaces: {'/home/bfmhno3'}
--   Clangd Settings: {}
--   Clangd Compilation Command: False
-- Server running at: http://127.0.0.1:60943
-- Server process ID: 52478
-- Server logfiles:
--   /tmp/ycmd_60943_stdout_11q5p3gk.log
--   /tmp/ycmd_60943_stderr_bpmhv4dp.log
-- Semantic highlighting supported: True
-- Virtual text supported: True
-- Popup windows supported: True

Output of YcmDiags

object.h|3 col 7 error| Expected unqualified-id [expected_unqualified_id]
object.h|4 col 6 error| Expected unqualified-id [expected_unqualified_id]

Output of git rev-parse HEAD in YouCompleteMe installation directory

5d8a7fe9304113c66568be60100b2600860cc505

Contents of YCM, ycmd and completion engine logfiles

Reproduce the issue with vim -Nu /path/to/YCM/vimrc_ycm_minimal, which enabled debug logging and other useful diagnostics. Include a link to a gist containing all of the log files listed by :YcmToggleLogs.

My gist is here.

OS version, distribution, etc.

            .-/+oossssoo+/-.               user@hostname
        `:+ssssssssssssssssss+:`           ---------------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 22.04.4 LTS on Windows 10 x86_64
    .ossssssssssssssssssdMMMNysssso.       Kernel: 5.15.153.1-microsoft-standard-WSL2
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 3 hours, 20 mins
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 1234 (dpkg), 6 (snap)
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: zsh 5.8
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Terminal: Relay(53334)
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   CPU: 13th Gen Intel i5-13500H (16) @ 3.187GHz
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   GPU: 73cd:00:00.0 Microsoft Corporation Device 008e
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Memory: 625MiB / 7808MiB
+sssshhhyNMMNyssssssssssssyNMMMysssssss+
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.

Output of build/install commands

Include link to a gist containing the invocation and entire output of install.py if reporting an installation issue.

bstaletic commented 2 months ago

That's odd. I can't repro at all and this really should not happen. If you have clang available, try compiling your file with clang.

puremourning commented 2 months ago

Please share your extra conf file

I think it's not working.

Clangd Compilation Command: False

https://gist.github.com/JoeAndMark/88f33342ed2b1b55fc6159196c59cbf8#file-clangd_stderr5nlvxsp_-log-L31

JoeAndMark commented 2 months ago

Please share your extra conf file

I think it's not working.

Clangd Compilation Command: False

https://gist.github.com/JoeAndMark/88f33342ed2b1b55fc6159196c59cbf8#file-clangd_stderr5nlvxsp_-log-L31

I have added my .ycm_extra_conf.py, you can inspect it at the following URL:

JoeAndMark commented 2 months ago

That's odd. I can't repro at all and this really should not happen. If you have clang available, try compiling your file with clang.

The YCM what I use is compiled with --clangd-completer, so I just recompiled it with '--clang-completer'. I add the output to my gist, you can inspect it at the following URL:

But the interesting thing is that the error still exists, I have no idea about it.

Some other information you may want to know:

  1. clang version

    Ubuntu clang version 14.0.0-1ubuntu1.1
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
  2. clangd version

    clangd version 10.0.0-4ubuntu1
  3. Local YCM repository status

    
    On branch master
    Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

puremourning commented 2 months ago

Your extr conf file is broken using extremely legacy FlagsForFile method

Please see then documentation for how to correctly configure clangd.

JoeAndMark commented 2 months ago

Your extr conf file is broken using extremely legacy FlagsForFile method

Please see then documentation for how to correctly configure clangd.

It't unbelievable that I forgot this, thanks for your patience and guidance. Best regards.

JoeAndMark commented 2 months ago

That's odd. I can't repro at all and this really should not happen. If you have clang available, try compiling your file with clang.

I think I find the solution to my problem, thanks for you patience and guidance. Best regards.