Skip to content

Commit

Permalink
Create and pass environment object to the jedi.Script API (#1544)
Browse files Browse the repository at this point in the history
* Create environment for Jedi
* Build environment object once
* Fixes #1532
  • Loading branch information
DonJayamanne authored Apr 30, 2018
1 parent 7b628d0 commit 5d6493b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pythonFiles/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class JediCompletion(object):

def __init__(self):
self.default_sys_path = sys.path
self.environment = jedi.api.environment.Environment(sys.prefix, sys.executable)
self._input = io.open(sys.stdin.fileno(), encoding='utf-8')
if (os.path.sep == '/') and (platform.uname()[2].find('Microsoft') > -1):
# WSL; does not support UNC paths
Expand Down Expand Up @@ -150,7 +151,7 @@ def _get_call_signatures_with_args(self, script):
except Exception:
sig["docstring"] = ''
sig["raw_docstring"] = ''

sig["name"] = signature.name
sig["paramindex"] = signature.index
sig["bracketstart"].append(signature.index)
Expand Down Expand Up @@ -199,7 +200,7 @@ def _serialize_completions(self, script, identifier=None, prefix=''):
}
_completion['description'] = ''
_completion['raw_docstring'] = ''

# we pass 'text' here only for fuzzy matcher
if value:
_completion['snippet'] = '%s=${1:%s}$0' % (name, value)
Expand All @@ -223,15 +224,15 @@ def _serialize_completions(self, script, identifier=None, prefix=''):
'type': self._get_definition_type(completion),
'raw_type': completion.type,
'rightLabel': self._additional_info(completion)
}
}
except Exception:
continue

for c in _completions:
if c['text'] == _completion['text']:
c['type'] = _completion['type']
c['raw_type'] = _completion['raw_type']

if any([c['text'].split('=')[0] == _completion['text']
for c in _completions]):
# ignore function arguments we already have
Expand Down Expand Up @@ -361,7 +362,7 @@ def _get_definitionsx(self, definitions, identifier=None, ignoreNoModulePath=Fal
definition = self._top_definition(definition)
definitionRange = {
'start_line': 0,
'start_column': 0,
'start_column': 0,
'end_line': 0,
'end_column': 0
}
Expand All @@ -377,7 +378,7 @@ def _get_definitionsx(self, definitions, identifier=None, ignoreNoModulePath=Fal
container = parent.name if parent.type != 'module' else ''
except Exception:
container = ''

try:
docstring = definition.docstring()
rawdocstring = definition.docstring(raw=True)
Expand Down Expand Up @@ -424,7 +425,7 @@ def _serialize_definitions(self, definitions, identifier=None):
container = parent.name if parent.type != 'module' else ''
except Exception:
container = ''

try:
docstring = definition.docstring()
rawdocstring = definition.docstring(raw=True)
Expand Down Expand Up @@ -474,7 +475,7 @@ def _serialize_tooltip(self, definitions, identifier=None):
'type': self._get_definition_type(definition),
'text': definition.name,
'description': description,
'docstring': description,
'docstring': description,
'signature': signature
}
_definitions.append(_definition)
Expand Down Expand Up @@ -566,8 +567,8 @@ def _process_request(self, request):
script = jedi.Script(
source=request.get('source', None), line=request['line'] + 1,
column=request['column'], path=request.get('path', ''),
sys_path=sys.path)
sys_path=sys.path, environment=self.environment)

if lookup == 'definitions':
defs = []
try:
Expand Down Expand Up @@ -625,7 +626,7 @@ def watch(self):
try:
rq = self._input.readline()
if len(rq) == 0:
# Reached EOF - indication our parent process is gone.
# Reached EOF - indication our parent process is gone.
sys.stderr.write('Received EOF from the standard input,exiting' + '\n')
sys.stderr.flush()
return
Expand Down

0 comments on commit 5d6493b

Please sign in to comment.