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

Workspace edits from ruff server commands occasionally fail in VS Code when operating on an yet-to-be-created file #11248

Closed
snowsignal opened this issue May 2, 2024 · 2 comments
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@snowsignal
Copy link
Contributor

Steps to reproduce:

  1. Disable VS Code auto-save.
  2. Add ALL to the select setting in the extension
  3. Create a new .py file, but don't save it yet.
  4. Add this code to the file:
import foo

def bar():
    unused = 4
  1. Using the command palette (Ctrl/Cmd+Shift+P), repeatedly run ruff.applyAutofix.
  2. The second time you run applyAutofix, you should see an error about a workspace edit that couldn't be applied.
@snowsignal snowsignal added bug Something isn't working server Related to the LSP server labels May 2, 2024
@snowsignal snowsignal self-assigned this May 2, 2024
snowsignal added a commit that referenced this issue May 21, 2024
## Summary

Closes #10858.

`ruff server` now supports `*.ipynb` (aka Jupyter Notebook) files.
Extensive internal changes have been made to facilitate this, which I've
done some work to contextualize with documentation and an pre-review
that highlights notable sections of the code.

`*.ipynb` cells should behave similarly to `*.py` documents, with one
major exception. The format command `ruff.applyFormat` will only apply
to the currently selected notebook cell - if you want to format an
entire notebook document, use `Format Notebook` from the VS Code context
menu.

## Test Plan

The VS Code extension does not yet have Jupyter Notebook support
enabled, so you'll first need to enable it manually. To do this,
checkout the `pre-release` branch and modify `src/common/server.ts` as
follows:

Before:
![Screenshot 2024-05-13 at 10 59
06 PM](https://github.com/astral-sh/ruff/assets/19577865/c6a3c604-c405-4968-b8a2-5d670de89172)

After:
![Screenshot 2024-05-13 at 10 58
24 PM](https://github.com/astral-sh/ruff/assets/19577865/94ab2e3d-0609-448d-9c8c-cd07c69a513b)

I recommend testing this PR with large, complicated notebook files. I
used notebook files from [this popular
repository](https://github.com/jakevdp/PythonDataScienceHandbook/tree/master/notebooks)
in my preliminary testing.

The main thing to test is ensuring that notebook cells behave the same
as Python documents, besides the aforementioned issue with
`ruff.applyFormat`. You should also test adding and deleting cells (in
particular, deleting all the code cells and ensure that doesn't break
anything), changing the kind of a cell (i.e. from markup -> code or vice
versa), and creating a new notebook file from scratch. Finally, you
should also test that source actions work as expected (and across the
entire notebook).

Note: `ruff.applyAutofix` and `ruff.applyOrganizeImports` are currently
broken for notebook files, and I suspect it has something to do with
#11248. Once this is fixed, I
will update the test plan accordingly.

---------

Co-authored-by: nolan <nolan.king90@gmail.com>
@T-256
Copy link
Contributor

T-256 commented May 28, 2024

I can't repro this in v0.4.5. If you are still able to repro this, could you also provide the logs?

@snowsignal
Copy link
Contributor Author

@T-256 I think this was fixed in #11206. 😄

The only caveat is that this fix involve omitting document versions from workspace edits, which I would like to add back eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

No branches or pull requests

2 participants