syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.65k stars 4.89k forks source link

lsp completion in python provides $0 instead of argument list #13358

Closed markgdawson closed 3 years ago

markgdawson commented 4 years ago

Description :octocat:

lsp completion for python provides $0 instead of argument list

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart: le is completed as len($0), with the cursor positioned to the right of the last bracket. Any other function call appears to be is completed in the same way, e.g. numpy.zeros($0).

Even functions with multiple arguments are completed with a single argument, which is always $0, with the cursor on the right hand side of the last bracket.

Expected behaviour: :heart: :smile: I expected to see len() with the cursor between the brackets, or len(o), with o highlighted and ready to edit.

For multiple arguments, I thought lsp-mode would provide a list of the arguments, with tab stops to edit each one.

The lsp-mode readme FAQ says:

Q: The completion does not work fine and inserts arguments and placeholders, what I am doing wrong? A: Snippet support works only with company-lsp so if you are using completion-at-point the snippets won’t be expanded and you should either disable them by setting lsp-enable-snippet to nil or you should switch to company-lsp. Note also that company-tng frontend does not support snippet expansion(see company-mode#891)

I'm not sure if this is related.

The value of completion-at-point-functions is (lsp-completion-at-point)

System Info :computer:

dvzubarev commented 4 years ago

https://github.com/emacs-lsp/lsp-mode/issues/1337 It occurs to me occasionally in c++-mode too.

smile13241324 commented 4 years ago

I will try to reproduce this behaviour and see whether we can do something about it.

smile13241324 commented 4 years ago

I am struggling a bit with reproducing your issue. I have followed your instructions except of using pyenv-workon instead I have used ,va.

The rest seems to be working on my side, completing le to len(o) with o being marked and replaced when i enter something. I have also completed the function do_nothing_eggs(text: str, text2: str, text3: str) which correctly highlighted the parameters and switched through them with tab.

I have used below file:

""" Very simple test file """
le -> complete to len(o)

def say(text: str) -> None:
    """ This prints what you tell it """
    print(text)

def add_eggs(text: str) -> str:
    """ This adds some eggs """
    return " ".join([text, "eggs"])

def do_nothing_eggs(text: str, text2: str, text3: str) -> str:
    """ Do nothing """
    pass

do_no -> completed to do_nothing_eggs(text, text2, text3)

say(add_eggs("I love my spam with"))

Can you update your packages and layers and check whether you see the same behaviour when you use my test file? Also it would be interesting which version of the lsp server you are using.

For me it is:

Here is my system config:

#### System Info :computer:
- OS: gnu/linux
- Emacs: 26.3
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. c7af78725)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
((lsp :variables lsp-navigation 'peek lsp-ui-doc-enable nil)
 dap
 (dart :variables dart-backend 'lsp lsp-dart-sdk-dir "~/Downloads/dart-sdk/")
 helm
 (scala :variables scala-backend 'scala-metals)
 nim spacemacs-purpose elasticsearch
 (yang :variables yang-pyang-rules "ietf")
 ietf scheme auto-completion syntax-checking better-defaults
 (clojure :variables clojure-enable-fancify-symbols t clojure-enable-sayid t clojure-enable-clj-refactor t clojure-enable-linters
          '(clj-kondo joker))
 gpu graphviz
 (plantuml :variables plantuml-jar-path "~/.plantuml/plantUml.jar" org-plantuml-jar-path "~/.plantuml/plantUml.jar")
 salt ibuffer emacs-lisp pdf
 (org :variables org-want-todo-bindings t org-enable-github-support t org-enable-bootstrap-support t org-enable-reveal-js-support t org-enable-hugo-support t org-enable-trello-support t org-enable-epub-support t org-enable-sticky-header nil)
 (shell :variables shell-enable-smart-eshell nil shell-default-shell 'vterm shell-default-height 30 shell-default-position 'bottom shell-default-full-span nil shell-default-term-shell "/usr/bin/fish")
 version-control import-js
 (cmake :variables cmake-enable-cmake-ide-support t)
 (c-c++ :variables c-c++-default-mode-for-headers 'c++-mode c-c++-backend 'lsp-clangd c-c++-lsp-enable-semantic-highlight 'rainbow c++-enable-organize-includes-on-save t c-c++-lsp-semantic-highlight-method 'overlay c-c++-enable-clang-format-on-save t c-c++-adopt-subprojects t c-c++-enable-auto-newline t)
 web-beautify semantic templates epub themes-megapack git github sml bm
 (copy-as-format :variables copy-as-format-default "markdown" copy-as-format-asciidoc-include-file-name t)
 pass common-lisp
 (python :variables python-backend 'lsp python-lsp-server 'pyls python-test-runner 'pytest python-formatter 'lsp python-format-on-save t python-save-before-test t python-sort-imports-on-save t)
 windows-scripts jr
 (shell-scripts :variables shell-scripts-backend 'lsp)
 prodigy emoji
 (markdown :variables markdown-live-preview-engine 'vmd)
 bibtex
 (json :variables json-fmt-tool 'web-beautify json-fmt-on-save t)
 debug
 (latex :variables latex-enable-auto-fill t latex-enable-magic nil latex-enable-folding t)
 lua html
 (javascript :variables javascript-import-tool 'import-js javascript-backend 'lsp javascript-fmt-tool 'web-beautify javascript-repl 'nodejs js2-basic-offset 2 js-indent-level 2)
 react
 (yaml :variables yaml-enable-lsp t)
 prettier
 (multiple-cursors :variables multiple-cursors-backend 'evil-mc)
 nginx
 (docker :variables docker-dockerfile-backend 'lsp)
 csv search-engine
 (restclient :variables restclient-use-org t)
 restructuredtext selectric octave purescript speed-reading systemd imenu-list
 (java :variables java-backend 'lsp)
 groovy
 (go :variables go-backend 'lsp go-use-golangci-lint t gofmt-command "goimports" go-tab-width 4 go-format-before-save t go-use-gocheck-for-testing t go-use-test-args "-race -timeout 10s" godoc-at-point-function 'godoc-gogetdoc)
 coq django
 (elm :variables elm-sort-imports-on-save t elm-format-on-save t)
 kubernetes idris
 (haskell :variables haskell-completion-backend 'lsp haskell-enable-hindent t haskell-process-type 'stack-ghci)
 pandoc sphinx parinfer asciidoc
 (treemacs :variables treemacs-use-follow-mode t treemacs-use-filewatch-mode t treemacs-collapse-dirs 3 treemacs-use-git-mode 'deferred)
 ansible puppet rust hy xkcd typography vimscript
 (terraform :variables terraform-auto-format-on-save t)
 (ruby :variables ruby-enable-enh-ruby-mode t ruby-backend 'lsp)
 ruby-on-rails asm
 (sql :variables sql-capitalize-keywords t)
 perl6 autohotkey
 (elixir :variables flycheck-elixir-credo-strict t elixir-backend 'lsp)
 faust vagrant erlang
 (dash :variables helm-dash-docset-newpath "~/.local/share/Zeal/Zeal/docsets")
 games php helpful nginx racket
 (colors :variables colors-colorize-identifiers 'all)
 d
 (typescript :variables typescript-backend 'lsp typescript-fmt-tool 'tide typescript-lsp-linter t typescript-linter 'tslint typescript-fmt-on-save t))
markgdawson commented 4 years ago

I still get the same behavior after updating packages and using commit c7af78725732c5ea2cf09c633e19199ee889646d on the spacemacs develop branch.

Starting a blank file, if I type le and pause, I get see len(o) highlighted. If I then press tab to accept the completion, it turns into len($0).

I'm currently using python-language-sever version 0.31.8 and python version 3.7.5

markgdawson commented 4 years ago

It seems that downgrading to 0.30.0 (still with python 3.7.5) solves the issue. Completion now behaves as I expect.

markgdawson commented 4 years ago

Even downgrading to 0.31.7 solves the issue for me. It seems that this is an issue related to latest version (0.31.8) specifically.

Thanks for your input @smile13241324.

smile13241324 commented 4 years ago

@M4rkD great 👍 would you mind opening an upstream issue for this?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

lebensterben commented 3 years ago

Probably fixed upstream, according to https://github.com/palantir/python-language-server/issues/773#issuecomment-633665615

@markgdawson Please help to verify it.

markgdawson commented 3 years ago

@lebensterben unfortunately I stopped using spacemacs quite some time ago. So I don't have a setup in which I can to recreate this.