astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding ruff to vscode editor language status

patillacode opened this issue · comments

Hello!

First of all, I have been using ruff for almost as long as ruff has existed and I am just so grateful. I think lots of people are very happy you created this tool, thanks for that!

To the matter:

Lately I have been trying VSCode and of course the first extension I installed was the ruff-vscode extension

Everything seems to work great, I was just wondering if it is possible to add the ruff console output to be displayed if requested.

Let me elaborate, below you can see in the VSCode menu bar I get a few items under the editor language status (which is under the { } icon)

Screenshot 2023-11-19 at 21 15 15

As you can see I have pinned the black formatter onto the menu bar.

Either by clicking on the "Black Formatter" in the menu bar or in the "Open Logs" link in the editor language status I get the black formatter output :

Screenshot 2023-11-19 at 21 19 17

In the previous screenshot on the top right you can see the output tab for vscode has a dropdown where I can choose the output of what to show, and I can choose ruff in there, which is great.

Screenshot 2023-11-19 at 21 23 07

the question is, how could I add the ruff extension to the editor language status ({ } icon) so it behaves like the black formatter one?

  • appear in the editor language status menu
  • ability to pin it to the menu bar and when clicked open the OUTPUT tab with the dropdown set to ruff

I have asked @vscode and this was the response:

To show the status of the Ruff extension in the editor language status, 
you need to have the Ruff extension installed. If it's not installed, you can use the 
Search marketplace command to search for and install the Ruff extension.

Once the Ruff extension is installed and enabled, it should automatically contribute 
to the editor language status if it has been designed to do so by the extension 
author. If it doesn't show up, it might be that the extension does not support this 
feature.

I know, this is more of a cherry-picking feature more than a "real issue" but I just thought it wouldn't hurt to ask.

thanks again!

Thank you @patillacode for the kind words :)

@karthiknadig -- do you know if there's anything we need to set (that we aren't already) to appear under the editor language status menu?

Although I don't see that same snippet in the template (https://github.com/microsoft/vscode-python-tools-extension-template) so now I'm unsure.

I see, so the ruff extension is missing the showLogs command (this is black's) and the registerLanguageStatusItem (this is black's)

The extension part I think is safe to add, you already have other commands added

As for the registerLanguageStatusItem I think black defines it here

Although status.ts is not in the template, so they basically created a way to achieve what we see.

I wonder why it's not present in the base template though. It's also present in the isort extension. We'll add it!

@charliermarsh we intentionally did not add status item to the template to keep it simple. The status item can be used to trigger commands, Pylance uses it to switch type checking modes.