notetau / geany-jedi-complete

a Geany plugin to provide code completion (Python) using jedi
GNU General Public License v2.0
32 stars 5 forks source link

Plugin's dependencies and unicode problem. #7

Open dmgl opened 7 years ago

dmgl commented 7 years ago

Plugin have dependency from libgtk2.0-dev. Without it make install return error:

mkdir -p lib/geany-complete-core/src/
g++ -c geany-complete-core/src/cc_plugin.cpp -O2 -fPIC `pkg-config --cflags geany` -std=c++0x -I./geany-complete-core/include -o lib/geany-complete-core/src/cc_plugin.o
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gtk+-2.0', required by 'geany', not found

Also plugin needs libcurl-dev virtual package or libcurl4-openssl-dev. Because without it make install failed:

g++ -c src/completion.cpp -O2 -fPIC `pkg-config --cflags geany` -std=c++0x -I./geany-complete-core/include -o lib/src/completion.o
src/completion.cpp:32:23: fatal error: curl/curl.h: Нет такого файла или каталога
compilation terminated.

After install libcurl4-openssl-dev and libgtk2.0-dev command make install completed right. So geanyjedicomplete.so copied to /usr/lib/i386-linux-gnu/geany/. And then you can enable plugin in Plugin manager from Geany. Also can reinstall jedi server script from settings (if needed).

But plugin don't work. Because has another problem = unicode problem from jediserver.py. It can be found in $HOME/.config/geany/plugins/jedi-complete/. The problem is UnicodeDecodeError:. For reproduce the error need create python file in editor with some code like:

my_string = "йцукенг"
my_string.

After making a dot symbol nothing happens. In terminal you can see:

127.0.0.1 - - [27/May/2017 00:33:17] "POST /complete HTTP/1.1" 200 -
('path:', '/complete')
('jedi-server/complete: ', 5, 10, '/tmp/1.py')
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 39538)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "/home/constantia/.config/geany/plugins/jedi-complete/jediserver.py", line 36, in do_POST
    self.wfile.write(post_data.encode("utf-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 65: ordinal not in range(128)
----------------------------------------
server ret = 0
complete 0

Need to correct .config/geany/plugins/jedi-complete/jediserver.py in 36 line. Workaround - add post_data = unicode(post_data, 'utf-8'). Sorry, i don't know where i can add it in C code before make install.

Fragment of code:

    def do_POST(self):
        time_start = time.time()
        print(self.headers)

        self.send_response(200)
        self.end_headers()
        print("path:", self.path)

        post_data = self.rfile.read(int(self.headers["content-length"]))
        if py3flag:
            post_data = str(post_data, "utf-8")
        post_data += self.run_complete(post_data)
        post_data = unicode(post_data, 'utf-8') # <= ADD THIS LINE
        self.wfile.write(post_data.encode("utf-8"))
        print("jedi-server: done {0} s".format(time.time() - time_start))

After all these steps i can enjoy wonderful plugin. Thank you!

dmgl commented 7 years ago

Suggestion => https://github.com/notetau/geany-jedi-complete/pull/8/commits/ea271ce3a50d122bef179c713ddbf0810ad926b6