2

I am using lsp-pyright[1] module in doom Emacs for Python major mode. Local imports from my project are not recognized by lsp server.

I have created a pyrightconfig.json file in root directory of my folder but still issue is not resolved.

How to i tell lsp to read json config from my project root folder ?

Digvijay S
  • 121
  • 1
  • 3

2 Answers2

2

You can include additional Python source paths with lsp-pyright-extra-paths. Here is my pyrightconfig.json for a project.

{
  "exclude": ["**/node_modules", "**/__pycache__"],
  "ignore": ["**/node_modules", "**/__pycache__"],
  "include": ["flextensor", "tvm"]
  "pythonPlatform": "Linux",
  "pythonVersion": "3.6",
  "reportMissingImports": true,
  "reportMissingTypeStubs": false,
  "stubPath": "typings",
  "typeCheckingMode": "basic",
  "venvPath": "/home/swarnendu/tmp/virtualenvs",
  "venv": "flextensor-venv"
}

Here is my Emacs setup (init.el) for pyright (ignoring remote Tramp setup). You could also use use-package for this.

  (when (executable-find "pyright")
    (unless (fboundp 'lsp-pyright-locate-python)
      (autoload #'lsp-pyright-locate-python "lsp-pyright" nil t))
    (unless (fboundp 'lsp-pyright-locate-venv)
      (autoload #'lsp-pyright-locate-venv "lsp-pyright" nil t))

    (add-hook 'python-mode-hook (lambda ()
                                  (require 'lsp-pyright)
                                  (lsp-deferred)))

    (defvar lsp-pyright-python-executable-cmd)
    (setq lsp-pyright-python-executable-cmd "python3")))

Here is the .dir-locals.el for the same project.

(
 (python-mode . (
                 (pyvenv-activate . "/home/swarnendu/tmp/virtualenvs/flextensor-venv")
                 (eval . (let (
                               (paths
                                (vconcat (list
                                          (expand-file-name "flextensor" (projectile-project-root))
                                          (expand-file-name "tvm" (projectile-project-root))
                                          ))))
                           (setq lsp-pyright-extra-paths paths)))
                 ))
 )

Please check whether a similar setup works for you.

Swarnendu Biswas
  • 1,378
  • 1
  • 11
  • 24
0

Have you checked if your pyrightconf.json file is actually found ?

You can check by skimming the log buffer for the lsp session

C-x C-b should give you a list of buffers

You can look for "window" as a keyword. In fact if the file is found or not is sent by the server in a "window" type message

  1. If your conf file is found, than it's a matter of properly filling it in
  2. If it's not, it's a matter of adding/removing roots from your lsp session (lsp-workspace-folder-add/remove)
user1632812
  • 155
  • 3