2

I am using lsp under Python.lsp does not start when a Python file is opened, I have to do M-x lsp for each file I open. Also when I switch from find-file to another file I have to do M-x lsp all over again.

I have followed: https://emacs-lsp.github.io/lsp-mode/page/installation/

(require 'lsp-mode)
(add-hook 'python-mode-hook 'lsp)
(add-hook 'python-mode-hook #'lsp-deferred)

What may be the reason for this? Is there any way to force lsp to start on all Python file whenever I open them?


I observe that when I start running emacs in the ibuffer there is python files that are located under the parent folder where those won't run LSP when I open them. But when I open another file in sub-folder it loads LSP by defualt.

example

  • emacs -nw ~/home.py and do M-x find-file ~/repo/work.py => lsp than M-x find-file ~/repo/work1.py ; lsp is enabled automatically right away.

  • But if I do emacs -nw ~/repo/work.py ; than M-x find-file ~/repo/work1.py ; lsp is not enabled by default for both.


I have following files all has import os in it. I am coming on top of os and do xref-find-definitions.

~/file1.py

.repo
├── file1.py
├── file2.py
└── file3.py

I do emacs -nw ~/file1.py and find-file repo/file1.py and LSP works. But afterwards when I do find-file to repo/file2.py now it does not :-(

Drew
  • 75,699
  • 9
  • 109
  • 225
alper
  • 1,238
  • 11
  • 30
  • Does LSP not prompt you to import the project when you invoke lsp on a single file? LSP should start automatically for all files once you import the project in to the workspace. – Swarnendu Biswas Mar 10 '21 at 02:46
  • You can also invoke `lsp-workspace-folders-add` to achieve the same effect. – Swarnendu Biswas Mar 10 '21 at 03:37
  • Can it add the base folder by default when emacs starts? I have tried `lsp-workspace-folders-add` but still when I open another file using `find-file` I have to run `lsp` to enable it again. – alper Mar 10 '21 at 08:16
  • Seems like when I open `emacs` python folders in the base folder already open within and they won't load `LSP` by default – alper Mar 10 '21 at 08:39
  • Like I do `emacs -nw ~/hello.py` than `find-file` to ~/repo/work.py it works. But if I do `emacs -nw ~/repo/work.py` it does not work – alper Mar 10 '21 at 08:50
  • Could try moving `~/hello.py` and others into another subdirectory under `$HOME` and then try? If I import a lsp project, then `A/B/*.py`, `A/*.py`, and `A/C/*.cpp` (say) all work automatically. – Swarnendu Biswas Mar 10 '21 at 13:42
  • Please see my updated question where what I tried – alper Mar 10 '21 at 13:50
  • Please see my updated question where what I tried. I feel like some settings in my init.el like elpy or jedi may cause this. – alper Mar 10 '21 at 14:24
  • I am not not sure what could the exact reason be. Sharing an MWE might help. Otherwise, you could try filing a bug on the LSP page at GitHub. – Swarnendu Biswas Mar 10 '21 at 17:23
  • 1
    @alper, if you really want to use lsp, then wipe out everything related to elpy and jedi (jedi.el I mean; jedi python module should be in your python installation). python-language-server uses jedi python module. – Ian Mar 11 '21 at 08:10
  • In order to wipe out can I do `M-x package-delete ` and `elpy* jedi*` ? In my `.emacs` file there is some functions related to `elpy and jedi` I will also remove them – alper Mar 11 '21 at 09:11
  • @Ian I was using jedi for auto-complete suggestions, can lsp provide the same functionality? – alper Mar 11 '21 at 09:41
  • Ref: elpy* - I don't know. Ref autocompletion, just copy-paste the ```(use-package company...)``` from ```emacs-rust-config``` folder, hope you still have it. It is a very good configuration and works with lsp. – Ian Mar 11 '21 at 11:56
  • @Ian Thanks well after few days of work and some luck I think I was able to make it work. `emacs-rust-config` is golden rope, I have tried to merge it with my own configuration (where I just appended added my init.el file on top of it and remove `elpy` `jedi` like you suggessted). // https://github.com/avatar-lavventura/dotfiles/blob/main/init_alper.el – alper Mar 11 '21 at 14:22

0 Answers0