Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: ollydbg on March 20, 2015, 03:31:39 pm

Title: Why the handling of OnProjectSaved is delayed by a timer
Post by: ollydbg on March 20, 2015, 03:31:39 pm
Hi, Morten, when reviewing the code, I have a question for revision 6510, which is on codecompletion_refactoring branch. (I just use a very simple git log -G command to find the exact revision number)

Here is the change:
Code
* cc_branch: applied patch to add timer for OnProjectSaved
   
    git-svn-id: http://svn.code.sf.net/p/codeblocks/code/branches/codecompletion_refactoring@6510 2a5c6006-c6dd-42ca-98ab-0921f2732cef

---------------- src/plugins/codecompletion/codecompletion.cpp ----------------
index 501642e..40e0c6a 100644
@@ -135,6 +135,7 @@ int idCodeCompleteTimer         = wxNewId();
 int idFunctionsParsingTimer     = wxNewId();
 int idRealtimeParsingTimer      = wxNewId();
 int idToolbarTimer              = wxNewId();
+int idProjectSavedTimer         = wxNewId();
 
 // milliseconds
 #define REALTIME_PARSING_DELAY      500
@@ -164,6 +165,7 @@ BEGIN_EVENT_TABLE(CodeCompletion, cbCodeCompletionPlugin)
     EVT_TIMER(idFunctionsParsingTimer, CodeCompletion::OnStartParsingFunctions)
     EVT_TIMER(idRealtimeParsingTimer, CodeCompletion::OnRealtimeParsing)
     EVT_TIMER(idToolbarTimer, CodeCompletion::OnStartParsingFunctions)
+    EVT_TIMER(idProjectSavedTimer, CodeCompletion::OnProjectSavedTimer)
 
     EVT_CHOICE(XRCID("chcCodeCompletionScope"),  CodeCompletion::OnScope)
     EVT_CHOICE(XRCID("chcCodeCompletionFunction"),  CodeCompletion::OnFunction)
@@ -180,6 +182,7 @@ CodeCompletion::CodeCompletion() :
     m_TimerFunctionsParsing(this, idFunctionsParsingTimer),
     m_TimerRealtimeParsing(this, idRealtimeParsingTimer),
     m_TimerToolbar(this, idToolbarTimer),
+    m_TimerProjectSaved(this, idProjectSavedTimer),
     m_pCodeCompletionLastEditor(0),
     m_ActiveCalltipsNest(0),
     m_IsAutoPopup(false),
@@ -901,7 +904,6 @@ public:
             // crash in linux, why?
 //            Manager::Get()->GetLogManager()->DebugLog(F(_T("Get Headers: %s , %d"), dirs[i].wx_str(),
 //                                                        m_SystemHeadersMap[dirs[i]].size()));
-#endif // crash in linux, why?
         }
 
         return 0;
@@ -1486,8 +1488,6 @@ void CodeCompletion::OnCodeCompleteTimer(wxTimerEvent& event)
 
 void CodeCompletion::OnWorkspaceChanged(CodeBlocksEvent& event)
 {
-//    Manager::Get()->GetLogManager()->DebugLog(_T("CodeCompletion::OnWorkspaceChanged"));
-
     // EVT_WORKSPACE_CHANGED is a powerful event, it's sent after any project
     // has finished loading or closing. It's the *LAST* event to be sent when
     // the workspace has been changed, and it's not sent if the application is
@@ -1511,8 +1511,6 @@ void CodeCompletion::OnWorkspaceChanged(CodeBlocksEvent& event)
 
 void CodeCompletion::OnProjectActivated(CodeBlocksEvent& event)
 {
-//    Manager::Get()->GetLogManager()->DebugLog(_T("CodeCompletion::OnProjectActivated"));
-
     // The Class browser shouldn't be updated if we're in the middle of loading/closing
     // a project/workspace, because the class browser would need to be updated again.
     // So we need to update it with the EVT_WORKSPACE_CHANGED event, which gets
@@ -1533,8 +1531,6 @@ void CodeCompletion::OnProjectActivated(CodeBlocksEvent& event)
 
 void CodeCompletion::OnProjectClosed(CodeBlocksEvent& event)
 {
-//    Manager::Get()->GetLogManager()->DebugLog(_T("CodeCompletion::OnProjectClosed"));
-
     // After this, the Class Browser needs to be updated. It will happen
     // when we receive the next EVT_PROJECT_ACTIVATED event.
     if (IsAttached() && m_InitDone)
@@ -1549,14 +1545,25 @@ void CodeCompletion::OnProjectClosed(CodeBlocksEvent& event)
 void CodeCompletion::OnProjectSaved(CodeBlocksEvent& event)
 {
     // reparse project (compiler search dirs might have changed)
-    cbProject* project = event.GetProject();
-    if (IsAttached() && m_InitDone)
+    if (m_TimerProjectSaved.IsRunning())
+        m_TimerProjectSaved.Stop();
+
+    m_TimerProjectSaved.SetClientData(event.GetProject());
+    // we need more time for waiting wxExecute in NativeParser::AddCompilerPredefinedMacros
+    m_TimerProjectSaved.Start(1000, wxTIMER_ONE_SHOT);
+
+    event.Skip();
+}
+
+void CodeCompletion::OnProjectSavedTimer(wxTimerEvent& event)
+{
+    cbProject* project = static_cast<cbProject*>(m_TimerProjectSaved.GetClientData());
+    m_TimerProjectSaved.SetClientData(NULL);
+
+    if (IsAttached() && m_InitDone && project && m_NativeParser.DeleteParser(project))
     {
-        if (project && m_NativeParser.DeleteParser(project))
-        {
-            Manager::Get()->GetLogManager()->DebugLog(_T("Reparsing project."));
-            m_NativeParser.CreateParser(project);
-        }
+        Manager::Get()->GetLogManager()->DebugLog(_T("Reparsing project."));
+        m_NativeParser.CreateParser(project);
     }
 
     event.Skip();

----------------- src/plugins/codecompletion/codecompletion.h -----------------
index 0085db4..3529377 100644
@@ -127,6 +127,7 @@ class CodeCompletion : public cbCodeCompletionPlugin
         void UpdateFunctions(unsigned int scopeItem);
         void EnableToolbarTools(bool enable = true);
  void OnRealtimeParsing(wxTimerEvent& event);
+ void OnProjectSavedTimer(wxTimerEvent& event);
 
         cbThreadPool                       m_ThreadPool;
         int                                m_PageIndex;
@@ -143,6 +144,7 @@ class CodeCompletion : public cbCodeCompletionPlugin
         wxTimer                            m_TimerFunctionsParsing;
         wxTimer                            m_TimerRealtimeParsing;
         wxTimer                            m_TimerToolbar;
+        wxTimer                            m_TimerProjectSaved;
         cbEditor*                          m_pCodeCompletionLastEditor;
         int                                m_ActiveCalltipsNest;

So, what does the comment line:
Code
// we need more time for waiting wxExecute in NativeParser::AddCompilerPredefinedMacros
means?

Is the patch from Loaden? I can't find any discussion about this patch here. Any ideas?
Title: Re: Why the handling of OnProjectSaved is delayed by a timer
Post by: MortenMacFly on March 20, 2015, 10:52:48 pm
As far as I remember it caused a crash a when wxexecute was not finished on (slow?) pcs. You can play with it and disable the timer to see if that's still the case...