Closed pidgeon777 closed 3 years ago
Did you try :CclsCallHierarchy
, my guess is this isn't implemented with a standard request for CCLS.
Yes I tried it, this is what I obtain:
vim-ccls: nvim-lspconfig error: no result from ccls
My mappings:
vim.cmd("nnoremap <silent> g1 <cmd>lua vim.lsp.buf.incoming_calls()<CR>")
vim.cmd("nnoremap <silent> g2 <cmd>lua vim.lsp.buf.outgoing_calls()<CR>")
Also those two commands above report errors, no matter of vim-ccls plugin:
method textDocument/prepareCallHierarchy is not supported by any of the servers registered for the current buffer
There is one thing I don't understand though, someone here seems to have a similar issue about ccls and call hierarchies:
https://github.com/neovim/neovim/issues/14441
This seems to be fixed, thus it should prove that current Neovim LSP and ccls should be able to provide call hierarchy.
I'm really trying to understand if there is an issue in my config because I'm quite sure that other users are currently able to use ccls in Neovim, with vim-ccls plugin also.
@pidgeon777 Hi, thanks for reporting this issue and for all the details.
Short explanation: I think vim.lsp.buf.incoming_calls()
is unrelated to this. ccls
has a non-standard method ($ccls/call
) to provide call hierarchies. This because the standard callHierarchy
methods are a recent addition to the LSP, while ccls had already support for this a few years before it was added to the official protocol specification.
I am a bit out of touch with the development of both ccls and neovim's built-in LSP client (I see there has been a lot of improvements lately), so I need to check if there has been any change in the API.
You should give Neovim's built-in LSP client a try, it is very good indeed.
Also, this is worth a look:
https://github.com/neovim/nvim-lspconfig
Well, I'll wait for your updates, then!
Hi!
I read the details of this issue and I see some confusion, so I should start by clarifying the scope of this project (vim-ccls
).
The following functions
lua vim.lsp.buf.incoming_calls()
lua vim.lsp.buf.outgoing_calls()
that you mention above:
callHierarchy
methods to communicate with the server,vim-ccls
(i.e. the particular vim plugin implemented in this repository).The commands exposed by vim-ccls
are listed in the README.md an in the documentation. If you want to show a call hierarchy with vim-ccls
, you should use the CclsCallHierarchy
command (and similar, you can refer to the README and the documentation for details and examples of usage).
As far as I know, ccls
does not support the callHierarchy LSP methods and it uses its custom API instead (which predates standard LSP call hierarchy support), so you cannot use
lua vim.lsp.buf.incoming_calls()
lua vim.lsp.buf.outgoing_calls()
with ccls
(and concerning that issue, requests for support belong to the ccls project itself, not here).
The purpose of vim-ccls
is to provide a vim/neovim interface to the non-standard API of ccls
, so if you want to get a call hierarchy using vim-ccls
you should not use the Lua bindings from Neovim (vim.lsp.buf.incoming_calls()
etc.) but rather :CclsCallHierarchy
.
That said, I can help with troubleshooting :CclsCallHierarchy
. I had a look at the log you posted and it seems there is a problem with handling of Windows paths (Windows support was outdated and pretty much untested). I opened a PR that should address the issue, it would be great if you could test it and see if it works for you.
You should give Neovim's built-in LSP client a try, it is very good indeed.
Also, this is worth a look:
This plugin already supports Neovim's built-in LSP client and nvim-lspconfig
as LSP client backend. I am already familiar with both, obviously (I implemented support for them in vim-ccls
...), but I don't use them on a daily basis.
First of all, thanks for the great description. That explains a lot.
I did this:
C:\>cd C:\Users\myUsername\AppData\Local\nvim-data\site\pack\packer\opt\vim-ccls
C:\Users\myUsername\AppData\Local\nvim-data\site\pack\packer\opt\vim-ccls>gh pr checkout 49
Switched to a new branch 'refactor-windows-path-handling'
When I execute :CclsCallHierarchy
placing the cursor at the create_remap_table
function, now it seems to correctly open the panel:
but when I press Enter
on the main
element, a new tab is wrongly created:
It is as if when opening the code location, the proper Windows slashes are not kept into account.
PWD where of the main.cpp
file where I executed the command, is of the form C:\Work\Projects\Git\<EditA>\<EditB>
.
Ok, thanks for the feedback! Now it seems that path -> URI conversion is working, but the other way around is still broken. I probably need to try this out on an actual Windows machine. It would also help if you could record a ccls log (I would like to see how the URIs from ccls look like before conversion).
Also, could you please check what values you get from these commands in Neovim on your platform?
:echo has('win32')
:echo has('win64')
:echo has('win32unix')
There is another issue now. For an unknown reason, your plugin doesn't seem to identify the ccls client attached to the buffer:
Configured servers: vuels, dartls, dockerls, ccls, ahk_lsp, vhdl_ls, kotlin_language_server, ghdl_ls, intelephense, sumneko_lua, emmet_ls, rust_analyzer, vhdl_tool, elmls, elixirls, angularls, cssls, efm, yamlls, terraformls, vimls, solargraph, svelte, tsserver, texlab, pyright, gopls, html, graphql, hdl_checker, bashls, jsonls
Neovim logs at: C:\Users\UserName\AppData\Local\Temp\nvim/lsp.log
1 client(s) attached to this buffer: ccls
Client: ccls (id 2)
root: C:\Work\Projects\Git\ACounter\testlut
filetypes: c, cpp, objc, objcpp
cmd: ccls --log-file=ccls.log -v=1
1 active client(s):
Client: ccls (id 2)
root: C:\Work\Projects\Git\ACounter\testlut
filetypes: c, cpp, objc, objcpp
cmd: ccls --log-file=ccls.log -v=1
Clients that match the filetype cpp:
Config: ccls
cmd: ccls --log-file=ccls.log -v=1
cmd is executable: True
identified root: C:\Work\Projects\Git\ACounter\testlut
custom handlers:
When executing commands such as CclsCallHierarchy
, your plugin reports:
vim-ccls: nvim-lspconfig error: ccls unavailable for buffer 14
ccls.log:
10:42:44 D:\CodeBlocks\ccls\src\messages\initialize.cc:274 I initialize in directory C:/Work/Projects/Git/ACounter/testlut with uri file:///C:/Work/Projects/Git/ACounter/testlut
10:42:44 D:\CodeBlocks\ccls\src\messages\initialize.cc:297 I initializationOptions: {"compilationDatabaseCommand":"","compilationDatabaseDirectory":"","cache":{"directory":".ccls-cache","format":"binary","hierarchicalPath":false,"retainInMemory":2},"capabilities":{"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},"foldingRangeProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}},"clang":{"excludeArgs":[],"extraArgs":[],"pathMappings":[],"resourceDir":""},"client":{"diagnosticsRelatedInformation":true,"hierarchicalDocumentSymbolSupport":true,"linkSupport":true,"snippetSupport":true},"codeLens":{"localVariables":true},"completion":{"caseSensitivity":2,"detailedLabel":true,"dropOldRequests":true,"duplicateOptional":true,"filterAndSort":false,"include":{"blacklist":[],"maxPathSize":30,"suffixWhitelist":[".h",".hpp",".hh",".inc"],"whitelist":[]},"maxNum":100,"placeholder":true},"diagnostics":{"blacklist":[],"onChange":1000,"onOpen":0,"onSave":0,"spellChecking":true,"whitelist":[]},"highlight":{"largeFileSize":2097152,"lsRanges":false,"blacklist":[],"whitelist":[]},"index":{"blacklist":[],"comments":0,"initialNoLinkage":false,"initialBlacklist":[],"initialWhitelist":[],"maxInitializerLines":5,"multiVersion":0,"multiVersionBlacklist":[],"multiVersionWhitelist":[],"name":{"suppressUnwrittenScope":false},"onChange":false,"parametersInDeclarations":true,"threads":0,"trackDependency":2,"whitelist":[]},"request":{"timeout":5000},"session":{"maxNum":10},"workspaceSymbol":{"caseSensitivity":1,"maxNum":1000,"sort":true},"xref":{"maxNum":2000}}
10:42:44 D:\CodeBlocks\ccls\src\messages\initialize.cc:329 I use -resource-dir=D:\CodeBlocks\llvm-11.0.1-install\lib\clang\11.0.1
10:42:44 D:\CodeBlocks\ccls\src\messages\initialize.cc:361 I workspace folder: C:/Work/Projects/Git/ACounter/testlut/
10:42:44 D:\CodeBlocks\ccls\src\project.cc:426 I loaded C:/Work/Projects/Git/ACounter/testlut/compile_commands.json
10:42:44 D:\CodeBlocks\ccls\src\messages\initialize.cc:386 I start 8 indexers
10:42:44 D:\CodeBlocks\ccls\src\messages\initialize.cc:394 I dispatch initial index requests
10:42:44 D:\CodeBlocks\ccls\src\pipeline.cc:493 I loaded project. Refresh semantic highlight for all working file.
10:42:44 D:\CodeBlocks\ccls\src\sema_manager.cc:763 I create session for C:/Work/Projects/Git/ACounter/testlut/main.cpp
C:/msys64/mingw64/bin/c++.exe --driver-mode=g++ -std=gnu++17 -Weverything -o CMakeFiles/testlut.dir/main.cpp.obj -c C:/Work/Projects/Git/ACounter/testlut/main.cpp -working-directory=C:/Work/Projects/Git/ACounter/testlut/Build_Unix
10:42:44 D:\CodeBlocks\ccls\src\pipeline.cc:298 I load cache for C:/Work/Projects/Git/ACounter/testlut/main.cpp
my_log_file_vim_ccls.txt:
16/06/2021 10:53:43 | ["Outgoing", {"method": "$ccls/call", "handler": "<SNR>133_handle_tree", "params": {"levels": 1, "callee": false, "hierarchy": true, "textDocument": {"uri": "file://C:/Work/Projects/Git/ACounter/testlut/main.cpp"}, "position": {"character": 5, "line": 668}}}]
16/06/2021 10:53:44 | ["Outgoing", {"method": "$ccls/call", "handler": "<SNR>133_handle_locations", "params": {"callee": false, "hierarchy": false, "textDocument": {"uri": "file://C:/Work/Projects/Git/ACounter/testlut/main.cpp"}, "position": {"character": 5, "line": 668}}}]
16/06/2021 10:53:45 | ["Outgoing", {"method": "$ccls/call", "handler": "<SNR>133_handle_tree", "params": {"levels": 1, "callee": true, "hierarchy": true, "textDocument": {"uri": "file://C:/Work/Projects/Git/ACounter/testlut/main.cpp"}, "position": {"character": 5, "line": 668}}}]
16/06/2021 10:53:46 | ["Outgoing", {"method": "$ccls/call", "handler": "<SNR>133_handle_locations", "params": {"callee": true, "hierarchy": false, "textDocument": {"uri": "file://C:/Work/Projects/Git/ACounter/testlut/main.cpp"}, "position": {"character": 5, "line": 668}}}]
Also:
:echo has('win32')
1
:echo has('win64')
1
:echo has('win32unix')
0
@pidgeon777 Thanks for the additional info. I managed to find some time to set up neovim and build ccls on a Windows machine to reproduce this.
but when I press Enter on the main element, a new tab is wrongly created:
I found the cause of this issue and pushed a new commit to the PR branch to fix it, feel free to try it out and see if it works for you.
There is another issue now. For an unknown reason, your plugin doesn't seem to identify the ccls client attached to the buffer
I have not been able to reproduce this. Are you standing in the right buffer at the moment you call :CclsCallHierarchy
? The command tries to fetch a hierarchy for the symbol under the cursor in the current buffer, so you will get an error if the currently active buffer is not the source file (e.g. if you call the command while standing in the call hierarchy view or in some other buffer).
If this other issue happens again, could you please:
Double-check the buffer number of the source file. So for instance, if you are trying to call :CclsCallHierarchy
for a symbol in foo.cpp
, you could execute :echo bufnr('foo.cpp')
to print the buffer number of the buffer holding foo.cpp
, and check if it matches the number in the error message.
You can also run :ls
to see a list of open buffers, where the leftmost number in each row is the buffer number, so you can see what buffer the number in the error message corresponds to, and execute :bx
(where x
is the buffer number) to switch to that buffer.
:lua print(vim.inspect(vim.lsp.buf_get_clients(x)))
after replacing x
with the buffer number shown in the error message, so for instance if you get an error
vim-ccls: nvim-lspconfig error: ccls unavailable for buffer 14
you should call
:lua print(vim.inspect(vim.lsp.buf_get_clients(14)))
This command prints a dump of the language server objects for a given buffer number.
So far, after testing your PR, everything seems to work. Congratulations!
The buffer not attached error was mainly due to two things:
compile_commands.json
file.I'll test your plugin more in-depth and let you know about the outcome.
Great! Then I will merge the PR and close this issue. Of course feel free to open a new issue in case you encounter any problem (there are relatively few Windows users, so feedback is highly valuable).
In my Neovim 0.5.0 setup configured with ccls as LSP for C, the following seem to work:
e.g.:
and most of the remaining ccls capabilities.
But those mappings/commands:
doesn't seem to work. Neovim reports:
Anyway, vim-ccls reports for all of its commands:
when executing them (with or without a word under the cursor).
Neovim version:
LspInfo output:
compile_commands.json:
LSP Config .lua setting:
ccls_log_file_content:
ccls log file:
Neovim LSP log file: