reddit / emacs

Setting up snippets and auto completion with lsp-mode and pyright

exceta · 2022-08-24 18:38
Hi, I am trying to get a simple Python setup working in Emacs. I have gotten auto completion to work but not to the extent where it will add parenthesis, insert the arguments, and allow me to select between them. I believe this should work (requires integration with yasnippet?) since I can see on the bottom of Emacs that on completion Pyright provides the function information e.g. `import gc gc.collect` shows `(function) collect: (generation: int = ...) -> int` init.el (setq custom-file (concat user-emacs-directory "custom.el")) (when (file-exists-p custom-file) (load custom-file)) (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (package-initialize) (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (require 'use-package) (setq use-package-always-defer t use-package-always-ensure t) (use-package company :hook (lsp-mode . company-mode) :config (global-company-mode)) (use-package flycheck :init (global-flycheck-mode)) (use-package lsp-mode :commands (lsp lsp-deferred) :init (setq lsp-keymap-prefix "C-c l") :config (lsp-enable-which-key-integration t) :hook (python-mode . lsp-deferred)) (use-package lsp-pyright :hook (python-mode . (lambda () (require 'lsp-pyright) (lsp-deferred)))) (use-package lsp-ui :commands lsp-ui-mode) (use-package python-mode) (use-package which-key :config (which-key-mode)) (use-package yasnippet :config (yas-global-mode t)) (use-package yasnippet-snippets)
cradlemann · 2022-08-24 20:32
The completion does not work fine and inserts arguments and placeholders, what I am doing wrong?# make sure you have installed yasnippet and you have yasnippet minor mode enabled. https://emacs-lsp.github.io/lsp-mode/page/faq/#the-completion-does-not-work-fine-and-inserts-arguments-and-placeholders-what-i-am-doing-wrong
exceta · 2022-08-24 21:58
yas-global-mode is set to on which has the same result as minor mode. I have tested the following: (use-package yasnippet :hook (lsp-mode . yas-minor-mode)) (use-package yasnippet-snippets :config (yas-reload-all)) I was able to get yasnippets integration working with (use-package company :init (setq company-backends `((:separate company-capf company-yasnippet)) :config (setq lsp-completion-provider :none)) But this does not give me any more than just built in yasnippets e.g. p expands to print() with the cursor in between the parenthesis. It does not provide autocompletion for my own function `def test(i,j,k): return None`
cradlemann · 2022-08-25 04:58
Maybe pyright does not support placeholders?