tomv564 / pyls-mypy

Mypy plugin for the Python Language Server
MIT License
110 stars 62 forks source link

pyls-mypy should use the :rootUri parameter to find the configuration file #9

Closed nilehmann closed 5 years ago

nilehmann commented 6 years ago

lsp-mode for emacs runs pyls in the directory of the first file visited in a project. If this directory is not the root of the project mypy will fail to find the configuration file. Using the :rootUri parameter we could either change the current working directory before running mypy or try to find the configuration file and pass it as an argument to mypy.

I also reported this in lsp-mode https://github.com/emacs-lsp/lsp-mode/issues/319

tomv564 commented 6 years ago

Thanks for reporting, great to hear this plugin working for Emacs users!

Although workspace is passed into pyls-mypy (exposing a root_path member), I am a bit unsure how it should improve your situation.

We use mypy as a library, so there is no mypy process to set a working directory on.

try to find the configuration file and pass it as an argument to mypy.

This is probably doable, but reading https://github.com/python/mypy/issues/3377 I get the impression mypy expects to be run from the project root.

Taking mypy_ini_path as a config option from lsp-mode through pyls feels safer in that case, at least the user will be aware of the problem when they have to manually specify the config file.

Is there some design limitation preventing lsp-mode from changing to rootPath itself before starting pyls?

nilehmann commented 6 years ago

By using rootUri I meant doing a os.chdir before calling mypy, but that doesn't feel right. The configurable path seems like a better option. Yet another solution could be calling mypy in a different process.

Anyway, it feels strange fixing the problem here the way the plugin is implemented, that's why I reported the issue in lsp-mode in the first place. I don't know if this can be fixed in lsp-mode or not.

tomv564 commented 5 years ago

I don't have any time to work on this. But feel free to open a PR with a workaround!

gdiv commented 5 years ago

@nilehmann

lsp-mode for emacs runs pyls in the directory of the first file visited in a project

This can be fixed by


  (lsp-define-stdio-client lsp-python "python"
                           #'projectile-project-root
                           '("pyls"))

  (add-hook 'python-mode-hook
            (lambda ()
          (let ((root (projectile-project-root)))
        (if root
            (progn
              (cd root)
              (lsp-python-enable))))))