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

Autocomplete with cquery not working #228

Closed
Alexmac22347 opened this issue Dec 31, 2018 · 19 comments
Closed

Autocomplete with cquery not working #228

Alexmac22347 opened this issue Dec 31, 2018 · 19 comments

Comments

@Alexmac22347
Copy link

Alexmac22347 commented Dec 31, 2018

Hi, I have a simple cmake/c++ project to isolate the issue. Basically, I #include <iostream>, but vim-lsp cannot seem to find std::cout. However I can still go to the definition of std::cout using LspDefinition after typing out std::cout myself.

Here's main.cpp (~/Documents/test/main.cpp)

#include <iostream>
int main() {
    std::cout << "hi";
}

compile_commands.json (~/Documents/test/build/compile_commands.json and symlink ~/Documents/test/compile_commands.json)

[
{
  "directory": "/home/alex/Documents/test/build",
  "command": "/usr/bin/c++      -o CMakeFiles/test.dir/main.cpp.o -c /home/alex/Documents/test/main.cpp",
  "file": "/home/alex/Documents/test/main.cpp"
}
]

I've attached the log
The completion request from vim-lsp looks ok, but then the server replies with isInComplete=True.
However, I do not think this is a cquery problem, since I tried the same thing in emacs using the emacs-cquery plugin, and was able to autocomplete std::cout.

Also, this problem happens with local includes as well. I tried adding file ~/Documents/test/foo.h:

int foo();

and modify ~/Documents/test/main.cpp:

#include "foo.h"
int main() {
    int a = foo();
}

Again, like the std::cout example, lsp#complete cannot find the function foo. However, after I type in foo();, I can use LspDefinition just fine.

Thank you

@mattn
Copy link
Collaborator

mattn commented Jan 29, 2019

As far as I can see your log, vim-lsp does not send current edting text to cquery. Could you pleae try again with following step?

  1. start vim
  2. let g:lsp_log_verbose=1
  3. let g:lsp_log_file='/tmp/lsp.log'
  4. open the file
  5. do code completion

@Alexmac22347
Copy link
Author

Hi there, I just did it. I was trying to autocomple std::cou -> std::cout, but got no autocompletion results. Ive attached the log
lsp.log

@Alexmac22347
Copy link
Author

Alexmac22347 commented Jan 30, 2019

Weird, sometimes it works. Ive attached from when it worked, and autocompleted std::cout
Most of the time though it doesnt work

EDIT actually I dont have the log file for when it was working

@mattn
Copy link
Collaborator

mattn commented Jan 30, 2019

Hmm, I could not figure out why cquery does not return candidate of completion from std::.

The first log file (#228 (comment))

initialize

2019年01月30日 18時59分33秒:["--->",1,"cquery",{"method":"initialize","params":{"rootUri":"file:///home/alex/Documents/test","initializationOptions":{"cacheDirectory":"/tmp/cquery/cache"},"capabilities":{"workspace":{"applyEdit ":true}},"rootPath":"/home/alex/Documents/test","trace":"off"}}]

didOpen

2019年01月30日 18時59分33秒:["--->",1,"cquery",{"method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///home/alex/Documents/test/main.cpp","version":1,"languageId":"cpp","text":"#include <iostream>\n\nint main() {\n    std::\n}"}}}]

didChange

2019年01月30日 18時59分40秒:["--->",1,"cquery",{"method":"textDocument/didChange","params":{"contentChanges":[{"text":"#include <iostream>\n\nint main() {\n    std::\n}"}],"textDocument":{"uri":"file:///home/alex/Documents/test/main.cpp","version":2}}}]

document still not have cou

completion

2019年01月30日 18時59分40秒:["--->",1,"cquery",{"method":"textDocument/completion","on_notification":"---funcref---","params":{"textDocument":{"uri":"file:///home/alex/Documents/test/main.cpp"},"position":{"character":9,"line":3}}}]

didChange

2019年01月30日 18時59分42秒:["--->",1,"cquery",{"method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":9,"line":3},"start":{"character":9,"line":3}},"text":"cou","rangeLength":0}],"textDocument":{"uri":"file:///home/alex/Documents/test/main.cpp","version":3}}}]

So completion was processed with text std:: without cou. And cou was sent after completion.

@Alexmac22347
Copy link
Author

I also found a way to make it autocomplete std::cout. basically, I type in std::co, then open the autocomplete menu and select the first choice. Then I started to delete characters, and once I delete enough characters so that its just std::co showing, then I will see the suggestion for cout showing!
Ill post more information and a gif when I get home

@mattn
Copy link
Collaborator

mattn commented Jan 31, 2019

Thank your report. BTW, I tried to install cquery on Ubuntu 18.04 but cquery crash when cquery receives completion. (I always use clangd)

@Alexmac22347
Copy link
Author

Alexmac22347 commented Jan 31, 2019

Im running Ubuntu 18.04 as well, cquery seems to run OK for me (no crash). I tried clangd as well, but it also could not complete std::cout. Ive attached a gif showing me using cquery, and how I can get the std::cout completion to show up by deleting characters.
cquery

Also heres what the clangd completion looked like. I couldnt get it to show std::cout at all. Notice that I can still go to definition if I manually type it out (this has always worked)
clangd2

Heres the logs
cquery.log
clangd.log

@mattn
Copy link
Collaborator

mattn commented Jan 31, 2019

cquery

The first gif, vim-lsp send request for completin with text std::. And response are:

