diff --git a/.travis.yml b/.travis.yml index c3cbccb..ccb2b8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,30 @@ sudo: false language: python +git: + depth: 3 python: - - "2.7" - - "3.4" + # First python version in this list is the default for matrix.include + # - "3.7" + - "3.6" - "3.5" + - "3.4" + - "2.7" env: matrix: - - EVM_EMACS=emacs-24.3-travis - - EVM_EMACS=emacs-24.4-travis - - EVM_EMACS=emacs-24.5-travis + - EVM_EMACS=emacs-26.1-travis global: # Turn on --use-mirrors option everywhere (even in tox): - PIP_USE_MIRRORS=t # Use Python version of the one used for running tox - TOXENV=py matrix: - allow_failures: - - python: "3.5" + include: + - env: EVM_EMACS=emacs-24.4-travis + - env: EVM_EMACS=emacs-24.5-travis + - env: EVM_EMACS=emacs-25.1-travis + - env: EVM_EMACS=emacs-25.2-travis + - env: EVM_EMACS=emacs-25.3-travis + before_install: - pip install -q virtualenv tox - curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh diff --git a/jediepcserver.py b/jediepcserver.py index fc6b6aa..5db5f6a 100755 --- a/jediepcserver.py +++ b/jediepcserver.py @@ -35,7 +35,6 @@ jedi = None # I will load it later - PY3 = (sys.version_info[0] >= 3) NEED_ENCODE = not PY3 @@ -92,20 +91,24 @@ def complete(*args): return reply +PARAM_PREFIX_RE = re.compile(r'^param\s+') +"""RE to strip unwanted "param " prefix returned by param.description.""" + def get_in_function_call(*args): sig = jedi_script(*args).call_signatures() call_def = sig[0] if sig else None - if call_def: - return dict( - # p.get_code(False) should do the job. But jedi-vim use replace. - # So follow what jedi-vim does... - params=[p.get_code().replace('\n', '') for p in call_def.params], - index=call_def.index, - call_name=call_def.call_name, - ) - else: - return [] # nil + if not call_def: + return [] + + return dict( + # p.description should do the job. But jedi-vim use replace. + # So follow what jedi-vim does... + params=[PARAM_PREFIX_RE.sub('', p.description).replace('\n', '') + for p in call_def.params], + index=call_def.index, + call_name=call_def.name, + ) def _goto(method, *args): @@ -176,10 +179,25 @@ def get_names_recursively(definition, parent=None): def defined_names(*args): - return list(map(get_names_recursively, jedi.api.defined_names(*args))) + # XXX: there's a bug in Jedi that returns returns definitions from inside + # classes or functions even though all_scopes=False is set by + # default. Hence some additional filtering is in order. + # + # See https://github.com/davidhalter/jedi/issues/1202 + top_level_names = [ + defn + for defn in jedi.api.names(*args) + if defn.parent().type == 'module' + ] + return list(map(get_names_recursively, top_level_names)) def get_module_version(module): + notfound = object() + for key in ['__version__', 'version']: + version = getattr(module, key, notfound) + if version is not notfound: + return version try: from pkg_resources import get_distribution, DistributionNotFound try: @@ -189,11 +207,6 @@ def get_module_version(module): except ImportError: pass - notfound = object() - for key in ['__version__', 'version']: - version = getattr(module, key, notfound) - if version is not notfound: - return version def get_jedi_version(): diff --git a/test-jedi.el b/test-jedi.el index 340b767..bb11bfe 100644 --- a/test-jedi.el +++ b/test-jedi.el @@ -68,14 +68,16 @@ json.l (ert-deftest jedi:get-in-function-call-request () (with-python-temp-buffer " -isinstance(obj, +def foobar(qux, quux): + pass +foobar(obj, " (goto-char (1- (point-max))) (destructuring-bind (&key params index call_name) (jedi-testing:sync (jedi:call-deferred 'get_in_function_call)) - (should (equal params '("object" "class_or_type_or_tuple"))) + (should (equal params '("qux" "quux"))) (should (equal index 1)) - (should (equal call_name "isinstance"))))) + (should (equal call_name "foobar"))))) (ert-deftest jedi:goto-request () (with-python-temp-buffer