Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions PythonCodeCompletion/PythonCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ END_EVENT_TABLE()
// constructor
PythonCodeCompletion::PythonCodeCompletion() : m_ActiveCalltipDef(_(""))
{
m_comp_position.line = 0;
m_comp_position.column = 0;
// Make sure our resources are available.
// In the generated boilerplate code we have no resources but when
// we add some, it will be nice that this code is in place already ;)
Expand Down Expand Up @@ -318,9 +320,29 @@ PythonCodeCompletion::CCProviderStatus PythonCodeCompletion::GetProviderStatusFo
std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd)
{
Manager::Get()->GetLogManager()->DebugLog(_("PYCC: GetAutocompList called"));

cbStyledTextCtrl* control = ed->GetControl();
const int line = control->LineFromPosition(tknStart);
const int lnStart = control->PositionFromLine(line);
int column = tknStart - lnStart;
for (; column > 0; --column)
{
if ( !wxIsspace(control->GetCharAt(lnStart + column - 1))
|| (column != 1 && !wxIsspace(control->GetCharAt(lnStart + column - 2))) )
{
break;
}
}

std::vector<CCToken> tokens;
if (m_state == STATE_COMPLETION_RETURNED)
{
if ((m_comp_position.line != line)||(m_comp_position.column != column))
{
Manager::Get()->GetLogManager()->DebugLog( _("PYCC: Position has changed since last CC request") );
m_state=STATE_NONE;
return tokens;
}
for (int i = 0; i<m_comp_results.Count(); ++i)
{
long int category=-1;
Expand All @@ -329,7 +351,6 @@ std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList
PythonCodeCompletion::CCToken t(i,m_comp_results[i].BeforeFirst('?'),category);
tokens.push_back(t);
}
cbStyledTextCtrl* control = ed->GetControl();
control->ClearRegisteredImages();
for (int i = 0; i < m_pImageList->GetImageCount(); i++)
control->RegisterImage(i+1,m_pImageList->GetBitmap(i));
Expand All @@ -341,7 +362,6 @@ std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList
// if ( (!ed->AutoCompActive()) // not already active autocompletion
// || (ch == _T('.')))
Manager::Get()->GetLogManager()->DebugLog(_("PYCC: Checking lexical state..."));
cbStyledTextCtrl *control=ed->GetControl();
int pos = tknEnd;
int style = control->GetStyleAt(pos);
wxChar ch = control->GetCharAt(pos);
Expand All @@ -357,6 +377,8 @@ std::vector<PythonCodeCompletion::CCToken> PythonCodeCompletion::GetAutocompList
wxString phrase=control->GetTextRange(tknStart,tknEnd);
Manager::Get()->GetLogManager()->DebugLog(_T("PYCC: Looking for ")+phrase+_T(" in ")+ed->GetFilename()+wxString::Format(_T(" %i"),pos));
m_state = STATE_COMPLETION_REQUEST;
m_comp_position.line = line;
m_comp_position.column = column;
RequestCompletion(control,pos,ed->GetFilename());
return tokens;
}
Expand Down
5 changes: 4 additions & 1 deletion PythonCodeCompletion/PythonCodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ class PythonCodeCompletion : public cbCodeCompletionPlugin
wxImageList* m_pImageList; //Type icons displayed in the code completion popup
CCCallTip m_ActiveCalltipDef; //contains the call tip definition retrieved from the server
wxArrayString m_comp_results; //contains an array of completion results retrieved from the server

struct {
int line;
int column;
} m_comp_position;
DECLARE_EVENT_TABLE();
};

Expand Down