Page 1 of 1

ContextCpp questions

Posted: Mon Nov 07, 2011 11:59 pm
by jfouche
Due to this problem, I need some clues about the ContextCpp class.

1 : What is the exact goal of the ContextCpp::GetExpression method ? Most of the time, it returns an empty string. And reading the code source, I don't understand what is the expected output regarding the caret position.
2 : What is the expression used for ?

Thanks

Re: ContextCpp questions

Posted: Tue Nov 08, 2011 10:34 am
by eranif
jfouche wrote:: What is the exact goal of the ContextCpp::GetExpression method ? Most of the time, it returns an empty string. And reading the code source, I don't understand what is the expected output regarding the caret position.
There are 2 main functions that being used for code-completion (and all other related functionalities, like 'goto declaration' etc):

Code: Select all

bool TagsManager::AutoCompleteCandidates(const wxFileName &fileName, int lineno, const wxString& expr, const wxString& text, std::vector<TagEntryPtr>& candidates)
bool TagsManager::WordCompletionCandidates(const wxFileName &fileName, int lineno, const wxString& expr, const wxString& text, const wxString &word, std::vector<TagEntryPtr> &candidates)
Both of this functions accept 'expr' as the third argument. An example would make it clear:

Assuming this code snippet:

Code: Select all

wxString str;
str.BeforeFirst(wxT('/')).B| // the | represents the caret current position
If you hit 'Ctrl-SPACE' at the caret position the expression is set to: 'str.BeforeFirst(wxT('/')).B'
The function 'ContextCpp::GetExpression' is responsible for extracting it from the editor and passing it 'TagsManager'

Just place a breakpoint at one of the two functions above (TagsManager::AutoCompleteCandidates & TagsManager::WordCompletionCandidates) and see the value of 'expr'

You could take a look at the 'CodeCompletionTests' workspace to see a simplified version of how these two methods are being used

Eran