Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Several improvements to Code Completion plugin
Huki:
Thanks for the commit.
Two patches for build targets parsing (i.e., project defined macros):
1) When a virtual target is selected, collect the defines for all child targets. Eg., in the CB project, if the "All" virtual target is selected we should collect defines from all sub-targets (scintilla, etc).
--- Code: ---Index: src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- src/plugins/codecompletion/nativeparser.cpp (revision 9271)
+++ src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -2342,6 +2367,18 @@
for (size_t i = 0; i < targetOpts.GetCount(); ++i)
opts.Add(targetOpts[i]);
}
+ // In case of virtual targets, collect the defines from all child targets.
+ wxArrayString targets = project->GetExpandedVirtualBuildTargetGroup(project->GetActiveBuildTarget());
+ for (size_t i = 0; i < targets.GetCount(); ++i)
+ {
+ target = project->GetBuildTarget(targets[i]);
+ if (target != NULL)
+ {
+ wxArrayString targetOpts = target->GetCompilerOptions();
+ for (size_t j = 0; j < targetOpts.GetCount(); ++j)
+ opts.Add(targetOpts[j]);
+ }
+ }
for (size_t i = 0; i < opts.GetCount(); ++i)
{
--- End code ---
2) When the build target is changed, trigger a whole project reparse.
--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 9271)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -647,6 +695,8 @@
pm->RegisterEventSink(cbEVT_WORKSPACE_CHANGED, new cbEventFunctor<CodeCompletion, CodeBlocksEvent>(this, &CodeCompletion::OnWorkspaceChanged));
+ pm->RegisterEventSink(cbEVT_BUILDTARGET_SELECTED, new cbEventFunctor<CodeCompletion, CodeBlocksEvent>(this, &CodeCompletion::OnBuildTargetSelected));
+
pm->RegisterEventSink(cbEVT_PROJECT_ACTIVATE, new cbEventFunctor<CodeCompletion, CodeBlocksEvent>(this, &CodeCompletion::OnProjectActivated));
pm->RegisterEventSink(cbEVT_PROJECT_CLOSE, new cbEventFunctor<CodeCompletion, CodeBlocksEvent>(this, &CodeCompletion::OnProjectClosed));
pm->RegisterEventSink(cbEVT_PROJECT_SAVE, new cbEventFunctor<CodeCompletion, CodeBlocksEvent>(this, &CodeCompletion::OnProjectSaved));
@@ -2552,6 +2609,29 @@
event.Skip();
}
+void CodeCompletion::OnBuildTargetSelected(CodeBlocksEvent& event)
+{
+ if (!ProjectManager::IsBusy() && IsAttached() && m_InitDone)
+ {
+ cbProject* project = Manager::Get()->GetProjectManager()->GetActiveProject();
+ if (project)
+ {
+ TRACE(_T("CodeCompletion::OnBuildTargetSelected(): Reparsing entire project."));
+
+ ReparsingMap::iterator it = m_ReparsingMap.find(project);
+ if (it != m_ReparsingMap.end())
+ m_ReparsingMap.erase(it);
+ if (m_NativeParser.DeleteParser(project))
+ m_NativeParser.CreateParser(project);
+
+ m_AutocompNameIdx.clear();
+ m_LastAutocompIndex = -1;
+ }
+ }
+
+ event.Skip();
+}
+
void CodeCompletion::OnProjectActivated(CodeBlocksEvent& event)
{
// The Class browser shouldn't be updated if we're in the middle of loading/closing
Index: src/plugins/codecompletion/codecompletion.h
===================================================================
--- src/plugins/codecompletion/codecompletion.h (revision 9271)
+++ src/plugins/codecompletion/codecompletion.h (working copy)
@@ -196,6 +200,7 @@
void OnProjectFileAdded(CodeBlocksEvent& event);
void OnProjectFileRemoved(CodeBlocksEvent& event);
void OnProjectFileChanged(CodeBlocksEvent& event);
+ void OnBuildTargetSelected(CodeBlocksEvent& event);
/** SDK editor related events */
void OnEditorSaveOrModified(CodeBlocksEvent& event);
void OnEditorOpen(CodeBlocksEvent& event);
--- End code ---
ollydbg:
The patch is still against old svn revision(92xx), we are currently in rev 98xx, there are around 600 commits. :)
It looks like
--- Code: --- m_AutocompNameIdx.clear();
m_LastAutocompIndex = -1;
--- End code ---
are totally removed in commit rev9694(CC management commits serials by alpha), I'm not sure it is simple remove the above two lines from your patch, still need time to test. :)
Huki:
--- Quote from: ollydbg on June 21, 2014, 04:01:26 am ---The patch is still against old svn revision(92xx), we are currently in rev 98xx, there are around 600 commits. :)
It looks like
--- Code: --- m_AutocompNameIdx.clear();
m_LastAutocompIndex = -1;
--- End code ---
are totally removed in commit rev9694(CC management commits serials by alpha), I'm not sure it is simple remove the above two lines from your patch, still need time to test. :)
--- End quote ---
Oh, those two lines can be safely removed.. I should have removed them myself but forgot.
Initially I took code from CodeCompletion::OnCurrentProjectReparse() which contained the Autocomp lines. But this code parses the current project (i.e., project of active editor). The goal is to reparse the active project (for which build target was changed), so we should do similar to CodeCompletion::OnProjectSavedTimer():
- Get the active project.
- Search for and remove project from m_ReparsingMap.
- Delete project's parser.
- Create project parser.
So the Autocomp lines are not required.
MortenMacFly:
Still, please always try to provide patches against trunk HEAD. Everything else is error prone.
ollydbg:
@Huki.
About parsing the target in a project. See an example.
A project have two targets: TargetA, TargetB.
TargetA is the active target, which contains two cpp file (A1.cpp, A2.cpp), TargetB contains two cpp file (B1.cpp, B2.cpp).
Current method: parse all the four files with the preprecessor directive from TargetA, see bool NativeParser::DoFullParsing(cbProject* project, ParserBase* parser).
Is this OK?
Or, is it better to only parse the files(A1.cpp, A2.cpp) belong to the active target? I don't have an idea.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version