Last active
August 6, 2018 14:44
-
-
Save hanspinckaers/663bb1461de2821d0bcce4ecef1f35c0 to your computer and use it in GitHub Desktop.
YCM and Jedi patches for faster Python completion, trade in type-information in completions for speed. Blog-post about my whole VIM setup coming soon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 49225f02ba22c79764e62c14d8f3747834e7547f Mon Sep 17 00:00:00 2001 | |
From: Hans Pinckaers <[email protected]> | |
Date: Mon, 6 Aug 2018 07:53:19 +0200 | |
Subject: [PATCH] Do not request type information (is slow) | |
--- | |
ycmd/completers/python/python_completer.py | 8 ++++---- | |
1 file changed, 4 insertions(+), 4 deletions(-) | |
diff --git a/ycmd/completers/python/python_completer.py b/ycmd/completers/python/python_completer.py | |
index ae45e32..b16233f 100644 | |
--- a/ycmd/completers/python/python_completer.py | |
+++ b/ycmd/completers/python/python_completer.py | |
@@ -192,10 +192,10 @@ class PythonCompleter( Completer ): | |
with self._jedi_lock: | |
return [ responses.BuildCompletionData( | |
insertion_text = completion.name, | |
- extra_menu_info = completion.description, | |
- detailed_info = completion.docstring(), | |
- kind = completion.type, | |
- extra_data = self._GetExtraData( completion ) | |
+ extra_menu_info = " ▸ jedi", | |
+ detailed_info = "", | |
+ kind = "", | |
+ extra_data = None | |
) for completion in self._GetJediScript( request_data ).completions() ] | |
-- | |
2.7.4 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e657556c402a9dbe9705b63a16b6584c0f8c9f73 Mon Sep 17 00:00:00 2001 | |
From: Hans Pinckaers <[email protected]> | |
Date: Mon, 6 Aug 2018 07:49:34 +0200 | |
Subject: [PATCH] Return empty context in find function for speed when possible | |
--- | |
jedi/__init__.py | 8 ++++++++ | |
jedi/api/completion.py | 10 +++++++++- | |
jedi/evaluate/finder.py | 5 ++++- | |
3 files changed, 21 insertions(+), 2 deletions(-) | |
diff --git a/jedi/__init__.py b/jedi/__init__.py | |
index 84ec178..4255fd5 100644 | |
--- a/jedi/__init__.py | |
+++ b/jedi/__init__.py | |
@@ -38,6 +38,14 @@ good text editor, while still having very good IDE features for Python. | |
__version__ = '0.12.1' | |
+def init_speed_hacks(on): | |
+ global speed_hacks | |
+ speed_hacks = on | |
+ | |
+def speed_hacks(): | |
+ global speed_hacks | |
+ return speed_hacks | |
+ | |
from jedi.api import Script, Interpreter, set_debug_function, \ | |
preload_module, names | |
from jedi import settings | |
diff --git a/jedi/api/completion.py b/jedi/api/completion.py | |
index 358d726..69b0f6f 100644 | |
--- a/jedi/api/completion.py | |
+++ b/jedi/api/completion.py | |
@@ -3,7 +3,7 @@ from parso.python import tree | |
from parso.tree import search_ancestor, Leaf | |
from jedi._compatibility import Parameter | |
-from jedi import debug | |
+from jedi import debug, init_speed_hacks | |
from jedi import settings | |
from jedi.api import classes | |
from jedi.api import helpers | |
@@ -91,6 +91,14 @@ class Completion: | |
self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position) | |
# The actual cursor position is not what we need to calculate | |
# everything. We want the start of the name we're on. | |
+ | |
+ # Some hacks to increase speed of Jedi | |
+ current_line = self._code_lines[position[0] - 1] | |
+ if '.' not in current_line and '(' not in current_line: | |
+ init_speed_hacks(True) | |
+ else: | |
+ init_speed_hacks(False) | |
+ | |
self._position = position[0], position[1] - len(self._like_name) | |
self._call_signatures_method = call_signatures_method | |
diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py | |
index 5e7043f..b2f5d81 100644 | |
--- a/jedi/evaluate/finder.py | |
+++ b/jedi/evaluate/finder.py | |
@@ -17,7 +17,7 @@ check for -> a is a string). There's big potential in these checks. | |
from parso.python import tree | |
from parso.tree import search_ancestor | |
-from jedi import debug | |
+from jedi import debug, speed_hacks | |
from jedi import settings | |
from jedi.evaluate.context import AbstractInstanceContext | |
from jedi.evaluate import compiled | |
@@ -53,6 +53,9 @@ class NameFinder(object): | |
:params bool attribute_lookup: Tell to logic if we're accessing the | |
attribute or the contents of e.g. a function. | |
""" | |
+ if speed_hacks(): | |
+ return ContextSet() | |
+ | |
names = self.filter_name(filters) | |
if self._found_predefined_types is not None and names: | |
check = flow_analysis.reachability_check( | |
-- | |
2.7.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To apply go to YouCompleteMe (probably somewhere in ~/.vim/):
$ git am --signoff < 1_ycm_speed_hacks.patch
Then inside the jedi-package of YouCompleteMe (YouCompleteMe/third_party/ycmd/third_party/jedi):
$ git am --signoff < 2_jedi_speed_hacks.patch