We've hit a couple issues while using clang for refactoring/auto-completion tools
1. clang code completion - There are two virtual methods within clang::CodeCompletionConsumer class. First is 'ProcessCodeCompleteResults'. This methods is working quite well. But second - 'ProcessOverloadCandidates', which is providing functions overload candidates within function call context, is working very strange. This method is called /only /within context of calling free function. Example:\
void Foo();
void Bar()
{
Foo(>|<); // Overload candidates are successfully provided and contain one item ('Foo()')
}
But:
class Clazz
{
public:
Clazz(int, int);
void Foo();
void TestFn();
};
void Bar(Clazz& cls)
{
cls.Foo(>|<); // Overload candidates aren't provided
Class other(>|<); // The same.
}
void TestFn()
{
Foo(>|<); // The same. Overload candidates aren't provided
}
Here ">|<" mark shows a current text caret position for which code completion is requested.
Is there missing functionality here? (If so anyone interested to help us with this?)
2. Here is a sample class:
class BaseClass : public SuperBaseClass
{
public:
BaseClass(int a);
BaseClass(int a, int b);
void SomeVirtualMethod(int a, int b = 10);
void foo(int a, int b);
void foo(double a);
void foo(BaseClass *cls);
};
BaseClass::>|<
In the point marked with ">|<" suggestion list doesn't contain constructors of the 'BaseClass'. It's very strange.
3. AST building. We're looking to implement:
- Create method declaration from usage
- Create method declaration from definition
Both this features assume what source code (in initial state) contains an error and feature implementation fix this error in the corresponded way. The problem is clang can't help us to analyze the line with such error.
For example:
void Bar()
{
int a, b;
Foo(a, b); // There is no 'Foo' function within code yet
}
clang parser throws out the line with 'Foo' call from AST. So we can't analyze nor type of symbol or type of arguments within this context.
My primary question is: can we add some special AST nodes into clang parser in order to handle such cases? In normal situation AST consumers/visitors will ignore such nodes but in case of refactoring we could extract some additional info from source code and have special handling for it.