mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-27 02:16:54 +00:00
[ty] Track open files in the server (#19264)
## Summary This PR updates the server to keep track of open files both system and virtual files. This is done by updating the project by adding the file in the open file set in `didOpen` notification and removing it in `didClose` notification. This does mean that for workspace diagnostics, ty will only check open files because the behavior of different diagnostic builder is to first check `is_file_open` and only add diagnostics for open files. So, this required updating the `is_file_open` model to be `should_check_file` model which validates whether the file needs to be checked based on the `CheckMode`. If the check mode is open files only then it will check whether the file is open. If it's all files then it'll return `true` by default. Closes: astral-sh/ty#619 ## Test Plan ### Before There are two files in the project: `__init__.py` and `diagnostics.py`. In the video, I'm demonstrating the old behavior where making changes to the (open) `diagnostics.py` file results in re-parsing the file: https://github.com/user-attachments/assets/c2ac0ecd-9c77-42af-a924-c3744b146045 ### After Same setup as above. In the video, I'm demonstrating the new behavior where making changes to the (open) `diagnostics.py` file doesn't result in re-parting the file: https://github.com/user-attachments/assets/7b82fe92-f330-44c7-b527-c841c4545f8f
This commit is contained in:
parent
ba7ed3a6f9
commit
99d0ac60b4
22 changed files with 220 additions and 140 deletions
|
|
@ -16,10 +16,10 @@ use ruff_source_file::{LineIndex, OneIndexed, SourceLocation};
|
|||
use ruff_text_size::{Ranged, TextSize};
|
||||
use ty_ide::signature_help;
|
||||
use ty_ide::{MarkupKind, goto_type_definition, hover, inlay_hints};
|
||||
use ty_project::ProjectMetadata;
|
||||
use ty_project::metadata::options::Options;
|
||||
use ty_project::metadata::value::ValueSource;
|
||||
use ty_project::watch::{ChangeEvent, ChangedKind, CreatedKind, DeletedKind};
|
||||
use ty_project::{CheckMode, ProjectMetadata};
|
||||
use ty_project::{Db, ProjectDatabase};
|
||||
use ty_python_semantic::Program;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
|
@ -76,7 +76,11 @@ impl Workspace {
|
|||
let project = ProjectMetadata::from_options(options, SystemPathBuf::from(root), None)
|
||||
.map_err(into_error)?;
|
||||
|
||||
let db = ProjectDatabase::new(project, system.clone()).map_err(into_error)?;
|
||||
let mut db = ProjectDatabase::new(project, system.clone()).map_err(into_error)?;
|
||||
|
||||
// By default, it will check all files in the project but we only want to check the open
|
||||
// files in the playground.
|
||||
db.set_check_mode(CheckMode::OpenFiles);
|
||||
|
||||
Ok(Self {
|
||||
db,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue