[gnome-code-assistance/wip/completion_python: 2/2] [backend/python] initial support for completion
- From: Igor Gnatenko <ignatenko src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-code-assistance/wip/completion_python: 2/2] [backend/python] initial support for completion
- Date: Mon, 12 Jan 2015 13:32:16 +0000 (UTC)
commit 94951c29150f3e39dc44143ea50959859aad4e3b
Author: Igor Gnatenko <ignatenko src gnome org>
Date: Mon Jan 12 16:31:40 2015 +0300
[backend/python] initial support for completion
Signed-off-by: Igor Gnatenko <ignatenko src gnome org>
README | 2 +-
backends/python/__init__.py | 22 +++++++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/README b/README
index 1f1f749..403fbb8 100644
--- a/README
+++ b/README
@@ -184,7 +184,7 @@ Dependencies : gjs
Dependencies : python, python-dbus, python-simplejson
### Python
-Dependencies : python, python-dbus
+Dependencies : python, python-dbus, python-jedi
Optional dependencies : pylint (enabled only if you will pass "pylint" in "options" to dbus service), pep8
(run when present)
### Ruby
diff --git a/backends/python/__init__.py b/backends/python/__init__.py
index 9476d6f..63263b5 100644
--- a/backends/python/__init__.py
+++ b/backends/python/__init__.py
@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import ast
+import jedi
import subprocess
import re
@@ -65,9 +66,28 @@ class PyLint(object):
return self.diagnostics
-class Service(transport.Service):
+class Service(transport.Service, transport.Completion):
language = 'python'
+ def complete(self, doc, options):
+ items = []
+ file_content = []
+ with open(doc.data_path, "r") as f:
+ file_content = f.readlines()
+ source = "".join(file_content)
+ script = jedi.Script(source,
+ doc.cursor.line + 1,
+ doc.cursor.column - 1,
+ "example.py")
+ completions = script.completions()
+ completions = sorted(completions, key=lambda d: d.name)
+ for comp in completions:
+ items.append(types.Completion(
+ comp.name,
+ [types.Completion.Chunk(comp.name)],
+ description=comp.description))
+ return items
+
def parse(self, doc, options):
doc.diagnostics = []
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]