ztlevi / doom-config

Blazing fast Doom Emacs private configuration
MIT License
211 stars 31 forks source link

Python 无法自动补全 #3

Closed nehcuh closed 5 years ago

nehcuh commented 5 years ago

RT,MAC 下的Python,用的Pyenv管理环境,环境切换没有问题,但是无法自动补全,知道如何解决么?

ztlevi commented 5 years ago

你用的是lsp-python-ms?如果是lsp-python-ms的话,我就不知道了,我也才刚开始使用。然后在conda环境下也没有任何问题。

如果是lsp-python的话,可能要在pyenv环境下安装pyls,python3 -m pip install --upgrade 'python-language-server[all]' pyls-isort

nehcuh commented 5 years ago

安装过了,自行编译了 Microsoft.Python.Language.Server,无法补全,估计得切换模式才行

ztlevi commented 5 years ago

没太看懂,你现在是系统环境下的python可以补全是吧

nehcuh commented 5 years ago

在其他编辑器,或者直接在 ipython 环境下,都可以补全,但是在 emacs 下无法自动补全

ztlevi commented 5 years ago

你主要看下这边的配置你写对了吗,如果你自己编译了mspyls,这里得改,确保路径什么的都对哈。

最好贴一下自己的配置,不然我也很难帮你看。。。

如果实在不行,那就把def-package! lsp-python-ms这段给删了,用回pyls算了。

记得安装,python3 -m pip install --upgrade 'python-language-server[all]' pyls-isort

nehcuh commented 5 years ago

说明

电脑配置如下:

 系统版本:  macOS 10.14.5 (18F203)
  内核版本: Darwin 18.6.0
  启动宗卷: Macintosh HD

现在的疑问是,无论是 macOS, 亦或是 Ubuntu19.04,Python 无法补全, c-c++ 同样如此,但是编辑 el 文件又可以

init.el


