Stale Diagnostics After Multi-File Edits via VS Code API
vscodeawaiting response
### Description
## Summary
When GitHub Copilot edits files using VS Code's workspace edit API (via `multi_replace_string_in_file`), basedpyright fails to re-check cross-file type dependencies, leaving stale diagnostics in unchanged dependent files. The diagnostics continue to reflect the old state of the dependency even after it has been modified.
This causes confusion when using GitHub Copilot, as it checks diagnostics after making edits and may see stale errors that appear to indicate the changes were incorrect, leading to unnecessary debugging and corrections of actually-correct code.
## Environment
- **VS Code**: 1.112.0
- **Basedpyright Extension**: 1.38.3
- **Python Version**: 3.14
## Reproduction Steps
### Setup
Create two Python files with a cross-file type dependency:
**a.py**:
```python
def x() -> str:
return "not a number"
```
**b.py**:
```python
from a import x
n: int
n = x()
```
At this point, basedpyright correctly reports a type error in `b.py` line 4:
```
Type "str" is not assignable to declared type "int"
```
### Trigger the Bug
1. Ensure basedpyright detects the error in `b.py` line 4
2. Have GitHub Copilot (or any probably any tool using VS Code's workspace edit API) edit **only a.py** using `multi_replace_string_in_file`
3. The edit fixes the type error by changing the return type:
```python
def x() -> int:
return 42
```
4. **Do not** edit `b.py` in the same operation
### Expected Behavior
Basedpyright should detect the change to `a.py` and re-check `b.py`. The error on line 4 should disappear since `x()` now returns `int`, which is assignable to `n: int`.
### Actual Behavior
The basedpyright diagnostic in `b.py` sometimes remains at line 4:
```
Type "str" is not assignable to declared type "int"
```
The diagnostic is stale - it still shows the error even though the dependency has been fixed and the assignment is now correct.
**Note**: This bug is somewhat intermittent. Sometimes basedpyright correctly updates the diagnostics after the multi-file edit, but in my experience it usually fails to do so, leaving stale diagnostics.
### Workaround
Manually saving `b.py` with some changes (e.g., adding a trailing space) triggers basedpyright to re-check the file and clear the stale diagnostic.
## Additional Notes
- When the **dependent file itself is included** in the multi-file edit, basedpyright updates correctly
1 条评论