Closed ricciolino closed 1 year ago
You're including standard library headers, maybe you don't have a standard library installed (in a standard place clang can find it)?
Are there any diagnostics shown? The log you posted didn't have any completion requests, was it truncated?
How can I tell clang where to search for the standard header files ?
I am sure I have installed it because I can compile and run the code.
The logs are not truncated, I don't know how to explicitly tell to coc plugin how to perform a completion request, I was thinking this could happen automatically once I start typing code similar to s.
, expecting a request to take place in that moment, or am I wrong ?
Failed to find compilation database for /home/ricciolino/Desktop/tmp/test_c++/main.cpp
clangd needs compile_commands.json
to understand your code, https://clangd.llvm.org/installation#project-setup
Here is my ~/.vim/coc-settings.json
:
{
"python.pythonPath": "python",
"python.autoComplete.addBrackets": true,
"python.formatting.provider": "autopep8",
"clangd.path": "/usr/bin/clangd",
"clangd.arguments": [
"-I/usr/include/c++/11",
"-I/usr/local/include"
]
}
Here is my compile_commands.json
:
[
{
"directory": "/home/ricciolino/Desktop/tmp/test_c++",
"file": "/home/ricciolino/Desktop/tmp/test_c++/main.cpp",
"command": "g++ -std=c++11 -o /home/ricciolino/Desktop/tmp/test_c++/main /home/ricciolino/Desktop/tmp/test_c++/main.cpp"
}
]
Now I am getting this error when open file main.cpp
:
[coc.nvim] Server clangd failed to start: Error: Pending response rejected since connection got
[coc.nvim] clangd client: couldn't create connection to server.
Here is the output of :CocOpenLog
:
2023-07-13T10:40:36.627 INFO (pid:1562968) [plugin] - coc.nvim initialized with node: v18.16.1 after [33m89[39m
2023-07-13T10:40:36.632 INFO (pid:1562968) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T10:40:36.634 INFO (pid:1562968) [language-client-index] - Language server "clangd" started with 1562981
2023-07-13T10:40:36.645 INFO (pid:1562968) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T10:40:36.645 INFO (pid:1562968) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T10:40:36.645 ERROR (pid:1562968) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T10:40:36.646 INFO (pid:1562968) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T10:40:36.648 INFO (pid:1562968) [language-client-index] - Language server "clangd" started with 1562982
2023-07-13T10:40:36.658 INFO (pid:1562968) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T10:40:36.658 ERROR (pid:1562968) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T10:40:36.658 INFO (pid:1562968) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T10:40:36.658 ERROR (pid:1562968) [services] - Server clangd failed to start: jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T10:40:36.660 INFO (pid:1562968) [language-client-index] - Language server "clangd" started with 1562983
2023-07-13T10:40:36.670 INFO (pid:1562968) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T10:40:36.670 ERROR (pid:1562968) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T10:40:36.670 INFO (pid:1562968) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T10:40:36.672 INFO (pid:1562968) [language-client-index] - Language server "clangd" started with 1562984
2023-07-13T10:40:36.682 ERROR (pid:1562968) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T10:42:48.284 INFO (pid:1562968) [attach] - receive notification: highlight []
2023-07-13T10:43:01.319 INFO (pid:1562968) [attach] - receive notification: openLog []
2023-07-13T10:43:01.623 INFO (pid:1562968) [attach] - receive notification: highlight []
Your clangd failed to start. You've set clangd.path
in coc-settings.json, what's the output of /usr/bin/clangd --version
?
> /usr/bin/clangd --version
Ubuntu clangd version 14.0.0-1ubuntu1
Features: linux+grpc
Platform: x86_64-pc-linux-gnu
I installed clangd
using apt package manager (Ubuntu 22), I also tried installing it from inside Vim editor using :CocCommand clangd.install
command, but same error persist.
Set clangd.path
to ~/.config/coc/extensions/coc-clangd-data/install/16.0.2/clangd_16.0.2/bin/clangd
and try again.
I already did it, same error occurs.
clangd.path
from your coc-settings.json~/.config/coc/extensions/coc-clangd-data
:CocCommand clangd.install
to re-install clangdJust done all three steps. Same error occur. Here is the Log:
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T11:40:24.855 INFO (pid:1602326) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T11:40:24.857 INFO (pid:1602326) [language-client-index] - Language server "clangd" started with 1602340
2023-07-13T11:40:24.859 ERROR (pid:1602326) [language-client] - Sending request failed.
2023-07-13T11:40:24.859 INFO (pid:1602326) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T11:40:24.859 ERROR (pid:1602326) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T11:40:24.859 INFO (pid:1602326) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T11:40:24.859 ERROR (pid:1602326) [services] - Server clangd failed to start: jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T11:40:24.861 INFO (pid:1602326) [language-client-index] - Language server "clangd" started with 1602341
2023-07-13T11:40:24.862 INFO (pid:1602326) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T11:40:24.862 ERROR (pid:1602326) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T11:40:24.862 INFO (pid:1602326) [services] - LanguageClient clangd state change: starting => stopped
2023-07-13T11:40:24.864 INFO (pid:1602326) [language-client-index] - Language server "clangd" started with 1602342
2023-07-13T11:40:24.865 ERROR (pid:1602326) [language-client-client] - Server clangd initialization failed. jh [Error]: Pending response rejected since connection got disposed
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:51:4592)
at Object.dispose (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:241:6209)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15575)
at Nd.handleConnectionClosed (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:248:3561)
at t (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:244:15224)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230)
at Qe (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:25:6504)
at yT.invoke (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:14460)
at lc.fire (/home/ricciolino/.vim/plugged/coc.nvim/build/index.js:24:15230) {
code: [33m-32097[39m,
data: [90mundefined[39m
}
2023-07-13T11:40:29.796 INFO (pid:1602326) [attach] - receive notification: highlight []
2023-07-13T11:40:35.281 INFO (pid:1602326) [attach] - receive notification: openLog []
From your first logs, https://github.com/clangd/coc-clangd/issues/603#issue-1801101819, clangd runs as expected, but now clangd failed to start.
~/.config/coc/extensions/coc-clangd-data/install/16.0.2/clangd_16.0.2/bin/clangd --version
ok?
Make sure you're using the correct clangd.
" ~/.config/coc/extensions/coc-clangd-data/install/16.0.2/clangd_16.0.2/bin/clangd --version
ok? "
Yes it's ok:
> ~/.config/coc/extensions/coc-clangd-data/install/16.0.2/clangd_16.0.2/bin/clangd --version
clangd version 16.0.2 (https://github.com/llvm/llvm-project 18ddebe1a1a9bde349441631365f0472e9693520)
Features: linux+grpc
Platform: x86_64-unknown-linux-gnu
Yeah from my first comment clangd was ok because I didn't have these lines added to coc-settings.json
file:
"clangd.arguments": [
"-I/usr/include/c++/11",
"-I/usr/local/include"
]
Removing those lines, I have a clean Log when open a cpp file:
2023-07-13T11:56:57.632 INFO (pid:1614357) [plugin] - coc.nvim initialized with node: v18.16.1 after [33m88[39m
2023-07-13T11:56:57.637 INFO (pid:1614357) [services] - LanguageClient clangd state change: stopped => starting
2023-07-13T11:56:57.639 INFO (pid:1614357) [language-client-index] - Language server "clangd" started with 1614370
2023-07-13T11:56:57.643 INFO (pid:1614357) [services] - LanguageClient clangd state change: starting => running
2023-07-13T11:56:57.646 INFO (pid:1614357) [services] - service clangd started
2023-07-13T11:56:59.958 INFO (pid:1614357) [attach] - receive notification: openLog []
But still see errors of this kind:
• 'iostream' file not found (clang pp_file_not_found)
• Use of undeclared identifier 'std' (clang undeclared_var_use)
clangd.arguments
is args passed to clangd, something like --background-index
, check clangd --help
. You can't pass includes to this.
Remove the clangd.arguments
configurations, and setup compile_commands.json
for your project.
Close for now because isn't coc-clangd's issue.
I configured now compile_commands.json like this:
"command": "g++ -std=c++11 -I/usr/local/include -I/usr/include/c++/11 -o /home/ricciolino/Desktop/tmp/test_c++/main /home/ricciolino/Desktop/tmp/test_c++/main.cpp"
And coc-settings.json like this:
"clangd.path": "~/.config/coc/extensions/coc-clangd-data/install/16.0.2/clangd_16.0.2/bin/clangd",
"clangd.arguments": [
"--background-index",
"--completion-style=detailed",
"--header-insertion=iwyu",
"--suggest-missing-includes"
]
Still no lucky, it doesn not work.
How do you generate compile_commands.json
? You can use bear
to generate it. https://clangd.llvm.org/installation#project-setup
Now I tried to generate using bear:
bear -- g++ -std=c++11 -I/usr/local/include -I/usr/include/c++/11 -o /home/ricciolino/Desktop/tmp/test_c++/main /home/ricciolino/Desktop/tmp/test_c++/main.cpp
And the generated compile_command.json is this one:
> cat compile_commands.json
[
{
"arguments": [
"/usr/bin/g++",
"-c",
"-std=c++11",
"-I/usr/local/include",
"-I/usr/include/c++/11",
"-o",
"/home/ricciolino/Desktop/tmp/test_c++/main",
"/home/ricciolino/Desktop/tmp/test_c++/main.cpp"
],
"directory": "/home/ricciolino/Desktop/tmp/test_c++",
"file": "/home/ricciolino/Desktop/tmp/test_c++/main.cpp",
"output": "/home/ricciolino/Desktop/tmp/test_c++/main"
}
]
But opening main.cpp
still error messages appear.
@sam-mccall can you take a look?
Hey guys!
I think I solved !!!!
I just realized that I was missing this "include" path:
/usr/include/x86_64-linux-gnu/c++/11
So I re-run bear for generating the compile_commands.json file like this:
bear -- g++ -std=c++11 -I/usr/local/include -I/usr/include/c++/11 -I/usr/include/x86_64-linux-gnu/c++/11 -o /home/ricciolino/Desktop/tmp/test_c++/main /home/ricciolino/Desktop/tmp/test_c++/main.cpp
And now the autocomplete suggestions work as expected (I think :) ):
Logs
:CocCommand workspace.showOutput
System information
clangd --version
:CocList extensions
Operating system: Ubuntu 22
I am trying to test the intellisense feature using this C++ snippet:
I expected that after typing
s.
on line number 7, the clangd coc.nvim extension gave me a rich list of possible methods from the std::string class. Actually I am not getting any suggestion. Why this?