Author Topic: cc toolbar related database update  (Read 1503 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4909
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
cc toolbar related database update
« on: August 19, 2015, 06:31:25 am »
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".

Code: [Select]
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:

Code: [Select]
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?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9414
Re: cc toolbar related database update
« Reply #1 on: August 19, 2015, 08:08:05 am »
What do you think?
Once again I am a bit worried about the a visible delay, but its worth a trial.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4909
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: cc toolbar related database update
« Reply #2 on: August 19, 2015, 02:50:48 pm »
What do you think?
Once again I am a bit worried about the a visible delay, but its worth a trial.
There is no visual delay I can see. CodeCompletion::OnEditorOpen() only add an empty element (marked as unparsed). My change is that the adding of empty element is delayed to CodeCompletion::OnEditorActivatedTimer() function, and is further delayed to CodeCompletion::OnToolbarTimer() function. In OnToolbarTimer, we call CodeCompletion::ParseFunctionsAndFillToolbar(). Then the following code automatically add an empty element if filename is not existed in the container(std::map<wxString, FunctionsScopePerFile>)

Code: [Select]
FunctionsScopePerFile* funcdata = &(m_AllFunctionsScopes[filename]);

Then, the default constructor of FunctionsScopePerFile is also set the parsed field as "unparsed".
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.