Skip to content

Commit e099981

Browse files
committed
[ty] Invert ty_ide and ty_project dependency
1 parent 53d795d commit e099981

File tree

9 files changed

+27
-143
lines changed

9 files changed

+27
-143
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty_ide/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ ruff_python_trivia = { workspace = true }
1919
ruff_source_file = { workspace = true }
2020
ruff_text_size = { workspace = true }
2121
ty_python_semantic = { workspace = true }
22+
ty_project = { workspace = true, features = ["testing"] }
2223

2324
itertools = { workspace = true }
2425
regex = { workspace = true }
2526
rustc-hash = { workspace = true }
26-
salsa = { workspace = true }
2727
smallvec = { workspace = true }
2828
tracing = { workspace = true }
2929

3030
[dev-dependencies]
31-
ty_vendored = { workspace = true }
3231

3332
insta = { workspace = true, features = ["filters"] }
3433

crates/ty_ide/src/db.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

crates/ty_ide/src/inlay_hints.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ mod tests {
156156
};
157157
use ruff_text_size::TextSize;
158158

159-
use crate::db::tests::TestDb;
160-
161159
use ruff_db::system::{DbWithWritableSystem, SystemPathBuf};
160+
use ty_project::ProjectMetadata;
162161
use ty_python_semantic::{
163162
Program, ProgramSettings, PythonPlatform, PythonVersionWithSource, SearchPathSettings,
164163
};
@@ -167,7 +166,10 @@ mod tests {
167166
const START: &str = "<START>";
168167
const END: &str = "<END>";
169168

170-
let mut db = TestDb::new();
169+
let mut db = ty_project::TestDb::new(ProjectMetadata::new(
170+
"test".into(),
171+
SystemPathBuf::from("/"),
172+
));
171173

172174
let start = source.find(START);
173175
let end = source
@@ -205,7 +207,7 @@ mod tests {
205207
}
206208

207209
pub(super) struct InlayHintTest {
208-
pub(super) db: TestDb,
210+
pub(super) db: ty_project::TestDb,
209211
pub(super) file: File,
210212
pub(super) range: TextRange,
211213
}

crates/ty_ide/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod completion;
2-
mod db;
32
mod docstring;
43
mod find_node;
54
mod goto;
@@ -14,7 +13,6 @@ mod signature_help;
1413
mod stub_mapping;
1514

1615
pub use completion::completion;
17-
pub use db::Db;
1816
pub use docstring::get_parameter_documentation;
1917
pub use goto::{goto_declaration, goto_definition, goto_type_definition};
2018
pub use hover::hover;
@@ -29,6 +27,7 @@ use ruff_db::files::{File, FileRange};
2927
use ruff_text_size::{Ranged, TextRange};
3028
use rustc_hash::FxHashSet;
3129
use std::ops::{Deref, DerefMut};
30+
use ty_project::Db;
3231
use ty_python_semantic::types::{Type, TypeDefinition};
3332

3433
/// Information associated with a text range.
@@ -211,13 +210,13 @@ impl HasNavigationTargets for TypeDefinition<'_> {
211210

212211
#[cfg(test)]
213212
mod tests {
214-
use crate::db::tests::TestDb;
215213
use insta::internals::SettingsBindDropGuard;
216214
use ruff_db::Db;
217215
use ruff_db::diagnostic::{Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig};
218216
use ruff_db::files::{File, system_path_to_file};
219217
use ruff_db::system::{DbWithWritableSystem, SystemPath, SystemPathBuf};
220218
use ruff_text_size::TextSize;
219+
use ty_project::ProjectMetadata;
221220
use ty_python_semantic::{
222221
Program, ProgramSettings, PythonPlatform, PythonVersionWithSource, SearchPathSettings,
223222
};
@@ -231,7 +230,7 @@ mod tests {
231230
}
232231

233232
pub(super) struct CursorTest {
234-
pub(super) db: TestDb,
233+
pub(super) db: ty_project::TestDb,
235234
pub(super) cursor: Cursor,
236235
_insta_settings_guard: SettingsBindDropGuard,
237236
}
@@ -286,7 +285,11 @@ mod tests {
286285

287286
impl CursorTestBuilder {
288287
pub(super) fn build(&self) -> CursorTest {
289-
let mut db = TestDb::new();
288+
let mut db = ty_project::TestDb::new(ProjectMetadata::new(
289+
"test".into(),
290+
SystemPathBuf::from("/"),
291+
));
292+
290293
let mut cursor: Option<Cursor> = None;
291294
for &Source {
292295
ref path,

crates/ty_project/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ruff_options_metadata = { workspace = true }
1919
ruff_python_ast = { workspace = true, features = ["serde"] }
2020
ruff_python_formatter = { workspace = true, optional = true }
2121
ruff_text_size = { workspace = true }
22-
ty_ide = { workspace = true }
2322
ty_python_semantic = { workspace = true, features = ["serde"] }
2423
ty_vendored = { workspace = true }
2524

@@ -53,6 +52,7 @@ deflate = ["ty_vendored/deflate"]
5352
schemars = ["dep:schemars", "ruff_db/schemars", "ty_python_semantic/schemars"]
5453
zstd = ["ty_vendored/zstd"]
5554
format = ["ruff_python_formatter"]
55+
testing = []
5656

5757
[lints]
5858
workspace = true

crates/ty_project/src/db.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ruff_db::system::System;
1414
use ruff_db::vendored::VendoredFileSystem;
1515
use salsa::plumbing::ZalsaDatabase;
1616
use salsa::{Event, Setter};
17-
use ty_ide::Db as IdeDb;
1817
use ty_python_semantic::lint::{LintRegistry, RuleSelection};
1918
use ty_python_semantic::{Db as SemanticDb, Program};
2019

@@ -404,9 +403,6 @@ impl SalsaMemoryDump {
404403
}
405404
}
406405

407-
#[salsa::db]
408-
impl IdeDb for ProjectDatabase {}
409-
410406
#[salsa::db]
411407
impl SemanticDb for ProjectDatabase {
412408
fn should_check_file(&self, file: File) -> bool {
@@ -468,7 +464,7 @@ mod format {
468464
}
469465
}
470466

471-
#[cfg(test)]
467+
#[cfg(any(test, feature = "testing"))]
472468
pub(crate) mod tests {
473469
use std::sync::{Arc, Mutex};
474470

@@ -487,7 +483,7 @@ pub(crate) mod tests {
487483

488484
#[salsa::db]
489485
#[derive(Clone)]
490-
pub(crate) struct TestDb {
486+
pub struct TestDb {
491487
storage: salsa::Storage<Self>,
492488
events: Events,
493489
files: Files,
@@ -497,7 +493,7 @@ pub(crate) mod tests {
497493
}
498494

499495
impl TestDb {
500-
pub(crate) fn new(project: ProjectMetadata) -> Self {
496+
pub fn new(project: ProjectMetadata) -> Self {
501497
let events = Events::default();
502498
let mut db = Self {
503499
storage: salsa::Storage::new(Some(Box::new({
@@ -522,7 +518,7 @@ pub(crate) mod tests {
522518

523519
impl TestDb {
524520
/// Takes the salsa events.
525-
pub(crate) fn take_salsa_events(&mut self) -> Vec<salsa::Event> {
521+
pub fn take_salsa_events(&mut self) -> Vec<salsa::Event> {
526522
let mut events = self.events.lock().unwrap();
527523

528524
std::mem::take(&mut *events)

crates/ty_project/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::glob::{GlobFilterCheckMode, IncludeResult};
22
use crate::metadata::options::{OptionDiagnostic, ToSettingsError};
33
use crate::walk::{ProjectFilesFilter, ProjectFilesWalker};
4+
#[cfg(feature = "testing")]
5+
pub use db::tests::TestDb;
46
pub use db::{ChangeResult, CheckMode, Db, ProjectDatabase, SalsaMemoryDump};
57
use files::{Index, Indexed, IndexedFiles};
68
use metadata::settings::Settings;

crates/ty_server/src/document/location.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use lsp_types::Location;
55
use ruff_db::files::FileRange;
66
use ruff_db::source::{line_index, source_text};
77
use ruff_text_size::Ranged;
8-
use ty_ide::{Db, NavigationTarget};
8+
use ty_ide::NavigationTarget;
9+
use ty_project::Db;
910

1011
pub(crate) trait ToLink {
11-
fn to_location(&self, db: &dyn ty_ide::Db, encoding: PositionEncoding) -> Option<Location>;
12+
fn to_location(&self, db: &dyn Db, encoding: PositionEncoding) -> Option<Location>;
1213

1314
fn to_link(
1415
&self,
15-
db: &dyn ty_ide::Db,
16+
db: &dyn Db,
1617
src: Option<FileRange>,
1718
encoding: PositionEncoding,
1819
) -> Option<lsp_types::LocationLink>;

0 commit comments

Comments
 (0)