EDIT: the asynchronized request is just my idea.
An asynchronized request:
1, ccmanager call a function in ccplugin, thus a request is send to ccplugin
2, ccplugin return a special value(maybe a number), and ccmanager know it will return the results later.
3, ccplugin can do the dirty work in a worker thread
4, when result is out, ccplugin can send a message or call a sdk function from ccplugin
5, the result is shown.
If there are another request in between those steps, we can cancel some steps and do it again, a request can have a number, so they don't conflict.
Hi, yvesdm3000, I think you have already implement this kind of feature.
The code is here:
std::vector<cbCodeCompletionPlugin::CCToken> ClangCodeCompletion::GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd)
{
// you just use the m_CCOutstandingResults to generate a returned tokens
}
And in the code:
void ClangCodeCompletion::OnCodeCompleteFinished( ClangEvent& event )
{
//CCLogger::Get()->DebugLog( wxT("OnCodeCompleteFinished") );
if ( event.GetTranslationUnitId() != m_TranslUnitId )
{
return;
}
if (m_CCOutstanding > 0)
{
if ( event.GetLocation() != m_CCOutstandingLoc )
{
CCLogger::Get()->DebugLog( wxT("Discard old CodeCompletion request result") );
return;
}
EditorManager* edMgr = Manager::Get()->GetEditorManager();
cbEditor* ed = edMgr->GetBuiltinActiveEditor();
if (ed)
{
m_CCOutstandingResults = event.GetCodeCompletionResults();
if ( m_CCOutstandingResults.size() > 0 )
{
CodeBlocksEvent evt(cbEVT_COMPLETE_CODE);
evt.SetInt(1);
Manager::Get()->ProcessEvent(evt);
return;
}
}
m_CCOutstanding--;
}
}
This event is send from the thread to the plugin, and you manually fire a cbEVT_COMPLETE_CODE.
Pay attachment to the value
I think in the ccmanager, this int value only have two meanings:
FROM_TIMER or not FROM_TIMER.
I'm not quite sure whether FROM_TIMER means, but we may add another option like "delayed call".
By reading the doxygen docs of this function:
virtual std::vector<CCToken> GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd) = 0;
I see that the returned value could be
1, an empty vector, in this case, no code suggestion will list
2, a non empty vector, thus a code suggestion list will prompted.
So, maybe we can add another returned value, indicates that the plugin will returned the vector later (asynchronized way).