;; Copy this file to ~/.doom.d/init.el or ~/.config/doom/init.el ('doom
;; quickstart' will do this for you). The `doom!' block below controls what
;; modules are enabled and in what order they will be loaded. Remember to run
;; 'doom refresh' after modifying it.
;;
;; More information about these modules (and what flags they support) can be
;; found in modules/README.org.

(doom! :completion
       (company          ; the ultimate code completion backend
        +auto            ; as-you-type code completion
        +childframe      ; a nicer company UI (Emacs 26+ only)
        )
       ;;(helm             ; the *other* search engine for love and life
       ;;+fuzzy)          ; enable fuzzy search backend for helm
       ;;ido               ; the other *other* search engine...
       (ivy              ; a search engine for love and life
        +icons
        +prescient
        +childframe)

       :ui
       ;;deft              ; notational velocity for Emacs
       doom              ; what makes DOOM look the way it does
       doom-dashboard    ; a nifty splash screen for Emacs
       doom-quit         ; DOOM quit-message prompts when you quit Emacs
       ;;fill-column       ; a `fill-column' indicator
       hl-todo           ; highlight TODO/FIXME/NOTE tags
       ;; indent-guides     ; highlighted indent columns
       modeline          ; snazzy, Atom-inspired modeline, plus API
       nav-flash         ; blink the current line after jumping
       ;;neotree           ; a project drawer, like NERDTree for vim
       ophints           ; highlight the region an operation acts on
       (popup            ; tame sudden yet inevitable temporary windows
        +all             ; catch all popups that start with an asterix
        +defaults)       ; default popup rules
       ;;pretty-code       ; replace bits of code with pretty symbols
       ;;tabbar            ; FIXME an (incomplete) tab bar for Emacs
       treemacs          ; a project drawer, like neotree but cooler
       ;;unicode           ; extended unicode support for various languages
       vc-gutter         ; vcs diff in the fringe
       vi-tilde-fringe   ; fringe tildes to mark beyond EOB
       window-select     ; visually switch windows
       workspaces        ; tab emulation, persistence & separate workspaces

       :editor
       (evil +everywhere); come to the dark side, we have cookies
       file-templates    ; auto-snippets for empty files
       fold              ; (nigh) universal code folding
       (format +onsave)  ; automated prettiness
       lispy             ; vim for lisp, for people who dont like vim
       multiple-cursors  ; editing in many places at once
       ;;parinfer          ; turn lisp into python, sort of
       rotate-text       ; cycle region at point between text candidates
       snippets          ; my elves. They type so I don't have to

       :emacs
       (dired            ; making dired pretty [functional]
        +ranger          ; bringing the goodness of ranger to dired
        +icons)          ; colorful icons for dired-mode
       electric          ; smarter, keyword-based electric-indent
       vc                ; version-control and Emacs, sitting in a tree

       :term
       eshell            ; a consistent, cross-platform shell (WIP)
       ;;term              ; terminals in Emacs
       vterm             ; another terminals in

       :tools
       ;;ansible
       ;;debugger          ; FIXME stepping through code, to help you add bugs
       direnv
       docker
       editorconfig      ; let someone else argue about tabs vs spaces
       ein               ; tame Jupyter notebooks with emacs
       eval              ; run code, run (also, repls)
       (flycheck
        +childframe)     ; tasing you for every semicolon you forget
       flyspell          ; tasing you for misspelling mispelling
       ;;gist              ; interacting with github gists
       (lookup           ; helps you navigate your code and documentation
        +devdocs         ; ...on devdocs.io online
        +docsets)        ; ...or in Dash docsets locally
       lsp
       macos             ; MacOS-specific commands
       magit             ; a git porcelain for Emacs
       make              ; run make tasks from Emacs
       ;;password-store    ; password manager for nerds
       pdf               ; pdf enhancements
       prodigy           ; FIXME managing external services & code builders
       rgb               ; creating color strings
       ;;terraform         ; infrastructure as code
       tmux              ; an API for interacting with tmux
       upload            ; map local to remote projects via ssh/ftp
       ;;wakatime

       :lang
       ;;agda              ; types of types of types of types...
       ;;assembly          ; assembly for fun or debugging
       (cc +lsp)           ; C/C++/Obj-C madness
       ;;clojure           ; java with a lisp
       ;;common-lisp       ; if you've seen one lisp, you've seen them all
       ;;coq               ; proofs-as-programs
       ;;crystal           ; ruby at the speed of c
       ;;csharp            ; unity, .NET, and mono shenanigans
       data              ; config/data formats
       ;;erlang            ; an elegant language for a more civilized age
       ;;elixir            ; erlang done right
       ;;elm               ; care for a cup of TEA?
       emacs-lisp        ; drown in parentheses
       ;;ess               ; emacs speaks statistics
       (go +lsp)                ; the hipster dialect
       ;;(haskell +intero) ; a language that's lazier than I am
       ;;hy                ; readability of scheme w/ speed of python
       ;;idris             ;
       (java +lsp)                       ; the poster child for carpal tunnel syndrome ;(java +meghanada)
       javascript        ; all(hope(abandon(ye(who(enter(here))))))
       ;;julia             ; a better, faster MATLAB
       kotlin            ; a better, slicker Java(Script)
       latex             ; writing papers in Emacs has never been so fun
       ;;ledger            ; an accounting system in Emacs
       ;;lua               ; one-based indices? one-based indices
       markdown          ; writing docs for people to ignore
       ;;nim               ; python + lisp at the speed of c
       ;;nix               ; I hereby declare "nix geht mehr!"
       ;;ocaml             ; an objective camel
       (org              ; organize your plain life in plain text
        +attach          ; custom attachment system
        +babel           ; running code in org
        +capture         ; org-capture in and outside of Emacs
        +export          ; Exporting org to whatever you want
        +habit           ; Keep track of your habits
        +present         ; Emacs for presentations
        +protocol)       ; Support for org-protocol:// links
       ;;perl              ; write code no one else can comprehend
       ;;php               ; perl's insecure younger brother
       ;;plantuml          ; diagrams for confusing people more
       ;;purescript        ; javascript, but functional
       (python
        +pyenv
        +conda
        +lsp)            ; beautiful is better than ugly
       qt                ; the 'cutest' gui framework ever
       ;;racket            ; a DSL for DSLs
       ;;rest              ; Emacs as a REST client
       ;;ruby              ; 1.step do {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
       rust              ; Fe2O3.unwrap().unwrap().unwrap().unwrap()
       ;;scala             ; java, but good
       sh                ; she sells (ba|z)sh shells on the C xor
       ;;solidity          ; do you need a blockchain? No.
       ;;swift             ; who asked for emoji variables?
       ;;terra             ; Earth and Moon in alignment for performance.
       web               ; the tubes
       ;;vala              ; GObjective-C

       ;; Applications are complex and opinionated modules that transform Emacs
       ;; toward a specific purpose. They may have additional dependencies and
       ;; should be loaded late.
       :app
       ;;(email +gmail)    ; emacs as an email client
       ;;irc               ; how neckbeards socialize
       ;;(rss +org)        ; emacs as an RSS reader
       ;;twitter           ; twitter client https://twitter.com/vnought
       (write            ; emacs as a word processor (latex + org + markdown)
       +wordnut         ; wordnet (wn) search
       +langtool)       ; a proofreader (grammar/style check) for Emacs

       :collab
       ;;floobits          ; peer programming for a price
       ;;impatient-mode    ; show off code over HTTP

       :config
       ;; For literate config users. This will tangle+compile a config.org
       ;; literate config in your `doom-private-dir' whenever it changes.
       ;;literate

       ;; The default module sets reasonable defaults for Emacs. It also
       ;; provides a Spacemacs-inspired keybinding scheme and a smartparens
       ;; config. Use it as a reference for your own modules.
       (default +bindings +snippets +smartparens)

       :private
       ;; lsp-intellij
       )
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (async quelpa use-package persistent-soft))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

2. config.el


(load! "+os")
(load! "+misc")
(load! "+text")
(load! "+prog")
(load! "+ui")
(load! "+bindings")

(setq doom-scratch-buffer-major-mode 'emacs-lisp-mode)

(setq-default fill-column 100
              delete-trailing-lines t)

;; Delete the selection when pasting
(delete-selection-mode 1)

;; disable risky local variables warning
(advice-add 'risky-local-variable-p :override #'ignore)

;; check minified-file
(add-to-list 'magic-mode-alist (cons #'+my/check-minified-file 'fundamental-mode))

(set-popup-rules! '(("^\\*helpful" :size 0.35)
                    ("^\\*Ibuffer\\*$" :size 0.35)
                    ("^\\*info.*" :size 80 :side right)
                    ("^\\*Man.*" :size 80 :side right)
                    ("^\\*Customize" :actions display-buffer)
                    ("^\\*edit-indirect" :size 0.6)
                    ("^\\*YASnippet Tables\\*$" :size 0.35)
                    ("^\\*grep\\*$" :size 0.35)
                    ("^\\*Anaconda\\*$" :size 0.35)
                    ("^\\*helm kill ring\\*$" :size 0.35)
                    ((lambda (buf _) (with-current-buffer buf (eq major-mode 'forge-topic-mode))) :size 0.35)
                    ))

;; Load system profile for different machines
(let ((profile "~/.config/doom/profile.el"))
  (when (file-exists-p profile)
    (load-file profile)))
ztlevi commented 5 years ago

c++需要编译ccls,follow这里,python的话我用的直接是vscode编译过的mspyls。就是用你的vscode安装python plugin然后打开一个python 文件,然后mspyls就编译好了。接下来fd就会找executable,所以你需要再安装下fd, brew install fd

nehcuh commented 5 years ago

并没有用,ccls已经安装过了,对于 Python,哪怕自行编译 Microsoft.Language.Server 并手动指定 ms-python-lsp 的位置,一样无法自动补全,😌

nehcuh commented 5 years ago

自定义执行路径如下,并不能自动补全,很神奇,为了测试,使用Centaur Emacs的配置,它的补全不会有问题

lsp-python-ms-executable is a variable defined in lsp-python-ms.el.

Value
"/Users/huchen/.vscode/extensions/python-language-server/output/obj/Microsoft.Python.LanguageServer/netcoreapp2.2/osx.10.14-x64/host/Microsoft.Python.LanguageServer"
lsp-python-ms-dir is a variable defined in lsp-python-ms.el.

Value
"/Users/huchen/.vscode/extensions/python-language-server/output/bin/Release/"
ztlevi commented 5 years ago

你是不是vscode的plugin没更新啊,我这边osx的python plugin路径跟你的不太一样。

然后现在安装编译和更新都已经集成到lsp-python-ms里了,你更新下这个plugin,然后M-x吧。

ccls project setup 参考这里

nehcuh commented 5 years ago

全部重新安装了,今晚突然发现正常了,回想了下过程,可能是因为emacs打开 Python 代码停留时间太长了,结果居然就正常了,不知道原因为何