Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get mypy to start from LSP-pylsp #9

Closed
StabbarN opened this issue Jun 12, 2021 · 9 comments
Closed

Can't get mypy to start from LSP-pylsp #9

StabbarN opened this issue Jun 12, 2021 · 9 comments

Comments

@StabbarN
Copy link

StabbarN commented Jun 12, 2021

I want to enable mypy (preferably dmypy) with Sublime and LSP-pylsp but I can't get mypy to run.
Linting and formatting in Sublime works fine.

My sublime-project file:

{
	...
	"settings":
	{
        "python_interpreter": "/Users/me/code/proj/.venv/bin/python",
	}
}

My LSP-pylsp.sublime-settings:

{
	"settings": {
        "pylsp.plugins.mypy_ls.enabled": true,
		...
    }
}

I've tried setting live_mode to true or false: "pylsp.plugins.mypy-ls.live_mode": true,

I've tried creating a mypy-ls.cfg file in my project's root with the following content but to no avail:
cat mypy-ls.cfg

{
    "enabled": True,
    "live_mode": False,
    "dmypy": True,
    "strict": False
}

Executing dmypy (and mypy) from terminal works fine.
When I have opened sublime dmypy isn't started dmypy status says "No status file found". So it seems that dmypy isn't started.

In Sublime I've set log_server": ["panel"] and checked what's sent to pylsp but it seems fine.

ls .venv
_pyenv_version bin            include        lib            pyvenv.cfg     share
which mypy
/Users/me/code/proj/.venv/bin/mypy
which dmypy
/Users/me/code/proj/venv/bin/dmypy

Please advice what more I can do to debug this.

@Richardk2n
Copy link
Member

There seems to be some ambiguity weather mypy_ls or mypy-ls works for the config (meaning try "pylsp.plugins.mypy-ls.enabled": true,)

Can you confirm other plugins run?

Can you confirm weather mypy-ls is started and misbehaving or if it is not even started?

@StabbarN
Copy link
Author

StabbarN commented Jun 12, 2021

There seems to be some ambiguity weather mypy_ls or mypy-ls works for the config (meaning try "pylsp.plugins.mypy-ls.enabled": true,)

Changing to "pylsp.plugins.mypy-ls.enabled": true, didn't help me.

Can you confirm other plugins run?

Other plugins run excellent, such as:

        "pylsp.configurationSources": [
            "flake8"
        ],
        "pylsp.plugins.flake8.enabled": true,
        "pylsp.plugins.pyls_isort.enabled": true,
        "pylsp.plugins.pylsp_black.enabled": true,

Can you confirm weather mypy-ls is started and misbehaving or if it is not even started?

I don't know how to check if it starts. I can't see any difference after mypy-ls has been set to enabled. I want to help but don't know where to look.

@jordaneremieff
Copy link

@StabbarN What does your LSP.sublime-settings file look like? I came across this ticket when I was having similar problems getting live mode to work.

I initially tried defining the settings in LSP-pylsp.sublime-settings, but it was only when I included the settings in LSP.sublime-settings that it started working:

// Settings in here override those in "LSP/LSP.sublime-settings"
{
    "clients": {
        "pylsp": {
            "enabled": true,
            "selector": "source.python",
            "command": [
                "path/to/.venv/bin/pylsp",
            ],
            "settings": {
                "pylsp.plugins.mypy_ls.enabled": true,
                "pylsp.plugins.mypy-ls.live_mode": true
            }
        }
    }
}

I didn't really dig into the reasons why one would work but the other would not, just sharing in case this might help.

@rchl
Copy link

rchl commented Jun 14, 2021

My sublime-project file:

I'm not sure what that python_interpreter setting is supposed to affect. It doesn't have anything to do with LSP-pylsp at least.

If you want pylsp to use your virtual environment then follow https://github.com/sublimelsp/LSP-pylsp#virtual-environments

To enable mypyls a settings like:

// Settings in here override those in "LSP-pylsp/LSP-pylsp.sublime-settings"
{
    "settings": {
        "pylsp.plugins.mypy_ls.enabled": true,
        "pylsp.plugins.mypy-ls.live_mode": false,
    }
}

should work. live_mode shouldn't be relevant but I'm fairly sure that live_mode has issues with locating types from imported files in some cases.

With a code like:

def test(a: str) -> None:
    pass


test(1)

do you not see an error like:
Screenshot 2021-06-14 at 17 46 06

(remember to save the file if you have live_mode disabled.

@StabbarN
Copy link
Author

Setup as

// Settings in here override those in "LSP/LSP.sublime-settings"
{
    "clients": {
        "pylsp": {
            "enabled": true,
            "selector": "source.python",
            "command": [
                "path/to/.venv/bin/pylsp",
            ],
            "settings": {
                "pylsp.plugins.mypy_ls.enabled": true,
                "pylsp.plugins.mypy-ls.live_mode": true
            }
        }
    }
}

seems to work after a quick test.

I've a lot of other stuffs going right now. I'll hopefully do more testing and verification in a few days.
Thanks for your help so far!

@rchl
Copy link

rchl commented Jun 15, 2021

The only reason I can think of why this would work better for you is because you are running pylsp from your virtual environment. When using the LSP-pylsp package, the pylsp runs from package storage directory somewhere in user home directory. That's why when using LSP-pylsp you are supposed to follow https://github.com/sublimelsp/LSP-pylsp#virtual-environments to configure your project to use the python venv.

@Richardk2n
Copy link
Member

It looks like you found a way, that works for you, and mypy-ls did not cause this issue. Is that correct? (Meaning can I close this now?)

@StabbarN
Copy link
Author

I haven't verified it yet but my problem is probably that I haven't installed Python LSP Server manually as described at https://yeray.dev/python/setting-up-sublime-text-4-for-python#manual-setup

I was planning to install it manually and then close this issue.

Yes, this issue can be closed.

Thank you for all responses!

@rchl
Copy link

rchl commented Jun 25, 2021

There was a recent related change made that might have fixed the original issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants