Skip to content

Commit c1b2a73

Browse files
committed
PythonCodeCompletion: adds goto definition, fix bug with error handling in the pyhton pipe server, various other clean up
1 parent 27f8b52 commit c1b2a73

6 files changed

Lines changed: 126 additions & 110 deletions

File tree

‎PythonCodeCompletion/PythonCodeCompletion.cbp‎

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Option compiler="gcc" />
88
<Build>
99
<Target title="XMLRPC">
10-
<Option output="XMLRPC\XmlRpc" prefix_auto="1" extension_auto="1" />
10+
<Option output="XMLRPC/XmlRpc" prefix_auto="1" extension_auto="1" />
1111
<Option working_dir="" />
1212
<Option type="2" />
1313
<Option compiler="gcc" />
@@ -18,7 +18,7 @@
1818
<Add option="-D_WINDOWS" />
1919
<Add option="-D_MBCS" />
2020
<Add option="-D_LIB" />
21-
<Add directory="XMLRPC\include" />
21+
<Add directory="XMLRPC/include" />
2222
</Compiler>
2323
<Linker>
2424
<Add library="Ws2_32" />
@@ -46,20 +46,20 @@
4646
<Add option="-DwxUSE_UNICODE" />
4747
<Add option="-D_WINDOWS" />
4848
<Add option="-D_LIB" />
49-
<Add directory="XMLRPC\include" />
50-
<Add directory="$(#cb)\include" />
51-
<Add directory="$(#cb)\sdk\wxscintilla\include" />
52-
<Add directory="$(#wx)\include" />
53-
<Add directory="$(#wx)\lib\gcc_dll\mswu" />
49+
<Add directory="XMLRPC/include" />
50+
<Add directory="$(#cb)/include" />
51+
<Add directory="$(#cb)/sdk/wxscintilla/include" />
52+
<Add directory="$(#wx)/include" />
53+
<Add directory="$(#wx)/lib/gcc_dll/mswu" />
5454
</Compiler>
5555
<Linker>
5656
<Add library="XmlRpc" />
5757
<Add library="codeblocks" />
5858
<Add library="wxmsw28u" />
5959
<Add library="Ws2_32" />
6060
<Add directory="XMLRPC" />
61-
<Add directory="$(#wx)\lib\gcc_dll" />
62-
<Add directory="$(#cb)\devel" />
61+
<Add directory="$(#wx)/lib/gcc_dll" />
62+
<Add directory="$(#cb)/devel" />
6363
</Linker>
6464
<ExtraCommands>
6565
<Add after="zip -j9 PythonCodeCompletion.zip manifest.xml" />
@@ -83,67 +83,67 @@
8383
<Unit filename="PythonCodeCompletion.h">
8484
<Option target="CodeCompletion" />
8585
</Unit>
86-
<Unit filename="XMLRPC\include\XmlRpc.h">
86+
<Unit filename="XMLRPC/include/XmlRpc.h">
8787
<Option target="XMLRPC" />
8888
</Unit>
89-
<Unit filename="XMLRPC\include\XmlRpcClient.h">
89+
<Unit filename="XMLRPC/include/XmlRpcClient.h">
9090
<Option target="XMLRPC" />
9191
</Unit>
92-
<Unit filename="XMLRPC\include\XmlRpcDispatch.h">
92+
<Unit filename="XMLRPC/include/XmlRpcDispatch.h">
9393
<Option target="XMLRPC" />
9494
</Unit>
95-
<Unit filename="XMLRPC\include\XmlRpcException.h">
95+
<Unit filename="XMLRPC/include/XmlRpcException.h">
9696
<Option target="XMLRPC" />
9797
</Unit>
98-
<Unit filename="XMLRPC\include\XmlRpcServer.h">
98+
<Unit filename="XMLRPC/include/XmlRpcServer.h">
9999
<Option target="XMLRPC" />
100100
</Unit>
101-
<Unit filename="XMLRPC\include\XmlRpcServerConnection.h">
101+
<Unit filename="XMLRPC/include/XmlRpcServerConnection.h">
102102
<Option target="XMLRPC" />
103103
</Unit>
104-
<Unit filename="XMLRPC\include\XmlRpcServerMethod.h">
104+
<Unit filename="XMLRPC/include/XmlRpcServerMethod.h">
105105
<Option target="XMLRPC" />
106106
</Unit>
107-
<Unit filename="XMLRPC\include\XmlRpcSocket.h">
107+
<Unit filename="XMLRPC/include/XmlRpcSocket.h">
108108
<Option target="XMLRPC" />
109109
</Unit>
110-
<Unit filename="XMLRPC\include\XmlRpcSource.h">
110+
<Unit filename="XMLRPC/include/XmlRpcSource.h">
111111
<Option target="XMLRPC" />
112112
</Unit>
113-
<Unit filename="XMLRPC\include\XmlRpcUtil.h">
113+
<Unit filename="XMLRPC/include/XmlRpcUtil.h">
114114
<Option target="XMLRPC" />
115115
</Unit>
116-
<Unit filename="XMLRPC\include\XmlRpcValue.h">
116+
<Unit filename="XMLRPC/include/XmlRpcValue.h">
117117
<Option target="XMLRPC" />
118118
</Unit>
119-
<Unit filename="XMLRPC\include\base64.h">
119+
<Unit filename="XMLRPC/include/base64.h">
120120
<Option target="XMLRPC" />
121121
</Unit>
122-
<Unit filename="XMLRPC\src\XmlRpcClient.cpp">
122+
<Unit filename="XMLRPC/src/XmlRpcClient.cpp">
123123
<Option target="XMLRPC" />
124124
</Unit>
125-
<Unit filename="XMLRPC\src\XmlRpcDispatch.cpp">
125+
<Unit filename="XMLRPC/src/XmlRpcDispatch.cpp">
126126
<Option target="XMLRPC" />
127127
</Unit>
128-
<Unit filename="XMLRPC\src\XmlRpcServer.cpp">
128+
<Unit filename="XMLRPC/src/XmlRpcServer.cpp">
129129
<Option target="XMLRPC" />
130130
</Unit>
131-
<Unit filename="XMLRPC\src\XmlRpcServerConnection.cpp">
131+
<Unit filename="XMLRPC/src/XmlRpcServerConnection.cpp">
132132
<Option target="XMLRPC" />
133133
</Unit>
134-
<Unit filename="XMLRPC\src\XmlRpcServerMethod.cpp">
134+
<Unit filename="XMLRPC/src/XmlRpcServerMethod.cpp">
135135
<Option target="XMLRPC" />
136136
</Unit>
137-
<Unit filename="XMLRPC\src\XmlRpcSocket.cpp">
137+
<Unit filename="XMLRPC/src/XmlRpcSocket.cpp">
138138
<Option target="XMLRPC" />
139139
</Unit>
140-
<Unit filename="XMLRPC\src\XmlRpcSource.cpp">
140+
<Unit filename="XMLRPC/src/XmlRpcSource.cpp">
141141
<Option target="XMLRPC" />
142142
</Unit>
143-
<Unit filename="XMLRPC\src\XmlRpcUtil.cpp">
143+
<Unit filename="XMLRPC/src/XmlRpcUtil.cpp">
144144
<Option target="XMLRPC" />
145145
</Unit>
146-
<Unit filename="XMLRPC\src\XmlRpcValue.cpp">
146+
<Unit filename="XMLRPC/src/XmlRpcValue.cpp">
147147
<Option target="XMLRPC" />
148148
</Unit>
149149
<Unit filename="XmlRpcEvents.cpp">
@@ -155,10 +155,13 @@
155155
<Unit filename="manifest.xml">
156156
<Option target="CodeCompletion" />
157157
</Unit>
158-
<Unit filename="python\python_completion_server.py">
158+
<Unit filename="python/jedi_example.py">
159159
<Option target="CodeCompletion" />
160160
</Unit>
161-
<Unit filename="python\stdlib_parser.py">
161+
<Unit filename="python/python_completion_server.py">
162+
<Option target="CodeCompletion" />
163+
</Unit>
164+
<Unit filename="python/stdlib_parser.py">
162165
<Option target="CodeCompletion" />
163166
</Unit>
164167
<Unit filename="xmlrpc_embedder.cpp">

‎PythonCodeCompletion/PythonCodeCompletion.cpp‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ BEGIN_EVENT_TABLE(PythonCodeCompletion, cbCodeCompletionPlugin)
4040
EVT_XMLRPC_RESPONSE(ID_STDLIB_LOAD,PythonCodeCompletion::OnStdLibLoaded)
4141
EVT_XMLRPC_RESPONSE(ID_COMPLETE_PHRASE,PythonCodeCompletion::OnCompletePhrase)
4242
EVT_XMLRPC_RESPONSE(ID_CALLTIP,PythonCodeCompletion::OnCalltip)
43-
EVT_XMLRPC_RESPONSE(ID_GOTO_DECLARATION,PythonCodeCompletion::OnGotoDeclaration)
44-
EVT_MENU(ID_GOTO_DECLARATION, PythonCodeCompletion::OnClickedGotoDeclaration)
43+
EVT_XMLRPC_RESPONSE(ID_GOTO_DECLARATION,PythonCodeCompletion::OnGotoDefinition)
44+
EVT_MENU(ID_GOTO_DECLARATION, PythonCodeCompletion::OnClickedGotoDefinition)
4545
END_EVENT_TABLE()
4646

4747
// constructor
@@ -307,16 +307,11 @@ void PythonCodeCompletion::OnCompletePhrase(XmlRpcResponseEvent &event)
307307
}
308308
Manager::Get()->GetLogManager()->Log(_("PYCC: Unexpected phrase completion result"));
309309
Manager::Get()->GetLogManager()->Log(wxString(val.toXml().c_str(),wxConvUTF8));
310+
return;
310311
}
311-
else if(event.GetState()==XMLRPC_STATE_RESPONSE)
312-
{
313-
XmlRpc::XmlRpcValue val=event.GetResponse();
314-
wxMessageBox(_("PYCC Error:\n")+wxString(val.toXml().c_str(),wxConvUTF8));
315-
Manager::Get()->GetLogManager()->Log(_("PYCC: Error in completion result"));
316-
Manager::Get()->GetLogManager()->Log(wxString(val.toXml().c_str(),wxConvUTF8));
317-
}
318-
else
319-
Manager::Get()->GetLogManager()->Log(_("PYCC: Completion failed"));
312+
XmlRpc::XmlRpcValue val=event.GetResponse();
313+
Manager::Get()->GetLogManager()->Log(_("PYCC: Error in completion result"));
314+
Manager::Get()->GetLogManager()->Log(wxString(val.toXml().c_str(),wxConvUTF8));
320315
}
321316

322317

@@ -499,7 +494,7 @@ void PythonCodeCompletion::RequestCompletion(cbStyledTextCtrl *control, int pos,
499494
int line = control->LineFromPosition(pos);
500495
int column = pos - control->PositionFromLine(line);
501496
XmlRpc::XmlRpcValue value;
502-
value.setSize(3);
497+
value.setSize(4);
503498
value[0] = filename.utf8_str(); //mb_str(wxConvUTF8);
504499
value[1] = control->GetText().utf8_str(); //mb_str(wxConvUTF8);
505500
value[2] = line;
@@ -513,7 +508,7 @@ void PythonCodeCompletion::RequestCallTip(cbStyledTextCtrl *control, int pos, co
513508
int line = control->LineFromPosition(pos);
514509
int column = pos - control->PositionFromLine(line);
515510
XmlRpc::XmlRpcValue value;
516-
value.setSize(3);
511+
value.setSize(4);
517512
value[0] = filename.utf8_str(); //mb_str(wxConvUTF8);
518513
value[1] = control->GetText().utf8_str(); //mb_str(wxConvUTF8);
519514
value[2] = line;
@@ -725,7 +720,7 @@ void PythonCodeCompletion::EditorEventHook(cbEditor* editor, wxScintillaEvent& e
725720
event.Skip();
726721
}
727722

728-
void PythonCodeCompletion::OnClickedGotoDeclaration(wxCommandEvent& event)
723+
void PythonCodeCompletion::OnClickedGotoDefinition(wxCommandEvent& event)
729724
{
730725
cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
731726
if(!ed)
@@ -736,20 +731,23 @@ void PythonCodeCompletion::OnClickedGotoDeclaration(wxCommandEvent& event)
736731
if(control->GetLexer() != wxSCI_LEX_PYTHON)
737732
return;
738733
int pos = control->GetCurrentPos();
734+
int line = control->LineFromPosition(pos);
735+
int column = pos - control->PositionFromLine(line);
739736
XmlRpc::XmlRpcValue value;
740-
value.setSize(3);
737+
value.setSize(4);
741738
value[0] = ed->GetFilename().utf8_str();
742739
value[1] = control->GetText().utf8_str();
743-
value[2] = pos;
740+
value[2] = line;
741+
value[3] = column;
744742
py_server->ClearJobs();
745743
py_server->ExecAsync(_T("get_definition_location"),value,this,ID_GOTO_DECLARATION);
746744
}
747745

748-
void PythonCodeCompletion::OnGotoDeclaration(XmlRpcResponseEvent &event)
746+
void PythonCodeCompletion::OnGotoDefinition(XmlRpcResponseEvent &event)
749747
{
750748
if(event.GetState()==XMLRPC_STATE_RESPONSE)
751749
{
752-
Manager::Get()->GetLogManager()->Log(_("PYCC: Declaration response"));
750+
Manager::Get()->GetLogManager()->Log(_("PYCC: Goto Definition response"));
753751
XmlRpc::XmlRpcValue val=event.GetResponse(); //Should return an array of path, lineno
754752
m_comp_results.Empty();
755753
Manager::Get()->GetLogManager()->Log(wxString::Format(_("PYCC: XML response \n%s"),val.toXml().c_str()));
@@ -762,20 +760,25 @@ void PythonCodeCompletion::OnGotoDeclaration(XmlRpcResponseEvent &event)
762760
// if(!ed)
763761
// return;
764762
// f.MakeRelativeTo(ed->GetFilename());
765-
Manager::Get()->GetLogManager()->Log(wxString::Format(_("PYCC: Declaration is at %s:%i"),f.GetFullPath().wx_str(),line));
763+
Manager::Get()->GetLogManager()->Log(wxString::Format(_("PYCC: Definition is at %s:%i"),f.GetFullPath().wx_str(),line));
766764
if(f.FileExists())
767765
{
768766
cbEditor* ed = Manager::Get()->GetEditorManager()->Open(f.GetFullPath());
769767
if (ed)
770768
{
771769
ed->Show(true);
772-
ed->GotoLine(line - 1, false);
770+
ed->GotoLine(line, false);
773771
}
774772
return;
775773
}
776774
Manager::Get()->GetLogManager()->Log(_("PYCC: file could not be opened"));
775+
XmlRpc::XmlRpcValue val=event.GetResponse();
776+
Manager::Get()->GetLogManager()->Log(wxString(val.toXml().c_str(),wxConvUTF8));
777+
return;
777778
}
778779
}
779-
Manager::Get()->GetLogManager()->Log(_("PYCC: Bad response for goto declaration"));
780+
Manager::Get()->GetLogManager()->Log(_("PYCC: Bad response for goto definition"));
781+
XmlRpc::XmlRpcValue val=event.GetResponse();
782+
Manager::Get()->GetLogManager()->Log(wxString(val.toXml().c_str(),wxConvUTF8));
780783
}
781784

‎PythonCodeCompletion/PythonCodeCompletion.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class PythonCodeCompletion : public cbCodeCompletionPlugin
132132
void OnStdLibLoaded(XmlRpcResponseEvent &event);
133133
void OnCalltip(XmlRpcResponseEvent &event);
134134
void OnCompletePhrase(XmlRpcResponseEvent &event);
135-
void OnClickedGotoDeclaration(wxCommandEvent& event);
136-
void OnGotoDeclaration(XmlRpcResponseEvent &event);
135+
void OnClickedGotoDefinition(wxCommandEvent& event);
136+
void OnGotoDefinition(XmlRpcResponseEvent &event);
137137

138138
void RequestCompletion(cbStyledTextCtrl *control, int pos, const wxString &filename);
139139
void RequestCallTip(cbStyledTextCtrl *control, int pos, const wxString &filename);

‎PythonCodeCompletion/python/jedi_example.py‎

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,58 @@
11
import jedi
2-
2+
import numpy
3+
numpy.
34
script = '''
45
def f(x,y,z):
56
print x,y,z
6-
f(
7+
f()
8+
print 1
9+
import os
10+
os.
711
'''
812

913

14+
def get_definition_location(path,source,line,column):
15+
source=source.replace('\r','')
16+
script = jedi.Script(source,line=line+1,column=column,source_path=path)
17+
results = script.goto_definitions()
18+
for d in results:
19+
print dir(d)
20+
module_path = d.module_path
21+
print d.line,d.line_nr
22+
if module_path is None:
23+
module_path = path
24+
return [module_path,d.line-1]
25+
return ['',-1]
26+
27+
print get_definition_location(None,script,3,1)
28+
1029
def complete_tip(path,source,line,column):
1130
source=source.replace('\r','')
1231
script = jedi.Script(source,line=line+1,column=column,source_path=path)
1332
call_def = script.call_signatures()
1433
calltip = ''
15-
print call_def
1634
for c in call_def:
17-
docstr=''
1835
calltip=c.call_name+'('
19-
for p in c.params:
20-
calltip+=p.get_name()+', '
21-
docstr+=p.docstr
22-
calltip+=')'
23-
if docstr!='':
24-
calltip+='\n'+docstr
36+
calltip+=', '.join([p.get_name().names[0] for p in c.params])+')'
37+
# docstr=''
38+
# for p in c.params:
39+
# docstr+=p.docstr
40+
# if docstr!='':
41+
# calltip+='\n'+docstr
2542
return calltip
2643
return ''
2744

28-
#print complete_tip(None,script,3,2)
45+
print complete_tip(None,script,3,2)
2946

3047

31-
s = jedi.Script(script,line=4,column=2)
32-
cs = s.call_signatures()
33-
for m in dir(cs[0]):
34-
print m
35-
36-
for p in cs[0].params:
37-
print p.get_name().names, p.docstr
38-
48+
#s = jedi.Script(script,line=4,column=2)
49+
#cs = s.call_signatures()
50+
#for m in dir(cs[0]):
51+
# print m
52+
#
53+
#for p in cs[0].params:
54+
# print p.get_name().names, p.docstr
55+
#
3956

4057
#for m in dir(cs[0].params[0]):
4158
# print m

0 commit comments

Comments
 (0)