Code::Blocks  SVN r11506
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
cbCodeCompletionPlugin Class Referenceabstract

Base class for code-completion plugins. More...

#include <cbplugin.h>

Inheritance diagram for cbCodeCompletionPlugin:
Collaboration diagram for cbCodeCompletionPlugin:

Classes

struct  CCCallTip
 Structure representing an individual calltip with an optional highlighted range. More...
 
struct  CCToken
 Structure representing a generic token, passed between CC plugins and CCManager. More...
 

Public Types

enum  CCProviderStatus { ccpsInactive, ccpsActive, ccpsUniversal }
 Level of functionality a CC plugin is able to provide. More...
 

Public Member Functions

 cbCodeCompletionPlugin ()
 
virtual CCProviderStatus GetProviderStatusFor (cbEditor *ed)=0
 Does this plugin handle code completion for the editor ed? More...
 
virtual std::vector< CCTokenGetAutocompList (bool isAuto, cbEditor *ed, int &tknStart, int &tknEnd)=0
 Supply content for the autocompletion list. More...
 
virtual wxString GetDocumentation (const CCToken &token)=0
 Supply html formatted documentation for the passed token. More...
 
virtual std::vector< CCCallTipGetCallTips (int pos, int style, cbEditor *ed, int &argsPos)=0
 Supply content for the calltip at the specified location. More...
 
virtual std::vector< CCTokenGetTokenAt (int pos, cbEditor *ed, bool &allowCallTip)=0
 Supply the definition of the token at the specified location. More...
 
virtual void DoAutocomplete (const CCToken &token, cbEditor *ed)
 Callback for inserting the selected autocomplete entry into the editor. More...
 
virtual void DoAutocomplete (const wxString &token, cbEditor *ed)
 Callback for inserting the selected autocomplete entry into the editor. More...
 
- Public Member Functions inherited from cbPlugin
 cbPlugin ()
 In default cbPlugin's constructor the associated PluginInfo structure is filled with default values. More...
 
 ~cbPlugin () override
 cbPlugin destructor. More...
 
virtual PluginType GetType () const
 The plugin must return its type on request. More...
 
virtual int GetConfigurationPriority () const
 Return the plugin's configuration priority. More...
 
virtual int GetConfigurationGroup () const
 Return the configuration group for this plugin. More...
 
virtual cbConfigurationPanelGetConfigurationPanel (cb_optional wxWindow *parent)
 Return plugin's configuration panel. More...
 
virtual cbConfigurationPanelGetProjectConfigurationPanel (cb_optional wxWindow *parent, cb_optional cbProject *project)
 Return plugin's configuration panel for projects. More...
 
virtual void BuildMenu (cb_optional wxMenuBar *menuBar)
 This method is called by Code::Blocks and is used by the plugin to add any menu items it needs on Code::Blocks's menu bar. More...
 
virtual void BuildModuleMenu (cb_optional const ModuleType type, cb_optional wxMenu *menu, cb_optional const FileTreeData *data=nullptr)
 This method is called by Code::Blocks core modules (EditorManager, ProjectManager etc) and is used by the plugin to add any menu items it needs in the module's popup menu. More...
 
virtual bool BuildToolBar (cb_optional wxToolBar *toolBar)
 This method is called by Code::Blocks and is used by the plugin to add any toolbar items it needs on Code::Blocks's toolbar. More...
 
virtual int GetToolBarPriority ()
 This method return the priority of the plugin's toolbar, the less value indicates a more preceding position when C::B starts with no configuration file. More...
 
virtual void CreateStatusField (cbStatusBar *statusBar)
 This method is called by Code::Blocks and is used by the plugin to add a field on Code::Blocks's statusbar. More...
 
bool IsAttached () const
 See whether this plugin is attached or not. More...
 
virtual bool CanDetach () const
 See whether this plugin can be detached (unloaded) or not. More...
 

Protected Member Functions

bool IsProviderFor (cbEditor *ed)
 Has this plugin been selected to provide content for the editor. More...
 
- Protected Member Functions inherited from cbPlugin
virtual void OnAttach ()
 Any descendent plugin should override this virtual method and perform any necessary initialization. More...
 
