Skip to content

Commit ec7a93f

Browse files
committed
CodeChecker: removed most log messages, implemented message display as a calltip that displays when hovering over line of error message (todo: make into a tooltip that displays when hovering over the error marker)
1 parent c49c993 commit ec7a93f

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

codecheck/codechecker.cpp

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ void CodeChecker::OnAttach()
5050
{
5151
Manager::Get()->RegisterEventSink(cbEVT_EDITOR_SAVE, new cbEventFunctor<CodeChecker, CodeBlocksEvent>(this, &CodeChecker::OnAnalyze));
5252
Manager::Get()->RegisterEventSink(cbEVT_EDITOR_OPEN, new cbEventFunctor<CodeChecker, CodeBlocksEvent>(this, &CodeChecker::OnAnalyze));
53+
Manager::Get()->RegisterEventSink(cbEVT_EDITOR_TOOLTIP, new cbEventFunctor<CodeChecker, CodeBlocksEvent>(this, &CodeChecker::OnTooltip));
5354
m_process=new AsyncProcess(this);
5455

5556
LangData ld1,ld2;
5657
ld1.command=_T("python -m py_compile $file");
57-
ld1.regexp=_T("File \"([^\\n]+)\", line (\\d+)\n");
58+
ld1.regexp=_T("File \"([^\\n]+)\", line (\\d+)\\n(.*)");
5859
m_commands[wxSCI_LEX_PYTHON]=ld1;
5960

6061
ld2.command=_T("php -I $file");
@@ -78,19 +79,37 @@ void CodeChecker::OnRelease(bool appShutDown)
7879
}
7980

8081
//TODO: Tooltips for error messages
81-
// pm->RegisterEventSink(cbEVT_EDITOR_TOOLTIP, new cbEventFunctor<CodeCompletion, CodeBlocksEvent>(this, &CodeCompletion::OnValueTooltip));
82-
//void CodeCompletion::OnValueTooltip(CodeBlocksEvent& event)
83-
//{
84-
// if (ed->GetControl()->CallTipActive())
85-
// ed->GetControl()->CallTipCancel();
86-
//// Manager::Get()->GetLogManager()->DebugLog(F(_T("CodeCompletion::OnValueTooltip: %p"), ed));
87-
// /* NOTE: The following 2 lines of codes can fix [Bug #11785].
88-
// * The solution may not the best one and it requires the editor
89-
// * to have the focus (even if C::B has the focus) in order to pop-up the tooltip. */
90-
// if (wxWindow::FindFocus() != static_cast<wxWindow*>(ed->GetControl()))
91-
// return;
92-
// ed->GetControl()->CallTipShow(pos, msg);
93-
//}
82+
void CodeChecker::OnTooltip(CodeBlocksEvent& e)
83+
{
84+
EditorBase *edb=e.GetEditor();
85+
if(!edb->IsBuiltinEditor())
86+
return;
87+
cbEditor *ed=(cbEditor *)edb;
88+
int lexer=ed->GetControl()->GetLexer();
89+
if(m_commands.find(lexer)==m_commands.end())
90+
return;
91+
/* NOTE: The following 2 lines of codes can fix [Bug #11785].
92+
* The solution may not the best one and it requires the editor
93+
* to have the focus (even if C::B has the focus) in order to pop-up the tooltip. */
94+
if (wxWindow::FindFocus() != static_cast<wxWindow*>(ed->GetControl()))
95+
return;
96+
int pos = ed->GetControl()->PositionFromPointClose(e.GetX(), e.GetY());
97+
if(pos==wxSCI_INVALID_POSITION)
98+
return;
99+
int line = ed->GetControl()->LineFromPosition(pos);
100+
if(m_issues.find(ed->GetFilename())==m_issues.end())
101+
return;
102+
CodeIssues &ci=m_issues[ed->GetFilename()];
103+
for(CodeIssues::iterator it=ci.begin();it!=ci.end();++it)
104+
if(line==it->line)
105+
{
106+
if (ed->GetControl()->CallTipActive())
107+
ed->GetControl()->CallTipCancel();
108+
LogMessage(wxString::Format(_("Tooltip dear: X - %i, Y - %i, pos - %i"),e.GetX(),e.GetY(),pos));
109+
wxString msg=it->msg;//_T("Goodnight Dear");
110+
ed->GetControl()->CallTipShow(pos, msg);
111+
}
112+
}
94113

95114

96115

@@ -123,17 +142,17 @@ void CodeChecker::OnProcessTerminate(wxProcessEvent &e)
123142
{
124143
CodeIssue ci;
125144
ci.line=linenum-1;
126-
ci.msg=_T("");
145+
ci.msg=re.GetMatch(data,ld.regexp_indmsg);//_T("");
127146
m_issues[file].push_back(ci);
128147
}
129148
size_t start,end;
130149
re.GetMatch(&start,&end,0);
131150
data=data.Mid(end);
132151
}
133152

134-
LogMessage(_("Syntax Check Results"));
135-
LogMessage(out);
136-
LogMessage(err);
153+
// LogMessage(_("Syntax Check Results"));
154+
// LogMessage(out);
155+
// LogMessage(err);
137156
EditorManager* em = Manager::Get()->GetEditorManager();
138157
EditorBase* eb = em->IsOpen(file);
139158
if (eb && eb->IsBuiltinEditor())
@@ -160,20 +179,13 @@ void CodeChecker::OnProcessTerminate(wxProcessEvent &e)
160179

161180
void CodeChecker::OnAnalyze(CodeBlocksEvent &e)
162181
{
163-
LogMessage(_("Code Checker: Open or change"));
164182
EditorBase *edb=e.GetEditor();
165183
if(!edb->IsBuiltinEditor())
166-
{
167-
LogMessage(_("Code Checker: Not built in editor"));
168184
return;
169-
}
170185
cbEditor *ed=(cbEditor *)edb;
171186
int lexer=ed->GetControl()->GetLexer();
172187
if(m_commands.find(lexer)==m_commands.end())
173-
{
174-
LogMessage(_("Code Checker: Lexer not found"));
175188
return;
176-
}
177189
ProcessQueueItems p;
178190
p.lang=lexer;
179191
p.file=ed->GetFilename();
@@ -186,7 +198,6 @@ void CodeChecker::OnAnalyze(CodeBlocksEvent &e)
186198
m_processqueue.push_back(p);
187199
if(m_processqueue.size()==1)
188200
m_queuetimer.Start(1000,true);
189-
LogMessage(_("Code Checker: Request queued"));
190201
}
191202
}
192203

codecheck/codechecker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class CodeChecker : public cbPlugin
6565

6666
/** Called if a new file is opened or saved in the editor */
6767
void OnAnalyze(CodeBlocksEvent &e);
68+
69+
void OnTooltip(CodeBlocksEvent& e);
6870

6971
/** Called if a new file is opened or saved in the editor */
7072
void OnQueueTimer(wxTimerEvent &e);

0 commit comments

Comments
 (0)