Beginner code completion questions


I just installed a trial of CLion, to use for C++, and I'm playing around with code completion. I have a couple questions. 

One of the repetitive things I type are `using` declarations at the top of a file. For example `using std::cout`, `using std::vector`, `using std::chrono_literals`. I don't like typing "::" (it's worse on my Dvorak layout).  I notice that... 

#include <iostream>
using ve // shows std::vector completion at top of list
using cou // no std::cout
using sc // show some matches on std::chrono by matching the first letters
// but again, no std::cout

Is this controlled by a setting somewhere? Is it a bug?

I notice that there is some support for splitting the string and matching the initial letters of parts. For example: (parens show which letters are highlighted as matching)...

using sc     // shows list with (s)td::(c)hrono::steady_clock 
// (s)td::(c)hrono::system_clock

But if then try to keep typing to select one of of those, it doesn't work. Say I type "scsy", to try to narrow that down to "std::chrono::system_clock". It doesn't find anything. Even "scs" doesn't match anything. It seems like if "sc" matches "std::chrono", then "scs" should match "std::chrono::system_clock".  

Oddly, "using ss" shows a completion list for "(s)td::chrono::(s)ys_seconds. So in that case it did start matching on the 3rd part. ?? Is there an explanation somewhere of how this works? Is this configurable? Is it a bug?


CLion 2022.2.1. macOS 12.5.1

1 comment

Hi! I wouldn't say it's a bug. There are certain limitations of what code completion may or may not show. Clangd looks up valid declarations, we use these results to show completions and try to prioritise and filter them. There are cases when clangd looks inside namespaces but they are limited because code completion shouldn't be slow.

In your case the classes from `std` namespace are just not found by lookup because it skips `std` namespace. So it doesn't matter which pattern you use - the completion won't show what it doesn't have. However your case is probably a good example when looking into namespaces could be a good idea so I would suggest you to create a ticket in our bugtracker.


Please sign in to leave a comment.