virtual void OnRelease (cb_optional bool appShutDown)
 Any descendent plugin should override this virtual method and perform any necessary de-initialization. More...
 
virtual void NotImplemented (const wxString &log) const
 This method logs a "Not implemented" message and is provided for convenience only. More...
 

Additional Inherited Members

- Protected Attributes inherited from cbPlugin
PluginType m_Type
 Holds the plugin's type. More...
 
bool m_IsAttached
 Holds the "attached" state. More...
 

Detailed Description

Base class for code-completion plugins.

The main operations of a code-completion plugin are executed by CCManager at the appropriate times. Smaller CC plugins should not have need to register very many (if any) events/editor hooks.

Definition at line 732 of file cbplugin.h.

Member Enumeration Documentation

◆ CCProviderStatus

Level of functionality a CC plugin is able to provide.

Enumerator
ccpsInactive 

CC plugin provides no functionality.

ccpsActive 

CC plugin provides specialized functionality.

ccpsUniversal 

CC plugin provides generic functionality.

Definition at line 738 of file cbplugin.h.

Constructor & Destructor Documentation

◆ cbCodeCompletionPlugin()

cbCodeCompletionPlugin::cbCodeCompletionPlugin ( )

Definition at line 1004 of file cbplugin.cpp.

References DoAutocomplete(), cbPlugin::m_Type, and ptCodeCompletion.

Member Function Documentation

◆ DoAutocomplete() [1/2]

virtual void cbCodeCompletionPlugin::DoAutocomplete ( const CCToken token,
cbEditor ed 
)
virtual

Callback for inserting the selected autocomplete entry into the editor.

The default implementation executes (wx)Scintilla's insert. Override and call ed->GetControl()->AutoCompCancel() for different wxEVT_SCI_AUTOCOMP_SELECTION behaviour.

Parameters
tokenThe CCToken corresponding to the selected entry.
edThe editor to operate in.

Reimplemented in CodeCompletion.

Referenced by cbCodeCompletionPlugin(), and CCManager::OnEditorHook().

◆ DoAutocomplete() [2/2]

void cbCodeCompletionPlugin::DoAutocomplete ( const wxString token,
cbEditor ed 
)
virtual

Callback for inserting the selected autocomplete entry into the editor.

This function is only called if CCManager fails to retrieve the CCToken associated with the selection (which should never happen). The default implementation creates a CCToken and passes it to DoAutocomplete(const CCToken&, cbEditor*)
Override for different behaviour.

Parameters
tokenA string corresponding to the selected entry.
edThe editor to operate in.

Definition at line 1014 of file cbplugin.cpp.

◆ GetAutocompList()

virtual std::vector<CCToken> cbCodeCompletionPlugin::GetAutocompList ( bool  isAuto,
cbEditor ed,
int &  tknStart,
int &  tknEnd 
)
pure virtual

Supply content for the autocompletion list.

CCManager takes care of calling this during most relevant situations. If the autocompletion mechanism is required at a time that CCManager does not initiate, call

In this case, the parameter isAuto is passed as false value.

Here is an example

#include <math.h>
int main()
{
float i = cos|------auto completion here
^ ^
}

This is the case the user has just enter the chars "cos", now to get a suggestion list. The first '^' is the position of tknStart, and the second '^' is the position of tknEnd In this case, the cc plugin would supply a CCToken vectors, which could contains "cos", "cosh" and "cosh"... In some special cases, the tknStart tknEnd may point to the same position, such as

struct AAA { int m_aaa1; };
int main()
{
AAA obj;
obj.|------auto completion here
^
}

Here, '^' are the positions of both tknStart and tknEnd.

Parameters
isAutoPassed as true if autocompletion was launched by typing an 'interesting' character such as '>' (for '->'). It is the plugin's job to filter out incorrect calls of this.
edThe context of this codecompletion call.
[in,out]tknStartThe assumed beginning of the token to be autocompleted. Change this variable if the plugin calculates a different starting location.
[in,out]tknEndThe current position/end of the known part of the token to be completed. The plugin is allowed to change this (but it is not recommended).
Returns
Completable tokens, or empty vector to cancel autocompletion.

Implemented in CodeCompletion.

Referenced by CCManager::OnCompleteCode().

◆ GetCallTips()

virtual std::vector<CCCallTip> cbCodeCompletionPlugin::GetCallTips ( int  pos,
int  style,
cbEditor ed,
int &  argsPos 
)
pure virtual

Supply content for the calltip at the specified location.

The output parameter argsPos is required to be set to the same (but unique) position for each unique calltip. This position is the location corresponding to the beginning of the argument list:

int endOfWord = stc->WordEndPosition(pos, true);
^

Each returned CCCallTip is allowed to have embedded '\n' line breaks.

Parameters
posThe location in the editor that the calltip is requested for.
styleThe scintilla style of the cbStyledTextCtrl at the given location. (TODO: This is unusual, remove it?)
edThe context of this calltip request.
[out]argsPosThe location in the editor of the beginning of the argument list. Required.
Returns
Each entry in this vector is guaranteed either a new line or a separate page in the calltip. CCManager will decide if lines should be further split (for formatting to fit the monitor).

Implemented in CodeCompletion.

Referenced by CCManager::OnEditorTooltip(), and CCManager::OnShowCallTip().

◆ GetDocumentation()

virtual wxString cbCodeCompletionPlugin::GetDocumentation ( const CCToken token)
pure virtual

Supply html formatted documentation for the passed token.

Refer to http://docs.wxwidgets.org/stable/overview_html.html#overview_html_supptags for the available formatting. When selecting colours, prefer use of the ones CCManager has registered with ColourManager, which are (TODO: register colours). Returning an empty string will cancel the documentation popup.

Parameters
tokenThe token to document.
Returns
Either an html document or an empty string (if no documentation available).

Implemented in CodeCompletion.

Referenced by CCManager::DoShowDocumentation().

◆ GetProviderStatusFor()

virtual CCProviderStatus cbCodeCompletionPlugin::GetProviderStatusFor ( cbEditor ed)
pure virtual

Does this plugin handle code completion for the editor ed?

The plugin should check the lexer, the HighlightLanguage, the file extension, or some combination of these. Do not call CCManager::GetProviderFor() from this function.

Parameters
edThe editor being checked.
Returns
The level of functionality this plugin is able to supply.

Implemented in CodeCompletion.

◆ GetTokenAt()

virtual std::vector<CCToken> cbCodeCompletionPlugin::GetTokenAt ( int  pos,
cbEditor ed,
bool &  allowCallTip 
)
pure virtual

Supply the definition of the token at the specified location.

The token(s) returned by this function are used to display tooltips.

Parameters
posThe location being queried.
edThe context of the request.
[out]allowCallTipAllow CCManager to consider displaying a calltip if the results from this function are unsuitable/empty. True by default.
Returns
A list of the token(s) that match the specified location, an empty vector if none.

Implemented in CodeCompletion.

Referenced by CCManager::OnEditorTooltip().

◆ IsProviderFor()

bool cbCodeCompletionPlugin::IsProviderFor ( cbEditor ed)
protected

Has this plugin been selected to provide content for the editor.

Convenience function; asks CCManager if this plugin is granted jurisdiction over the editor.

Parameters
edThe editor to check.
Returns
Is provider for the editor.

Definition at line 1019 of file cbplugin.cpp.

References Manager::Get().

◆ OnDocumentationLink()

virtual wxString cbCodeCompletionPlugin::OnDocumentationLink ( wxHtmlLinkEvent &  event,
bool &  dismissPopup 
)
pure virtual

Callback to handle a click on a link in the documentation popup.

Handle a link command by, for example, showing the definition of a member function, or opening an editor to the location of the declaration.

Parameters
eventThe generated event (it is the plugin's responsibility to Skip(), if desired).
[out]dismissPopupIf set to true, the popup will be hidden.
Returns
If non-empty, the popup's content will be set to this html formatted string.

Implemented in CodeCompletion.

Referenced by CCManager::OnHtmlLink().


The documentation for this class was generated from the following files: