Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Python Code Completion
MortenMacFly:
--- Quote from: oBFusCATed on October 19, 2012, 10:11:30 am ---
--- Quote from: MortenMacFly on October 19, 2012, 10:04:21 am ---What I meant is not only to trust the editor style - this might be wrong.
--- End quote ---
Do we have a function we could trust?
--- End quote ---
Not atm.
But better than either only checking for the editor style or only checking for the file types and mask is probably doing both in a proper way.
dmoore:
For the UI I thought it would be more reliable to trust the Lexer:
* C++ std headers have no extension
* Python scripts on unix are often missing an extension (they do usually have shebang and so could be inferred)
* As Rick has mentioned to me in the past, CC can be used for C like languages, hence we dont want to just restrict CC to C/C++
* The user can switch the highlight mode of a file. When they do i think their intent should be respected by CC.
* Note that i dont think either patch affects what the parser parses, just the files it offers a UI for. CC has a UI to control the parser i think.
So how about a more refined version. Each plugin has public member bool IsProviderFor(cbEditor *ed). That can do whatever checks that plugin prefers. For CC itself, since it is fallback, its method would be
--- Code: ---For each CC plugin instance except me:
if Plugin.IsProviderFor(ed):
return false
return true
--- End code ---
MortenMacFly:
--- Quote from: dmoore on October 19, 2012, 02:24:59 pm ---For CC itself, since it is fallback, its method would be
--- Code: ---For each CC plugin instance except me:
if Plugin.IsProviderFor(ed):
return false
return true
--- End code ---
--- End quote ---
Yes, I think it should be something like that. Similar to what we actually do with plugins:
if Plugin.OffersFor(CC, Debugger...) [Do something.]
It can / has to be handled with CC plugins, too.
BTW: We should also consider several CC plugins for one language, like Clang and Ctags - if one fails, the other can be queried as fallback. While working on the integration of Erans CC into C::B I was facing such. So in the code above, not only return "false", but do some more intelligent stuff, like "if generally responsible, do CC and return "true", but if the not enough information to complete, return false and let others try"... You get the idea.
dmoore:
--- Quote from: MortenMacFly on October 19, 2012, 02:48:25 pm ---BTW: We should also consider several CC plugins for one language, like Clang and Ctags - if one fails, the other can be queried as fallback. While working on the integration of Erans CC into C::B I was facing such. So in the code above, not only return "false", but do some more intelligent stuff, like "if generally responsible, do CC and return "true", but if the not enough information to complete, return false and let others try"... You get the idea.
--- End quote ---
I think that will need to wait until we refactor stuff into the SDK. Right now CC provides a couple of UI bits that all plugins use (call tip and completion) but plugins must provide their own symbol tree, right click menu options etc. Defining more complicated fallback behavior as you are proposing above will require more extensive reworking.
dmoore:
Here's a revised patch to try. I've made the needed change to the fortran plugin as well.
(EDIT: Patch revised again, thx OllyDbg)
--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 8464)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -727,8 +727,12 @@
if ( ParserCommon::FileType(filename) == ParserCommon::ftOther
&& Manager::Get()->GetPluginManager()->IsFileExtRegistered(filename) )
return;
+
+ if(!IsProviderFor(ed))
+ return;
}
+
wxString NameUnderCursor;
bool IsInclude = false;
const bool nameUnderCursor = CodeCompletionHelper::EditorHasNameUnderCursor(NameUnderCursor, IsInclude);
@@ -825,6 +829,16 @@
return true;
}
+bool CodeCompletion::IsProviderFor(cbEditor *ed)
+{
+ PluginsArray pa=Manager::Get()->GetPluginManager()->GetCodeCompletionOffers();
+ for(unsigned int i = 0; i < pa.Count(); ++i)
+ if(pa[i]!=this && static_cast<cbCodeCompletionPlugin*>(pa[i])->IsProviderFor(ed))
+ return false;
+ return true;
+}
+
+
int CodeCompletion::CodeComplete()
{
if (!IsAttached() || !m_InitDone)
@@ -835,6 +849,9 @@
if (!ed)
return -3;
+ if(!IsProviderFor(ed))
+ return -3;
+
FileType ft = FileTypeOf(ed->GetShortName());
const bool caseSens = m_NativeParser.GetParser().Options().caseSensitive;
@@ -1015,6 +1032,9 @@
if (!ed)
return;
+ if(!IsProviderFor(ed))
+ return;
+
wxString filename = ed->GetShortName();
if ( ParserCommon::FileType(filename) == ParserCommon::ftOther
&& Manager::Get()->GetPluginManager()->IsFileExtRegistered(filename) )
@@ -1342,6 +1362,9 @@
return;
}
+ if(!IsProviderFor(editor))
+ return;
+
cbStyledTextCtrl* control = editor->GetControl();
if (event.GetEventType() == wxEVT_SCI_CHARADDED)
Index: src/plugins/codecompletion/codecompletion.h
===================================================================
--- src/plugins/codecompletion/codecompletion.h (revision 8464)
+++ src/plugins/codecompletion/codecompletion.h (working copy)
@@ -89,6 +89,7 @@
virtual wxArrayString GetCallTips() { return wxArrayString(); }
virtual int CodeComplete();
virtual void ShowCallTip();
+ virtual bool IsProviderFor(cbEditor *ed);
/** give auto suggestions on preprocessor directives*/
void CodeCompletePreprocessor();
Index: src/sdk/cbplugin.cpp
===================================================================
--- src/sdk/cbplugin.cpp (revision 8464)
+++ src/sdk/cbplugin.cpp (working copy)
@@ -1216,6 +1216,7 @@
return -1;
}
+
//ToDo: Is this c++ only?
int cbSmartIndentPlugin::GetFirstBraceInLine(cbStyledTextCtrl* stc, int string_style)const
{
Index: src/include/cbplugin.h
===================================================================
--- src/include/cbplugin.h (revision 8464)
+++ src/include/cbplugin.h (working copy)
@@ -743,6 +743,24 @@
virtual wxArrayString GetCallTips() = 0;
virtual int CodeComplete() = 0;
virtual void ShowCallTip() = 0;
+ /** @brief Does this plugin handle code completion for the editor cb?
+ *
+ * A plugin should override this function to indicate whether it will
+ * provide completion and call tips for the editor. The plugin should
+ * then prepare to handle codecomplete and calltip menu messages if
+ * it returns true. To implement this function, plugins will usually
+ * check the mimetype of the file or the current lexer (highlight
+ * language).
+ *
+ * Note: Currently the core CC plugin provides a default CodeCompletion
+ * implementation for any file type that is not provided for by any
+ * other CC plugins. The calltip and main menu options that can be handled
+ * by any CC plugin is also supplied by the core CC plugin.
+ *
+ * @param cb The editor for which code completion
+ * @return return true if the plugin handles completion for this editor,
+ * false otherwise*/
+ virtual bool IsProviderFor(cbEditor* /*cb*/) { return false; }
};
/** @brief Base class for wizard plugins
@@ -857,6 +875,7 @@
/** Get the last non-whitespace character from position in line */
wxChar GetNextNonWhitespaceCharOfLine(cbStyledTextCtrl* stc, int position = -1, int *pos = 0)const;
+
bool AutoIndentEnabled()const;
bool SmartIndentEnabled()const;
bool BraceSmartIndentEnabled()const;
Index: src/plugins/contrib/FortranProject/fortranproject.cpp
===================================================================
--- src/plugins/contrib/FortranProject/fortranproject.cpp (revision 27)
+++ src/plugins/contrib/FortranProject/fortranproject.cpp (working copy)
@@ -1226,6 +1226,16 @@
return -5;
}
+bool FortranProject::IsProviderFor(cbEditor *cb)
+{
+ if (!ed
+ || !m_pNativeParser->IsFileFortran(ed->GetShortName())
+ || !Manager::Get()->GetConfigManager(_T("fortran_project"))->ReadBool(_T("/use_code_completion"), true))
+ {
+ return false;
+ }
+ return true;
+}
+
void FortranProject::ShowCallTip()
{
if (!IsAttached() || !m_InitDone)
Index: src/plugins/contrib/FortranProject/fortranproject.h
===================================================================
--- src/plugins/contrib/FortranProject/fortranproject.h (revision 27)
+++ src/plugins/contrib/FortranProject/fortranproject.h (working copy)
@@ -46,6 +46,7 @@
virtual wxArrayString GetCallTips();
virtual int CodeComplete();
virtual void ShowCallTip();
+ virtual bool IsProviderFor(cbEditor *cb);
void OnCodeComplete(wxCommandEvent& event);
void OnShowCallTip(wxCommandEvent& event);
void CompleteCodeEvt(CodeBlocksEvent& event);
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version