clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.57k stars 64 forks source link

Suggest inserting using declarations in addition to inserting qualifiers for unknown/unresolved symbols #976

Open kadircet opened 2 years ago

kadircet commented 2 years ago

Clangd already suggests qualifying symbols e.g:

namespace ns { struct Foo {}; }
void bar() {
  Foo f; // here clangd will offer a fix for qualifting `Foo` to `ns::Foo`.
}

In addition to that, we can also offer a fix that inserts a using declaration.

sam-mccall commented 2 years ago

Yes, I want this all the time and always do the dumb two-step version.

The trick is getting the layering right: FindUsing doesn't know about the namespace (though I guess the recovered AST has it...) and Sema doesn't know where to insert using.