astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
946 stars 45 forks source link

The ruff VSCode extension doesn't appear to function in a particular VSCode dev-extension environment (works in "default" environment) #432

Closed wolfch-elsevier closed 3 months ago

wolfch-elsevier commented 3 months ago

Here's a simple piece of contrived code:

from requests import ReadTimeout, Request, Response, Timeout, TooManyRedirects
from sys import argv
import logging
import os

def main() -> None:
    pass

In the first case, I wanted the extension to perform the equivalent of isort, so in VSCode, I invoke Shift-Command-P (MacOs) and from the list: Ruff: Format Imports ...nothing happens - the code doesn't change.

Then, from the command line, I invoke: ruff check --fix --select I roughruff.py ...where roughtruff.py is the quoted code above and this time, it gets changed to:

import logging
import os
from sys import argv

from requests import ReadTimeout, Request, Response, Timeout, TooManyRedirects

def main() -> None:
    pass

So ruff can successfully replace isort but only via the command line - the VSCode extension doesn't work.

charliermarsh commented 3 months ago

Can you share any relevant logging from VS Code? There isn't much to go off in the write-up above. I'm referring to this pane:

Screenshot 2024-03-16 at 10 17 28 AM

You should be able to access it by clicking "Ruff" here from a Python file, though it may vary based on how your VS Code is configured:

Screenshot 2024-03-16 at 10 17 24 AM

wolfch-elsevier commented 3 months ago

Wow - thanks for the timely reply! I look at the bottom strip and only see:

Screenshot 2024-03-22 at 12 47 55 AM

I don't see "Ruff"; I do see a warning, "Select Interpreter" but when invoke Shift-Command-P, it shows the "Selected Interpeter" to be:

Screenshot 2024-03-22 at 12 48 46 AM

...which is correct. I should mention this is running inside of a dev-container (sorry, I should have made that clear initially)

charliermarsh commented 3 months ago

Could you try opening the log file from the command palette instead, like this?

Screenshot 2024-03-22 at 12 56 59 AM

Screenshot 2024-03-22 at 12 57 01 AM

wolfch-elsevier commented 3 months ago

Wait - I needed to select "Ruff" from the "Output" drop-down

Screenshot 2024-03-22 at 12 58 16 AM
wolfch-elsevier commented 3 months ago

I re-tried "Select Interpreter" which select the default (not correct in terms of installed dependencies) but this tine the Ruff VSCode extension works - see the attached log. ruff.log

but I expected it to work with the selected hatch environment. Let me change the title of this issue - and offer my apologies.. this dev-container concept is a bit difficult.

wolfch-elsevier commented 3 months ago

Oh God - it totally works in the dev-container - sorry!. However: I have some caveats for people looking to use this extension in a VSCode dev-container. If you have a monorepo with each service having a corresponding hatch environment other than default, you need to insure that the ruff dependency is declared and installed in the particular hatch environment you are using.

wolfch-elsevier commented 3 months ago

The use-case was specific to using within a dev-container which lead to the false belief it was not working.

charliermarsh commented 3 months ago

Glad to see it resolved, sorry you ran into trouble!