Ignore source code actions for a notebook cell (#16154)

## Summary

Related to https://github.com/astral-sh/ruff-vscode/pull/686, this PR
ignores handling source code actions for notebooks which are not
prefixed with `notebook`.

The main motivation is that the native server does not actually handle
it well which results in gibberish code. There's some context about this
in
https://github.com/astral-sh/ruff-vscode/issues/680#issuecomment-2647490812
and the following comments.

closes: https://github.com/astral-sh/ruff-vscode/issues/680

## Test Plan

Running a notebook with the following does nothing except log the
message:
```json
  "notebook.codeActionsOnSave": {
    "source.organizeImports.ruff": "explicit",
  },
```

while, including the `notebook` code actions does make the edit (as
usual):
```json
  "notebook.codeActionsOnSave": {
    "notebook.source.organizeImports.ruff": "explicit"
  },
```
This commit is contained in:
Dhruv Manilawala 2025-02-18 10:28:03 +05:30 committed by GitHub
parent b5cd4f2f70
commit 82eae511ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 3 deletions

View file

@ -184,4 +184,15 @@ impl DocumentSnapshot {
pub(crate) fn encoding(&self) -> PositionEncoding {
self.position_encoding
}
/// Returns `true` if this snapshot represents a notebook cell.
pub(crate) const fn is_notebook_cell(&self) -> bool {
matches!(
&self.document_ref,
index::DocumentQuery::Notebook {
cell_url: Some(_),
..
}
)
}
}