When an editor is opened, we do those things, which add one element in the cc toolbar database (m_AllFunctionsScopes), and mark it as "unparsed".
void CodeCompletion::OnEditorOpen(CodeBlocksEvent& event)
{
if (!Manager::IsAppShuttingDown() && IsAttached() && m_InitDone)
{
cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor());
if (ed)
{
FunctionsScopePerFile* funcdata = &(m_AllFunctionsScopes[ed->GetFilename()]);
funcdata->parsed = false;
}
}
event.Skip();
}
When loading a project, c::b may open a lot of editors, then we add many elements, and mark them as "unparsed".
One think I think it is not necessary, is that we can have a default constructor of the element, which mark the file(editor) as unparsed, see the patch below:
9e1059c39ce826e9c0f56e8aa9c3766840c6316e
src/plugins/codecompletion/codecompletion.cpp | 4 +++-
src/plugins/codecompletion/codecompletion.h | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/plugins/codecompletion/codecompletion.cpp b/src/plugins/codecompletion/codecompletion.cpp
index 9d8ab6e..32953a1 100644
--- a/src/plugins/codecompletion/codecompletion.cpp
+++ b/src/plugins/codecompletion/codecompletion.cpp
@@ -2421,7 +2421,7 @@ void CodeCompletion::OnEditorSave(CodeBlocksEvent& event)
void CodeCompletion::OnEditorOpen(CodeBlocksEvent& event)
{
- if (!Manager::IsAppShuttingDown() && IsAttached() && m_InitDone)
+ if (!ProjectManager::IsBusy() && !Manager::IsAppShuttingDown() && IsAttached() && m_InitDone)
{
cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor());
if (ed)
@@ -3036,6 +3036,8 @@ void CodeCompletion::ParseFunctionsAndFillToolbar()
// FunctionsScopePerFile contains all the function and namespace information for
// a specified file, m_AllFunctionsScopes[filename] will implicitly insert an new element in
// the map if no such key(filename) is found.
+ // thus, we don't need to add one filename in the EditorOpen Event when project is loading
+ // by default, the implicitly added one has parsed field set as false
FunctionsScopePerFile* funcdata = &(m_AllFunctionsScopes[filename]);
// *** Part 1: Parse the file (if needed) ***
diff --git a/src/plugins/codecompletion/codecompletion.h b/src/plugins/codecompletion/codecompletion.h
index ec4b240..4293d30 100644
--- a/src/plugins/codecompletion/codecompletion.h
+++ b/src/plugins/codecompletion/codecompletion.h
@@ -70,6 +70,7 @@ public:
struct FunctionsScopePerFile
{
+ FunctionsScopePerFile():parsed(false){}
FunctionsScopeVec m_FunctionsScope; // all functions in the file
NameSpaceVec m_NameSpaces; // all namespaces in the file
bool parsed; // indicates whether this file is parsed or not
Here, a default constructor of the element(FunctionsScopePerFile), so that we can stop adding the element when project is loading. void CodeCompletion::ParseFunctionsAndFillToolbar() will be triggered when an editor is activated. And if the file associated with the editor is not recorded in the cc toolbar database, we get its default status as "unparsed".
BTW: with this change, I think we can totally
remove the function: CodeCompletion::OnEditorOpen(), since all can be handled in OnEditorActivated().
What do you think?