Skip to content

Commit

Permalink
Fixed: there is a noticable lag when typing while the function argume…
Browse files Browse the repository at this point in the history
…nt tooltip is shown

Fixed: when the function arguments tip window shows, skip the first argument if it is "self" (e.g. for class method in Python or Rust)
  • Loading branch information
eranif committed Apr 7, 2024
1 parent c16722e commit 0655eb2
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 181 deletions.
127 changes: 66 additions & 61 deletions CodeLite/cl_calltip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ clCallTip::clCallTip(const clCallTip& rhs) { *this = rhs; }

clCallTip& clCallTip::operator=(const clCallTip& rhs)
{
if(this == &rhs)
if (this == &rhs)
return *this;
m_tips = rhs.m_tips;
m_curr = rhs.m_curr;
Expand All @@ -67,15 +67,15 @@ thread_local wxString empty_tip;
wxString clCallTip::First()
{
m_curr = 0;
if(m_tips.empty())
if (m_tips.empty())
return wxEmptyString;
return TipAt(0);
}

wxString clCallTip::TipAt(int at)
{
wxString tip;
if(m_tips.size() > 1) {
if (m_tips.size() > 1) {
tip << m_tips.at(at).str;
} else {
tip << m_tips.at(0).str;
Expand All @@ -86,11 +86,11 @@ wxString clCallTip::TipAt(int at)
wxString clCallTip::Next()
{
// format a tip string and return it
if(m_tips.empty())
if (m_tips.empty())
return wxEmptyString;

m_curr++;
if(m_curr >= (int)m_tips.size()) {
if (m_curr >= (int)m_tips.size()) {
m_curr = 0;
} // if( m_curr >= m_tips.size() )

Expand All @@ -100,11 +100,11 @@ wxString clCallTip::Next()
wxString clCallTip::Prev()
{
// format a tip string and return it
if(m_tips.empty())
if (m_tips.empty())
return wxEmptyString;

m_curr--;
if(m_curr < 0) {
if (m_curr < 0) {
m_curr = (int)m_tips.size() - 1;
}
return TipAt(m_curr);
Expand All @@ -113,7 +113,7 @@ wxString clCallTip::Prev()
wxString clCallTip::All()
{
wxString tip;
for(size_t i = 0; i < m_tips.size(); i++) {
for (size_t i = 0; i < m_tips.size(); i++) {
tip << m_tips.at(i).str << wxT("\n");
}
tip.RemoveLast();
Expand All @@ -124,29 +124,13 @@ int clCallTip::Count() const { return (int)m_tips.size(); }

void clCallTip::Initialize(const std::vector<TagEntryPtr>& tags) { FormatTagsToTips(tags, m_tips); }

void clCallTip::GetHighlightPos(int index, int& start, int& len)
{
start = wxNOT_FOUND;
len = wxNOT_FOUND;
if(m_curr >= 0 && m_curr < (int)m_tips.size()) {
clTipInfo ti = m_tips.at(m_curr);
int base = ti.str.Find(wxT("("));

// sanity
if(base != wxNOT_FOUND && index < (int)ti.paramLen.size() && index >= 0) {
start = ti.paramLen.at(index).first + base;
len = ti.paramLen.at(index).second;
}
}
}

wxString clCallTip::Current()
{
// format a tip string and return it
if(m_tips.empty())
if (m_tips.empty())
return wxEmptyString;

if(m_curr >= (int)m_tips.size() || m_curr < 0) {
if (m_curr >= (int)m_tips.size() || m_curr < 0) {
m_curr = 0;
}
return TipAt(m_curr);
Expand All @@ -155,8 +139,8 @@ wxString clCallTip::Current()
void clCallTip::SelectSiganture(const wxString& signature)
{
// search for a match
for(size_t i = 0; i < m_tips.size(); ++i) {
if(m_tips.at(i).str == signature) {
for (size_t i = 0; i < m_tips.size(); ++i) {
if (m_tips.at(i).str == signature) {
m_curr = i;
break;
}
Expand All @@ -166,51 +150,68 @@ void clCallTip::SelectSiganture(const wxString& signature)
void clCallTip::FormatTagsToTips(const TagEntryPtrVector_t& tags, std::vector<clTipInfo>& tips)
{
std::map<wxString, tagCallTipInfo> mymap;
for(size_t i = 0; i < tags.size(); i++) {
for (size_t i = 0; i < tags.size(); i++) {
tagCallTipInfo cti;
TagEntryPtr t = tags.at(i);

// Use basic signature
if(t->GetFlags() & TagEntry::Tag_No_Signature_Format) {
if (t->GetFlags() & TagEntry::Tag_No_Signature_Format) {

wxString raw_sig = t->GetSignature();
int startOffset(0);
if(raw_sig.Find(wxT("(")) != wxNOT_FOUND) {
if (raw_sig.Find(wxT("(")) != wxNOT_FOUND) {
startOffset = raw_sig.Find(wxT("(")) + 1;
}

// Remove the open / close brace
wxString tmpsig = raw_sig;
tmpsig.Trim().Trim(false); // remove any whitespaces from right

size_t j = 0;
size_t depth = -1; // we start collecting after we find the open paren
for(; j < tmpsig.length(); ++j) {
if(tmpsig.at(j) == '(') {
++depth;
} else if(tmpsig.at(j) == ')') {
--depth;
} else if(tmpsig.GetChar(j) == wxT(',') && (depth == 0)) {
std::pair<int, int> p;
p.first = startOffset;
p.second = (j - startOffset);
cti.paramLen.push_back(p);
startOffset = j + 1;
tmpsig.Trim().Trim(false);

wxString curtoken;
size_t j = startOffset;
size_t depth = 0;
for (; j < tmpsig.length(); ++j) {
wxChar ch = tmpsig[j];
switch (ch) {
case '(':
case '{':
case '[':
depth++;
break;
case ')':
case '}':
case ']':
depth--;
break;
case ',':
// skip Rust and Python "self" as first argument
if (depth == 0) {
curtoken.Trim().Trim(false);
if (curtoken == "mut self" || curtoken == "&mut self" || curtoken == "self" ||
curtoken == "&self") {
// skip it
} else {
cti.paramLen.push_back({ startOffset, j - startOffset });
}
startOffset = j + 1;
curtoken.clear();
}
break;
default:
curtoken << ch;
break;
}
}

if(startOffset != (int)j) {
std::pair<int, int> p;
p.first = startOffset;
p.second = (j - startOffset -
1); // -1 here since its likely that the signature ends with a ")" so don't include it
cti.paramLen.push_back(p);
if (startOffset != (int)j) {
// -1 here since its likely that the signature ends with a ")" so don't include it
cti.paramLen.push_back({ startOffset, j - startOffset - 1 });
}
cti.sig = raw_sig;
mymap[raw_sig] = cti;

} else {
if(t->IsMethod()) {
if (t->IsMethod()) {

wxString raw_sig(t->GetSignature().Trim().Trim(false));

Expand All @@ -230,14 +231,14 @@ void clCallTip::FormatTagsToTips(const TagEntryPtrVector_t& tags, std::vector<cl
raw_sig, Normalize_Func_Name | Normalize_Func_Default_value, &cti.paramLen);
cti.sig = full_signature;

if(hasDefaultValues) {
if (hasDefaultValues) {
// incase default values exist in this prototype,
// update/insert this signature
mymap[key] = cti;
}

// make sure we dont add duplicates
if(mymap.find(key) == mymap.end()) {
if (mymap.find(key) == mymap.end()) {
// add it
mymap[key] = cti;
}
Expand All @@ -248,11 +249,11 @@ void clCallTip::FormatTagsToTips(const TagEntryPtrVector_t& tags, std::vector<cl
wxString pattern = t->GetPattern();

int where = pattern.Find(macroName);
if(where != wxNOT_FOUND) {
if (where != wxNOT_FOUND) {
// remove the #define <name> from the pattern
pattern = pattern.Mid(where + macroName.Length());
pattern = pattern.Trim().Trim(false);
if(pattern.StartsWith(wxT("("))) {
if (pattern.StartsWith(wxT("("))) {
// this macro has the form of a function
pattern = pattern.BeforeFirst(wxT(')'));
pattern.Append(wxT(')'));
Expand All @@ -266,10 +267,14 @@ void clCallTip::FormatTagsToTips(const TagEntryPtrVector_t& tags, std::vector<cl

std::map<wxString, tagCallTipInfo>::iterator iter = mymap.begin();
tips.clear();
for(; iter != mymap.end(); iter++) {
for (; iter != mymap.end(); iter++) {
wxString tip;
tip << iter->second.sig;
if(iter->second.retValue.empty() == false) {

// Rust & Php have "self" or other variant of it in the argument
// list, so lets filter it
tip.Trim().Trim(false);
if (iter->second.retValue.empty() == false) {
tip << " -> " << iter->second.retValue.Trim(false).Trim();
}

Expand All @@ -282,8 +287,8 @@ void clCallTip::FormatTagsToTips(const TagEntryPtrVector_t& tags, std::vector<cl

bool clCallTip::SelectTipToMatchArgCount(size_t argcount)
{
for(size_t i = 0; i < m_tips.size(); ++i) {
if(m_tips.at(i).paramLen.size() > argcount) {
for (size_t i = 0; i < m_tips.size(); ++i) {
if (m_tips.at(i).paramLen.size() > argcount) {
m_curr = i;
return true;
}
Expand Down
8 changes: 0 additions & 8 deletions CodeLite/cl_calltip.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ class WXDLLIMPEXP_CL clCallTip
*/
wxString All();

/**
* @brief get the highlight offset & width for the current tip
* @param index paramter index
* @param start [output]
* @param len [output]
*/
void GetHighlightPos(int index, int& start, int& len);

int GetCurr() const { return m_curr; }

/**
Expand Down
32 changes: 16 additions & 16 deletions LiteEditor/ContextRust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include "cl_editor_tip_window.h"
#include "editor_config.h"

#include <wx/xrc/xmlres.h>
#include <unordered_set>
#include <wx/xrc/xmlres.h>

ContextRust::ContextRust(clEditor* editor)
: ContextGeneric(editor, "rust")
Expand All @@ -54,7 +54,7 @@ ContextRust::ContextRust()

ContextRust::~ContextRust()
{
if(m_eventsBound) {
if (m_eventsBound) {
Unbind(wxEVT_MENU, &ContextRust::OnCommentSelection, this, XRCID("comment_selection"));
Unbind(wxEVT_MENU, &ContextRust::OnCommentLine, this, XRCID("comment_line"));
}
Expand All @@ -66,13 +66,13 @@ void ContextRust::ApplySettings()
{
SetName(wxT("rust"));
LexerConf::Ptr_t lexPtr;
if(EditorConfigST::Get()->IsOk()) {
if (EditorConfigST::Get()->IsOk()) {
lexPtr = EditorConfigST::Get()->GetLexer(GetName());
}
clEditor& rCtrl = GetCtrl();
if(lexPtr) {
if (lexPtr) {
rCtrl.SetLexer(lexPtr->GetLexerId());
for(int i = 0; i <= 4; ++i) {
for (int i = 0; i <= 4; ++i) {
wxString keyWords = lexPtr->GetKeyWords(i);
keyWords.Replace(wxT("\n"), wxT(" "));
keyWords.Replace(wxT("\r"), wxT(" "));
Expand Down Expand Up @@ -129,13 +129,7 @@ void ContextRust::OnFileSaved() {}

void ContextRust::OnKeyDown(wxKeyEvent& event) { event.Skip(); }

void ContextRust::OnSciUpdateUI(wxStyledTextEvent& event)
{
clEditor& ctrl = GetCtrl();
if(ctrl.GetFunctionTip()->IsActive()) {
ctrl.GetFunctionTip()->Highlight(DoGetCalltipParamterIndex());
}
}
void ContextRust::OnSciUpdateUI(wxStyledTextEvent& event) { wxUnusedVar(event); }

void ContextRust::RemoveMenuDynamicContent(wxMenu* menu) {}

Expand All @@ -146,15 +140,15 @@ void ContextRust::SemicolonShift()
int foundPos(wxNOT_FOUND);
int semiColonPos(wxNOT_FOUND);
clEditor& ctrl = GetCtrl();
if(ctrl.NextChar(ctrl.GetCurrentPos(), semiColonPos) == wxT(')')) {
if (ctrl.NextChar(ctrl.GetCurrentPos(), semiColonPos) == wxT(')')) {

// test to see if we are inside a 'for' statement
long openBracePos(wxNOT_FOUND);
int posWordBeforeOpenBrace(wxNOT_FOUND);

if(ctrl.MatchBraceBack(wxT(')'), semiColonPos, openBracePos)) {
if (ctrl.MatchBraceBack(wxT(')'), semiColonPos, openBracePos)) {
ctrl.PreviousChar(openBracePos, posWordBeforeOpenBrace);
if(posWordBeforeOpenBrace != wxNOT_FOUND) {
if (posWordBeforeOpenBrace != wxNOT_FOUND) {
wxString word = ctrl.PreviousWord(posWordBeforeOpenBrace, foundPos);

// At the current pos, we got a ';'
Expand Down Expand Up @@ -203,7 +197,13 @@ bool ContextRust::IsStringTriggerCodeComplete(const wxString& str) const
return (m_completionTriggerStrings.count(str) > 0);
}

void ContextRust::ProcessIdleActions() { ContextGeneric::ProcessIdleActions(); }
void ContextRust::ProcessIdleActions()
{
clEditor& ctrl = GetCtrl();
if (ctrl.GetFunctionTip()->IsActive()) {
ctrl.GetFunctionTip()->Highlight(DoGetCalltipParamterIndex());
}
}

void ContextRust::OnCommentSelection(wxCommandEvent& event)
{
Expand Down
3 changes: 2 additions & 1 deletion LiteEditor/cl_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5689,7 +5689,6 @@ void clEditor::OnTimer(wxTimerEvent& event)
}
}
}
GetContext()->ProcessIdleActions();
}

void clEditor::SplitSelection()
Expand Down Expand Up @@ -6597,6 +6596,8 @@ void clEditor::OnIdle(wxIdleEvent& event)

// Always update the status bar with event, calling it directly causes performance degredation
m_mgr->GetStatusBar()->SetLinePosColumn(message);

GetContext()->ProcessIdleActions();
}

void clEditor::ClearModifiedLines()
Expand Down
Loading

0 comments on commit 0655eb2

Please sign in to comment.