is_signed
isupper
isupper
is_void
is_array
add_volatile
fill_n
time_put_byname
enable_if_t
aligned_union_t
moneypunct
cin
strtoll
set_new_handler
wcslen
basic_ifstream
wfilebuf
vsscanf
front_insert_iterator
unexpected_handler
wcstok
remove_volatile_t
messages_byname
is_trivially_copy_constructible
stod
stod
piecewise_construct
_S_internal
_Require
stoll
stoll
vfwprintf
make_error_code
make_error_code
range_error
aligned_union
_Select1st
flush
oct
conditional
int_fast64_t
ungetc
wostream
cout
output_iterator_tag
hexfloat
copy_backward
uses_allocator
greater_equal
istream
numpunct
is_swappable_v
iterator_traits
is_arithmetic
_S_left
vswprintf
make_signed_t
remove_all_extents
has_facet
error_condition
make_pair
swap
swap
swap
swap
swap
literals
set_terminate
add_pointer_t
is_member_function_pointer
num_get
error_code
wstringbuf
uint_least32_t
_S_ios_iostate_max
to_string
to_string
to_string
to_string
to_string
to_string
to_string
to_string
to_string
binder1st
allocator
toupper
toupper
malloc
strtof
_S_end
remove_reference
strtoul
putwc
fputwc
throw_with_nested
binary_negate
_S_boolalpha
max
max

You seems type some keys. So the condidates are filtered in the popup window. (As far as I see from cquery.log, you selected conditional)

Could you please try this?

let g:lsp_async_completion = 1

clangd

When open a file, vim-lsp start language server. This take bit while for ready. On my environment, It take about 5sec until be possible to do omni completion. So as far as I can see the second gif, it seems that langserver is not ready yet.

@Alexmac22347
Copy link
Author

Alexmac22347 commented Feb 1, 2019

Sorry just so you dont get confused, the logs and the gifs arent exactly the same. I forgot to turn on logging when I was making the gif, so the exact word I selected might be different from the gif. Also, I am using the omni complete function, ie in my vimrc I have set
autocmd FileType cpp setlocal omnifunc=lsp#complete
I will try your suggestions today

@prabirshrestha
Copy link
Owner

Please do try omnifunc and asyncomplete separately that will help us identify if the bug is in asyncomplete or omnifunc

@Alexmac22347
Copy link
Author

Hi, I tried waiting for clangd, but it didnt autocomplete std::cout. It must be finished initialization because I can see many other autocomplete suggestions showing, and I can also goto definition of std::cout.

Good news though, I tried using asyncomplete and asyncomplete-lsp.
That appears to find cout, and the function from my header file, so I will just use that from now on.
It works with both clangd and cquery.
When I have time, I will look more into why omnicomplete with just vim-lsp wasnt working. It works when I use the plugin vim-lsc, so I can compare how the two are sending the auto completion request to the server

@Alexmac22347
Copy link
Author

btw, heres the log when it works with asyncomplete. Note that since it autocompletes as I type, theres probably a lot more completion requests
lsp.log

@prabirshrestha
Copy link
Owner

If you are using asyncomplete please try the v2 branch. It has lot of improvements.

@mkwork
Copy link
Contributor

mkwork commented Mar 5, 2019

Please be noticed that cquery is no more supported by its author and its community and current master branch is in mess a bit. Try with its latest release or ccls or even clangd.

@prabirshrestha
Copy link
Owner

@mkwork If itsn't supported we should remove it from the wiki. https://github.com/prabirshrestha/vim-lsp/wiki/Servers-cquery

@mkwork
Copy link
Contributor

mkwork commented Mar 5, 2019

I guess it's better to make remark about stable version and possibly broken master. Also link to this issue could be provided.

I can propose such form:

ATTENTION: looks like cquery is no more supported by its author and master could be unstable. Please check this issues status. Anyway try to use latest stable version or other clang based language server like ccls or clangd, before reporting issues related to cquery.

@Alexmac22347
Copy link
Author

Yeah, I just did a fresh install of vim-lsp and clangd, and everything seems to work now, so I think it was a cquery problem. Thanks for the help!

@Abbyyan
Copy link

Abbyyan commented Jun 23, 2019

Thank your report. BTW, I tried to install cquery on Ubuntu 18.04 but cquery crash when cquery receives completion. (I always use clangd)

Sorry to bother you . Could you give an config of vim-lsp on clangd? I have installed clangd and vim-lsp , but it seems can't work just for autocomplete. Will it come out the selection bar automatically when I input some words ? Or should i type Ctl+N when i want to use complete features? It seems like i still use original vim-autocomplete even after i config the vim-lsp. Hope for your reply . Thanks a lot.

@thomasfaingnaert
Copy link
Collaborator

@Abbyyan I'm using the following config for clangd:

if executable('clangd')
    augroup vim_lsp_cpp
        autocmd!
        autocmd User lsp_setup call lsp#register_server({
                    \ 'name': 'clangd',
                    \ 'cmd': {server_info->['clangd']},
                    \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp', 'cc'],
                    \ })
        autocmd FileType c,cpp,objc,objcpp,cc setlocal omnifunc=lsp#complete
        autocmd FileType c,cpp,objc,objcpp,cc setlocal keywordprg=:LspHover
        autocmd FileType c,cpp,objc,objcpp,cc nnoremap <buffer> <C-]> :LspDefinition<CR>
        autocmd FileType c,cpp,objc,objcpp,cc nnoremap <buffer> <F2> :LspRename<CR>
    augroup end
endif

You can start completion manually by pressing CTRL-X CTRL-O in insert mode.
If you want the completion menu to pop up automatically, you may want to check out https://github.com/prabirshrestha/asyncomplete.vim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants