Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
CC plugin interface redesign
dmoore:
Seriously don't know why you guys love git/github so much. Just needlessly built the master branch :-[ Thought I had "git clone"d the cc branch by switching from master to cc branch in the github interface and copying the clone link, only to learn that I needed to "git checkout cc_interface" because clone grabs everything. :'( Anyway, building it now and will figure out how to get python stuff working in the next week or so.
dmoore:
Qs:
1. Am I understanding correctly that the framework now handles the completion, calltip and doc popups, and the plugin just needs to provide data?
2. It looks like the framework expects the plugin to decide whether the caret is in the appropriate place (e.g. don't want to show popups in a comment line) and then immediately return the tokens. Is that right? The current version of the python plugin does the caret check then makes an asynchronous request to a remote python process for the CC tokens because we don't want to cause a potentially long freeze in the editor. How do I handle this case? EDIT: Maybe initially return nothing, but make the async call and then when it returns send a cbEVT_COMPLETE_CODE event to re-call the handler? Can the same be done for Doc strings?
3. What is the plugin supposed to do in the DoAutoComplete functions and why are there two? (CC plugin appears to place text for the selected token into the editor and do any needed reparsing/formatting/showing additional calls tips? Shouldn't there be a default implementation that just does what Scintilla does by default??)
4. Is there any delay before showing a popup or is this up to the plugin to implement? (e.g. if user is typing fast don't show a popup until they slow down.)
EDIT: 5. What is GetTokenAt for?
Alpha:
--- Quote from: dmoore on October 30, 2013, 04:51:53 am ---Seriously don't know why you guys love git/github so much. Just needlessly built the master branch :-[ Thought I had "git clone"d the cc branch by switching from master to cc branch in the github interface and copying the clone link, only to learn that I needed to "git checkout cc_interface" because clone grabs everything. :'(
--- End quote ---
Sorry, that might be partially my fault (this is my first time with git). I think I may have unnecessarily created a master branch in my fork.
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---1. Am I understanding correctly that the framework now handles the completion, calltip and doc popups, and the plugin just needs to provide data?
--- End quote ---
That is how I am intending it to work. Your plugin can also send cbEVT_SHOW_CALL_TIP, cbEVT_EDITOR_TOOLTIP and cbEVT_COMPLETE_CODE events for specialized situations (that the (hopefully more generic) CCManager does not handle).
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---2. It looks like the framework expects the plugin to decide whether the caret is in the appropriate place (e.g. don't want to show popups in a comment line) and then immediately return the tokens. Is that right? The current version of the python plugin does the caret check then makes an asynchronous request to a remote python process for the CC tokens because we don't want to cause a potentially long freeze in the editor. How do I handle this case? EDIT: Maybe initially return nothing, but make the async call and then when it returns send a cbEVT_COMPLETE_CODE event to re-call the handler?
--- End quote ---
Yes. Returning an empty vector will cancel code completion, and sending the event (once your plugin is prepared) will start it up again. (Although, you may consider first testing to see if it creates a noticeable lag when done synchronously.)
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---Can the same be done for Doc strings?
--- End quote ---
Not with the current API. However, CCManager tries to only request documentation be generated when the user pauses in scrolling through options, so a short freeze here is unlikely to be noticed (at least, that is the theory).
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---3. What is the plugin supposed to do in the DoAutoComplete functions and why are there two? (CC plugin appears to place text for the selected token into the editor and do any needed reparsing/formatting/showing additional calls tips?
--- End quote ---
The function DoAutocomplete(const wxString& token, cbEditor* ed) technically never will be called, however I added it to the code because I cannot guarantee that. It will only be called if, for some unknown reason, CCManager is unable to return the CCToken equivalent that was selected.
Its purpose is to give the plugin a chance to insert/replace the token into the editor in a more advanced way than simply inserting (for example, also adding argument lists).
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---Shouldn't there be a default implementation that just does what Scintilla does by default??)
--- End quote ---
Probably. The default implementation would be:
--- Code: ---void cbCodeCompletionPlugin::DoAutocomplete(const CCToken& /*token*/, cbEditor* /*ed*/)
{
return;
}
--- End code ---
As long as you do not call ed->GetControl()->AutoCompCancel() in this function, default autocomplete action will occur.
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---4. Is there any delay before showing a popup or is this up to the plugin to implement? (e.g. if user is typing fast don't show a popup until they slow down.)
--- End quote ---
I intend CCManager to handle that (however, it is currently hardcoded at 10ms, and synchronous if the user types three characters in a row).
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---EDIT: 5. What is GetTokenAt for?
--- End quote ---
I think I will need to rename that; it is currently called to supply tooltips when the user hovers the mouse over a token.
dmoore:
--- Quote from: Alpha on October 30, 2013, 03:07:40 pm ---Sorry, that might be partially my fault (this is my first time with git). I think I may have unnecessarily created a master branch in my fork.
--- End quote ---
No I blame them not you. Makes sense to be able to have multiple branches. But when you git clone something it would be friendlier to noobs like me that git should give a hint that you are getting multiple branches and what the default one will be. Maybe it did and I just didn't see it, but git and its output is pretty hard for mere mortals to parse in general. I was more surprised that github's interface doesn't make it clearer how to clone a specific branch.
--- Quote ---That is how I am intending it to work. Your plugin can also send cbEVT_SHOW_CALL_TIP, cbEVT_EDITOR_TOOLTIP and cbEVT_COMPLETE_CODE events for specialized situations (that the (hopefully more generic) CCManager does not handle).
--- End quote ---
So when a user types:
* alphanumerics (e.g. say, "im"), the framework is going to call the plugin's GetAutocompList?
* "(" or ",", the framework will call GetCallTips?
Or is it really up to the plugin to hook into the editor events and post the messages you listed above. I'm wondering how one is supposed to handle the calltip with highlighting of the relevant function arg.
I think I saw some places where there is code that looks like "stc->CallTipShow" / "stc->CallTipHide". I would have expected members to handle these sorts of actions to be part of the plugin or CCManager class.
--- Quote ---Yes. Returning an empty vector will cancel code completion, and sending the event (once your plugin is prepared) will start it up again. (Although, you may consider first testing to see if it creates a noticeable lag when done synchronously.)
--- End quote ---
There will definitely be situations where there is noticeable lag. In one case it took >30s to get gtk's symbols :o. That's kind of an extreme case but I expect up to 1s delays to be pretty common, which rules out blocking approaches.
--- Quote ---Not with the current API. However, CCManager tries to only request documentation be generated when the user pauses in scrolling through options, so a short freeze here is unlikely to be noticed (at least, that is the theory).
--- End quote ---
This is probably a case where blocking until the asynch call returns would probably have acceptable delays, since the token list should (usually??) have already been generated.
--- Quote ---I intend CCManager to handle that (however, it is currently hardcoded at 10ms, and synchronous if the user types three characters in a row).
--- End quote ---
That works for me.
--- Quote ---
--- Quote from: dmoore on October 30, 2013, 05:30:08 am ---EDIT: 5. What is GetTokenAt for?
--- End quote ---
I think I will need to rename that; it is currently called to supply tooltips when the user hovers the mouse over a token.
--- End quote ---
GetTooltipForTokenAt?
One more Q... How does one set the icon used in the CC popup. Is that the "id"?
Alpha:
--- Quote from: dmoore on October 31, 2013, 07:22:28 pm ---So when a user types:
* alphanumerics (e.g. say, "im"), the framework is going to call the plugin's GetAutocompList?
* "(" or ",", the framework will call GetCallTips?
--- End quote ---
Yes and yes. (Details on word length and key characters are still hardcoded.)
--- Quote from: dmoore on October 31, 2013, 07:22:28 pm ---Or is it really up to the plugin to hook into the editor events and post the messages you listed above. I'm wondering how one is supposed to handle the calltip with highlighting of the relevant function arg.
--- End quote ---
CCManager calls GetCallTips() whenever one of m_CallTipChars (currently hardcoded) is typed and when the user presses navigation (up/down/left/right) keys (buffered delay), so the relevant argument *should* always be highlighted.
The only time I found it necessary for the CC plugin to send cbEVT_SHOW_CALL_TIP was in DoAutocomplete() when the token is a function.
--- Quote from: dmoore on October 31, 2013, 07:22:28 pm ---I think I saw some places where there is code that looks like "stc->CallTipShow" / "stc->CallTipHide". I would have expected members to handle these sorts of actions to be part of the plugin or CCManager class.
--- End quote ---
I do not think I understand... example please?
--- Quote from: dmoore on October 31, 2013, 07:22:28 pm ---There will definitely be situations where there is noticeable lag. In one case it took >30s to get gtk's symbols :o. That's kind of an extreme case but I expect up to 1s delays to be pretty common, which rules out blocking approaches.
--- End quote ---
You are right; do not block here. (I think it should be the plugin's job, and not CCManager, to send an event when it is ready.)
(+1 for Code::Blocks CC devs, the search tree is quite fast.)
--- Quote from: dmoore on October 31, 2013, 07:22:28 pm ---One more Q... How does one set the icon used in the CC popup. Is that the "id"?
--- End quote ---
--- Code: --- const wxString idxStr = F(wxT("\n%d"), PARSER_IMG_PREPROCESSOR);
for (size_t i = 0; i < macros.size(); ++i)
{
if (text.IsEmpty() || macros[i][0] == text[0]) // ignore tokens that start with a different letter
tokens.push_back(CCToken(wxNOT_FOUND, macros[i] + idxStr));
}
stc->ClearRegisteredImages();
stc->RegisterImage(PARSER_IMG_PREPROCESSOR,
m_NativeParser.GetImageList()->GetBitmap(PARSER_IMG_PREPROCESSOR));
--- End code ---
Currently poor API for this (change is planned). You must append the string "\n" + xyzNumber to the token's name.
id - unused by CCManager, passed back to the plugin so that the plugin can use it internally to know which token it represents
displayName - verbose text representation of token
name - minimal text representation of token (not currently used, but in place so that CCManager can change between verbose and minimal tooltip/autocomplete modes)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version