clangd / coc-clangd

clangd extension for coc.nvim
Apache License 2.0
757 stars 34 forks source link

coc reference not working with clangd, clangd log shows error: Task was cancelled. #686

Closed shimbay closed 1 month ago

shimbay commented 1 month ago

coc reference not working after coc / coc plugins upgrade

coc-setting

{                                                                           
  "semanticTokens.enable": true,                                            
  "semanticTokens.filetypes": ["*"],                                        
  "clangd.enabled": true,                                                   
  "clangd.arguments": ["--query-driver=/usr/bin/g++", "--background-index"],
  "inlayHint.display": false,                                               
  "diagnostic.checkCurrentLine": true,                                      
  "list.height": 15,                                                        
  "list.maxPreviewHeight": 20,                                              
  "list.previewToplineStyle": "middle",                                     
  "list.previewHighlightGroup": "CursorLine",                               
  "list.source.diagnostics.pathFormat": "short",                            
  "list.source.files.command": "git",                                       
  "list.source.files.args": ["ls-files", "--recurse-submodules"],           
  "list.source.grep.command": "rg",                                         
  "list.source.grep.args": ["-i"],                                          
  "list.source.grep.useLiteral": false,                                     
  "python.pythonPath": "python3",                                           
  "pyright.organizeimports.provider": "isort",                              
  "pyright.inlayHints.functionReturnTypes": false,                          
  "pyright.inlayHints.variableTypes": false,                                
  "snippets.userSnippetsDirectory": "$HOME/.config/snippet",                
  "suggest.maxCompleteItemCount": 15,                                       
  "suggest.preferCompleteThanJumpPlaceholder": true,                        
  "suggest.enablePreselect": false,                                         
  "snippets.ultisnips.pythonPrompt": false                                  
}                                                                           

Logs Please attach the clangd log from :CocCommand workspace.showOutput if you can. If possible, run with --log=verbose - note that the logs will include the contents of open files!

I[10:50:52.130] clangd version 18.1.3 (https://github.com/llvm/llvm-project c13b7485b87909fcf739f62cfa382b55407433c0)                                                                                       
I[10:50:52.130] Features: linux+grpc                                                                                                                                                                        
I[10:50:52.130] PID: 158327                                                                                                                                                                                 
I[10:50:52.130] Working directory: /home/sunyunbo/workspace/src/xxx                                                                                                                                
I[10:50:52.130] argv[0]: ../../../../../home/sunyunbo/.config/coc/extensions/coc-clangd-data/install/18.1.3/clangd_18.1.3/bin/clangd                                                                        
I[10:50:52.130] argv[1]: --query-driver=/usr/bin/g++                                                                                                                                                        
I[10:50:52.130] argv[2]: --background-index                                                                                                                                                                 
I[10:50:52.130] argv[3]: --log=verbose                                                                                                                                                                      
V[10:50:52.130] User config file is /home/sunyunbo/.config/clangd/config.yaml                                                                                                                               
I[10:50:52.131] Starting LSP over stdin/stdout                                                                                                                                                              
V[10:50:52.131] <<< {"id":0,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"markdown":{"parser":"marked","version":"7.0.5"},"positionEncodings":["utf-16"],"regularExpressions":

I[10:50:52.131] <-- initialize(0)                                                                                                                                                                           
I[10:50:52.134] --> reply:initialize(0) 2 ms                                                                                                                                                                
V[10:50:52.134] >>> {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"astProvider":true,"callHierarchyProvider":true,"clangdInlayHintsProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","r

V[10:50:52.137] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}                                                                                                                                    

I[10:50:52.137] <-- initialized                                                                                                                                                                             
V[10:50:52.142] <<< {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"#pragma once\n\n#include <dirent.h>\n#include <stdio.h>\n#include <stdlib.h>\n\n#i

I[10:50:52.142] <-- textDocument/didOpen                                                                                                                                                                    
V[10:50:52.143] System include extraction: driver clang expanded to /home/sunyunbo/workspace/bin/llvm/bin/clang                                                                                             
V[10:50:52.143] System include extraction: not allowed driver /home/sunyunbo/workspace/bin/llvm/bin/clang                                                                                                   
V[10:50:52.143] config note at /home/sunyunbo/.config/clangd/config.yaml:1:0: Parsing config fragment                                                                                                       
V[10:50:52.143] config note at /home/sunyunbo/.config/clangd/config.yaml:1:0: Parsed 1 fragments from file                                                                                                  
V[10:50:52.143] Config fragment: compiling /home/sunyunbo/.config/clangd/config.yaml:1 -> 0x00007F0394001CD0 (trusted=true)                                                                                 
I[10:50:52.143] --> textDocument/publishDiagnostics                                                                                                                                                         
V[10:50:52.143] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///home/sunyunbo/.config/clangd/config.yaml"}}                                       

I[10:50:52.147] Loaded compilation database from /data/sunyunbo/workspace/src/xxx/compile_commands.json                                                                                            
V[10:50:52.147] Broadcasting compilation database from /data/sunyunbo/workspace/src/xxx                                                                                                            
V[10:50:52.147] System include extraction: not allowed driver /data/sunyunbo/toolchain/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++                                     
I[10:50:52.147] ASTWorker building file /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h version 1 with command inferred from /home/sunyunbo/workspace/src/xxx/sdk
[/data/shared/sunyunbo/yyy/sdk/yyy/test]                                                                                                                                                            
/data/sunyunbo/toolchain/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++ --target=aarch64-none-linux-gnu --driver-mode=g++ -DCOMPILER_ENV_TYPE=1 -DCOMPILER_SOC_TYPE=1 -DEN
V[10:50:52.148] Driver produced command: cc1 -cc1 -triple aarch64-none-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name yyy_h
I[10:50:52.148] --> textDocument/clangd.fileStatus                                                                                                                                                          
V[10:50:52.149] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, running Update","uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/

V[10:50:52.149] Building first preamble for /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h version 1                                                                     
I[10:50:52.149] Loaded compilation database from /home/sunyunbo/workspace/src/xxx/compile_commands.json                                                                                            
V[10:50:52.342] <<< {"id":1,"jsonrpc":"2.0","method":"textDocument/documentLink","params":{"textDocument":{"uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h"}

I[10:50:52.342] <-- textDocument/documentLink(1)                                                                                                                                                            
V[10:50:52.545] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fexcept_t' in the global namespace                
V[10:50:52.549] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'feclearexcept' in the global namespace            
V[10:50:52.554] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fegetexceptflag' in the global namespace          
V[10:50:52.559] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'feraiseexcept' in the global namespace            
V[10:50:52.563] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fesetexceptflag' in the global namespace          
V[10:50:52.566] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fetestexcept' in the global namespace             
V[10:50:52.570] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fegetround' in the global namespace               
V[10:50:52.573] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fesetround' in the global namespace
V[10:50:52.577] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fegetenv' in the global namespace; did you mean 'g
V[10:50:52.580] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'feholdexcept' in the global namespace             
V[10:50:52.583] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'fesetenv' in the global namespace                 
V[10:50:52.588] Dropped diagnostic: /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h: in included file: no member named 'feupdateenv' in the global namespace              
V[10:50:52.744] <<< {"id":2,"jsonrpc":"2.0","method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_han

I[10:50:52.744] <-- textDocument/semanticTokens/full(2)                                                                                                                                                     
V[10:50:53.248] Dropped diagnostic: /home/sunyunbo/workspace/src/xxx/sdk/common/common/tnum.hpp: 'static_assert' with no message is a C++17 extension                                              
I[10:50:53.251] Built preamble of size 15088708 for file /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h version 1 in 1.10 seconds                                        
I[10:50:53.252] --> workspace/semanticTokens/refresh(0)                                                                                                                                                     
V[10:50:53.252] >>> {"id":0,"jsonrpc":"2.0","method":"workspace/semanticTokens/refresh","params":null}                                                                                                      

I[10:50:53.252] Indexing c++14 standard library in the context of /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h                                                         
V[10:50:53.256] <<< {"id":0,"jsonrpc":"2.0","result":null}                                                                                                                                                  

I[10:50:53.256] <-- reply(0)                                                                                                                                                                                
V[10:50:53.357] <<< {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":2}}                                                                                                                          

I[10:50:53.357] <-- $/cancelRequest                                                                                                                                                                         
V[10:50:53.357] <<< {"id":3,"jsonrpc":"2.0","method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_han

I[10:50:53.357] <-- textDocument/semanticTokens/full(3)                                                                                                                                                     
V[10:50:53.424] indexed file AST for /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h version 1:                                                                           
  symbol slab: 45 symbols, 14656 bytes                                                                                                                                                                      
  ref slab: 160 symbols, 544 refs, 26752 bytes                                                                                                                                                              
  relations slab: 0 relations, 24 bytes                                                                                                                                                                     
V[10:50:53.425] Build dynamic index for main-file symbols with estimated memory usage of 76424 bytes                                                                                                        
I[10:50:53.425] --> textDocument/publishDiagnostics                                                                                                                                                         
V[10:50:53.425] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"no_member_suggest","message":"In included file: no member named 'fenv_t' in the global nam

V[10:50:53.426] ASTWorker running DocumentLinks on version 1 of /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h                                                           
I[10:50:53.426] --> reply:textDocument/documentLink(1) 1083 ms                                                                                                                                              
V[10:50:53.426] >>> {"id":1,"jsonrpc":"2.0","result":[{"range":{"end":{"character":19,"line":2},"start":{"character":9,"line":2}},"target":"file:///usr/include/dirent.h"},{"range":{"end":{"character":18,"

I[10:50:53.426] --> reply:textDocument/semanticTokens/full(2) 682 ms, error: Task was cancelled.                                                                                                            
V[10:50:53.426] >>> {"error":{"code":-32800,"message":"Request cancelled"},"id":2,"jsonrpc":"2.0"}                                                                                                          

V[10:50:53.426] ASTWorker running SemanticHighlights on version 1 of /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h                                                      
I[10:50:53.427] --> reply:textDocument/semanticTokens/full(3) 70 ms                                                                                                                                         
V[10:50:53.428] >>> {"id":3,"jsonrpc":"2.0","result":{"data":[35,16,3,15,131584,2,10,7,15,131073,2,12,16,3,131075,0,23,6,8,131072,0,8,1,2,16403,0,3,21,8,66048,0,23,6,2,16387,1,4,6,2,16384,0,7,7,6,33280,0,

I[10:50:53.428] --> textDocument/clangd.fileStatus                                                                                                                                                          
V[10:50:53.428] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h"}}  

[Error - 10:50:53.436] Sending request textDocument/semanticTokens/full failed.                                                                                                                             
  Message: Request cancelled                                                                                                                                                                                
  Code: -32800                                                                                                                                                                                              
V[10:50:53.500] indexed preamble AST for /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h version 1:                                                                       
  symbol slab: 20900 symbols, 6118680 bytes                                                                                                                                                                 
  ref slab: 0 symbols, 0 refs, 128 bytes                                                                                                                                                                    
  relations slab: 887 relations, 17432 bytes                                                                                                                                                                
V[10:50:53.551] Build dynamic index for header symbols with estimated memory usage of 11396856 bytes                                                                                                        
V[10:50:53.703] Ignored diagnostic. /usr/include/c++/9/memory:121:25:cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
V[10:50:53.934] Ignored diagnostic. /usr/lib/gcc/x86_64-linux-gnu/9/include/stdatomic.h:40:17:unknown type name '_Bool'                       
V[10:50:53.936] Ignored diagnostic. /usr/lib/gcc/x86_64-linux-gnu/9/include/stdatomic.h:221:3:unknown type name '_Bool'                       
V[10:50:53.938] Ignored diagnostic. /usr/lib/gcc/x86_64-linux-gnu/9/include/stdatomic.h:230:8:unknown type name '_Bool'                       
V[10:50:53.940] Ignored diagnostic. /usr/lib/gcc/x86_64-linux-gnu/9/include/stdatomic.h:233:8:unknown type name '_Bool'                       
V[10:50:53.946] Ignored diagnostic. /usr/include/c++/9/fenv.h:58:11:no member named 'fenv_t' in the global namespace; did you mean 'dev_t'?   
V[10:50:53.946] Ignored diagnostic. /usr/include/x86_64-linux-gnu/sys/types.h:59:17:'dev_t' declared here                                     
V[10:50:53.949] Ignored diagnostic. /usr/include/c++/9/fenv.h:59:11:no member named 'fexcept_t' in the global namespace                       
V[10:50:53.952] Ignored diagnostic. /usr/include/c++/9/fenv.h:62:11:no member named 'feclearexcept' in the global namespace                   
V[10:50:53.956] Ignored diagnostic. /usr/include/c++/9/fenv.h:63:11:no member named 'fegetexceptflag' in the global namespace                 
V[10:50:53.959] Ignored diagnostic. /usr/include/c++/9/fenv.h:64:11:no member named 'feraiseexcept' in the global namespace                   
V[10:50:53.963] Ignored diagnostic. /usr/include/c++/9/fenv.h:65:11:no member named 'fesetexceptflag' in the global namespace                 
V[10:50:53.966] Ignored diagnostic. /usr/include/c++/9/fenv.h:66:11:no member named 'fetestexcept' in the global namespace                    
V[10:50:53.969] Ignored diagnostic. /usr/include/c++/9/fenv.h:68:11:no member named 'fegetround' in the global namespace                      
V[10:50:53.972] Ignored diagnostic. /usr/include/c++/9/fenv.h:69:11:no member named 'fesetround' in the global namespace                      
V[10:50:53.974] Ignored diagnostic. /usr/include/c++/9/fenv.h:71:11:no member named 'fegetenv' in the global namespace; did you mean 'getenv'?
V[10:50:53.974] Ignored diagnostic. /usr/include/stdlib.h:641:14:'getenv' declared here                                                       
V[10:50:53.977] Ignored diagnostic. /usr/include/c++/9/fenv.h:72:11:no member named 'feholdexcept' in the global namespace                    
V[10:50:53.980] Ignored diagnostic. /usr/include/c++/9/fenv.h:73:11:no member named 'fesetenv' in the global namespace                        
V[10:50:53.982] Ignored diagnostic. /usr/include/c++/9/fenv.h:74:11:no member named 'feupdateenv' in the global namespace                     
V[10:50:53.985] Ignored diagnostic. /usr/include/c++/9/cfenv:61:11:no member named 'fenv_t' in the global namespace; did you mean 'dev_t'?    
V[10:50:53.985] Ignored diagnostic. /usr/include/x86_64-linux-gnu/sys/types.h:59:17:'dev_t' declared here                                     
V[10:50:53.987] Ignored diagnostic. too many errors emitted, stopping now                                                                     
I[10:50:54.254] Indexed c++14 standard library (incomplete due to errors): 11920 symbols, 1797 filtered                                       
V[10:50:54.302] Build dynamic index for header symbols with estimated memory usage of 14028436 bytes

System information Clangd version (from the log, or clangd --version): clangd extension version (from :CocInfo):

## versions                                                

vim version: NVIM v0.10.0                                  
node version: v19.9.0                                      
coc.nvim version: 0.0.82-56632971 2024-07-04 19:25:14 +0800
coc.nvim directory: /home/sunyunbo/.vim/bundle/coc.nvim    
term: tmux                                                 
platform: linux                                            

Operating system:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy
fannheyward commented 1 month ago

Can't reproduced.

textDocument/semanticTokens/full(2) 682 ms, error: Task was cancelled

This's semantic highlighting request, has nothing related with reference.

Run :call CocAction('jumpReferences') on the symbol you want to jump, trace the logs.

shimbay commented 1 month ago
I[11:07:14.057] <-- textDocument/references(9)                                                                                                                                                              
V[11:07:14.057] ASTWorker running References on version 1 of /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h                                                              
I[11:07:14.058] --> reply:textDocument/references(9) 1 ms                                                                                                                                                   
V[11:07:14.058] >>> {"id":9,"jsonrpc":"2.0","result":[{"range":{"end":{"character":24,"line":51},"start":{"character":19,"line":51}},"uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src

I[11:07:14.058] --> textDocument/clangd.fileStatus                                                                                                                                                          
V[11:07:14.058] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h"}}  

V[11:07:14.399] <<< {"id":10,"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"position":{"character":19,"line":51},"textDocument":{"uri":"file:///data/sunyunbo/workspace/src/npu-codeba

I[11:07:14.399] <-- textDocument/documentHighlight(10)                                                                                                                                                      
V[11:07:14.399] ASTWorker running Highlights on version 1 of /data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h                                                              
I[11:07:14.400] --> reply:textDocument/documentHighlight(10) 0 ms                                                                                                                                           
V[11:07:14.400] >>> {"id":10,"jsonrpc":"2.0","result":[{"kind":1,"range":{"end":{"character":24,"line":51},"start":{"character":19,"line":51}}}]}                                                           

I[11:07:14.400] --> textDocument/clangd.fileStatus                                                                                                                                                          
V[11:07:14.400] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///data/sunyunbo/workspace/src/xxx/sdk/yyy/src/handle/yyy_handle.h"}}  
shimbay commented 1 month ago

reference in the same file is ok, but if reference in other files, coc-reference does not work. i have checked compile_commands.json, it seems nothing wrong.

shimbay commented 1 month ago

it seems other file does not loaded by clangd

fannheyward commented 1 month ago

reference in other files, coc-reference does not work

Have no idea about this, maybe clangd related. coc.nvim/coc-clangd sends references request to clangd server, the server responded with locations and the client side displays them.

shimbay commented 1 month ago

@fannheyward I am pretty sure the reference works correctly with llm 14.0.0 and a old version coc before upgrading.

Now, I downgrade the llvm back to 14.0.0, and use with the latest coc, reference is still not working.

I also found some weird behavior, the background indexing is not work if i donot specify the --compile-commands-dir similar disscussion here

shimbay commented 1 month ago

it`s solved, https://github.com/clangd/clangd/issues/503, my home dir is a symbol link, clangd has a bug to process it correctly.