FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/jedi/utils.py at interpreter · Demon888/pythonVSCode · GitHub
Demon888
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
jedi
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
114 lines (94 loc) · 3.97 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
jedi
/
utils.py
Copy path
File metadata and controls
executable file
·
114 lines (94 loc) · 3.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Utilities for end-users.
"""
from
__future__
import
absolute_import
import
__main__
from
collections
import
namedtuple
import
re
import
os
import
sys
from
jedi
import
Interpreter
from
jedi
.
api
.
helpers
import
completion_parts
from
jedi
.
parser
.
user_context
import
UserContext
def
setup_readline
(
namespace_module
=
__main__
):
"""
Install Jedi completer to :mod:`readline`.
This function setups :mod:`readline` to use Jedi in Python interactive
shell. If you want to use a custom ``PYTHONSTARTUP`` file (typically
``$HOME/.pythonrc.py``), you can add this piece of code::
try:
from jedi.utils import setup_readline
setup_readline()
except ImportError:
# Fallback to the stdlib readline completer if it is installed.
# Taken from http://docs.python.org/2/library/rlcompleter.html
print("Jedi is not installed, falling back to readline")
try:
import readline
import rlcompleter
readline.parse_and_bind("tab: complete")
except ImportError:
print("Readline is not installed either. No tab completion is enabled.")
This will fallback to the readline completer if Jedi is not installed.
The readline completer will only complete names in the global namespace,
so for example::
ran<TAB>
will complete to ``range``
with both Jedi and readline, but::
range(10).cou<TAB>
will show complete to ``range(10).count`` only with Jedi.
You'll also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to
your shell profile (usually ``.bash_profile`` or ``.profile`` if you use
bash).
"""
class
JediRL
(
object
):
def
complete
(
self
,
text
,
state
):
"""
This complete stuff is pretty weird, a generator would make
a lot more sense, but probably due to backwards compatibility
this is still the way how it works.
The only important part is stuff in the ``state == 0`` flow,
everything else has been copied from the ``rlcompleter`` std.
library module.
"""
if
state
==
0
:
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
# Calling python doesn't have a path, so add to sys.path.
try
:
interpreter
=
Interpreter
(
text
, [
namespace_module
.
__dict__
])
path
=
UserContext
(
text
, (
1
,
len
(
text
))).
get_path_until_cursor
()
path
,
dot
,
like
=
completion_parts
(
path
)
before
=
text
[:
len
(
text
)
-
len
(
like
)]
completions
=
interpreter
.
completions
()
finally
:
sys
.
path
.
pop
(
0
)
self
.
matches
=
[
before
+
c
.
name_with_symbols
for
c
in
completions
]
try
:
return
self
.
matches
[
state
]
except
IndexError
:
return
None
try
:
import
readline
except
ImportError
:
print
(
"Module readline not available."
)
else
:
readline
.
set_completer
(
JediRL
().
complete
)
readline
.
parse_and_bind
(
"tab: complete"
)
# jedi itself does the case matching
readline
.
parse_and_bind
(
"set completion-ignore-case on"
)
# because it's easier to hit the tab just once
readline
.
parse_and_bind
(
"set show-all-if-unmodified"
)
readline
.
parse_and_bind
(
"set show-all-if-ambiguous on"
)
# don't repeat all the things written in the readline all the time
readline
.
parse_and_bind
(
"set completion-prefix-display-length 2"
)
# No delimiters, Jedi handles that.
readline
.
set_completer_delims
(
''
)
def
version_info
():
"""
Returns a namedtuple of Jedi's version, similar to Python's
``sys.version_info``.
"""
Version
=
namedtuple
(
'Version'
,
'major, minor, micro'
)
from
jedi
import
__version__
tupl
=
re
.
findall
(
'[a-z]+|\d+'
,
__version__
)
return
Version
(
*
[
x
if
i
==
3
else
int
(
x
)
for
i
,
x
in
enumerate
(
tupl
)])
Back
|
FazBrowse Home
|
New Git URL