Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add option to use Jedi in the IPython console + warning on greedy completer #6832

Merged
merged 6 commits into from Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions spyder/config/main.py
Expand Up @@ -158,6 +158,7 @@
'startup/use_run_file': False,
'startup/run_file': '',
'greedy_completer': False,
'jedi_completer': False,
'autocall': 0,
'symbolic_math': False,
'in_prompt': '',
Expand Down
52 changes: 39 additions & 13 deletions spyder/plugins/ipythonconsole.py
Expand Up @@ -477,20 +477,46 @@ def setup_page(self):
run_file_group.setLayout(run_file_layout)

# ---- Advanced settings ----
# Enable Jedi completion
jedi_group = QGroupBox(_("Jedi completion"))
jedi_label = QLabel(_("Enable Jedi-based <tt>Tab</tt> completion "
"in the IPython console; similar to the "
"greedy completer, but without evaluating "
"the code.<br>"
"<b>Warning:</b> Slows down your console "
"when working with large dataframes!"))
jedi_label.setWordWrap(True)
jedi_box = newcb(_("Use Jedi completion in the IPython console"),
"jedi_completer",
tip="<b>Warning</b>: "
"Slows down your console when working with "
"large dataframes!<br>"
"Allows completion of nested lists etc.")

jedi_layout = QVBoxLayout()
jedi_layout.addWidget(jedi_label)
jedi_layout.addWidget(jedi_box)
jedi_group.setLayout(jedi_layout)

# Greedy completer group
greedy_group = QGroupBox(_("Greedy completion"))
greedy_label = QLabel(_("Enable <tt>Tab</tt> completion on elements "
"of lists, results of function calls, etc, "
"<i>without</i> assigning them to a "
"variable.<br>"
"For example, you can get completions on "
"things like <tt>li[0].&lt;Tab&gt;</tt> or "
"<tt>ins.meth().&lt;Tab&gt;</tt>"))
"<i>without</i> assigning them to a variable, "
"like <tt>li[0].&lt;Tab&gt;</tt> or "
"<tt>ins.meth().&lt;Tab&gt;</tt> <br>"
"<b>Warning:</b> Due to a bug, IPython's "
"greedy completer requires a leading "
"<tt>&lt;Space&gt;</tt> for some completions; "
"e.g. <tt>np.sin(&lt;Space&gt;np.&lt;Tab&gt;"
"</tt> works while <tt>np.sin(np.&lt;Tab&gt; "
"</tt> doesn't."))
greedy_label.setWordWrap(True)
greedy_box = newcb(_("Use the greedy completer"), "greedy_completer",
greedy_box = newcb(_("Use greedy completion in the IPython console"),
"greedy_completer",
tip="<b>Warning</b>: It can be unsafe because the "
"code is actually evaluated when you press "
"<tt>Tab</tt>.")
"code is actually evaluated when you press "
"<tt>Tab</tt>.")

greedy_layout = QVBoxLayout()
greedy_layout.addWidget(greedy_label)
Expand All @@ -500,10 +526,10 @@ def setup_page(self):
# Autocall group
autocall_group = QGroupBox(_("Autocall"))
autocall_label = QLabel(_("Autocall makes IPython automatically call "
"any callable object even if you didn't type "
"explicit parentheses.<br>"
"For example, if you type <i>str 43</i> it "
"becomes <i>str(43)</i> automatically."))
"any callable object even if you didn't "
"type explicit parentheses.<br>"
"For example, if you type <i>str 43</i> it "
"becomes <i>str(43)</i> automatically."))
autocall_label.setWordWrap(True)

smart = _('Smart')
Expand Down Expand Up @@ -575,7 +601,7 @@ def setup_page(self):
_("Graphics"))
tabs.addTab(self.create_tab(run_lines_group, run_file_group),
_("Startup"))
tabs.addTab(self.create_tab(greedy_group, autocall_group, sympy_group,
tabs.addTab(self.create_tab(jedi_group, greedy_group, autocall_group, sympy_group,
prompts_group), _("Advanced Settings"))

vlayout = QVBoxLayout()
Expand Down
1 change: 1 addition & 0 deletions spyder/utils/ipython/kernelspec.py
Expand Up @@ -124,6 +124,7 @@ def env(self):
'SPY_RUN_FILE_O': CONF.get('ipython_console', 'startup/run_file'),
'SPY_AUTOCALL_O': CONF.get('ipython_console', 'autocall'),
'SPY_GREEDY_O': CONF.get('ipython_console', 'greedy_completer'),
'SPY_JEDI_O': CONF.get('ipython_console', 'jedi_completer'),
'SPY_SYMPY_O': CONF.get('ipython_console', 'symbolic_math'),
'SPY_RUN_CYTHON': self.is_cython
}
Expand Down
4 changes: 3 additions & 1 deletion spyder/utils/ipython/start_kernel.py
Expand Up @@ -69,10 +69,12 @@ def kernel_config():
# Until we implement Issue 1052
spy_cfg.InteractiveShell.xmode = 'Plain'

# Jedi completer
jedi_o = os.environ.get('SPY_JEDI_O') == 'True'
# - Using Jedi slow completions a lot for objects with big repr's.
# - Jedi completions are not available in Python 2.
if not PY2:
spy_cfg.IPCompleter.use_jedi = False
spy_cfg.IPCompleter.use_jedi = jedi_o

# Run lines of code at startup
run_lines_o = os.environ.get('SPY_RUN_LINES_O')
Expand Down